File Coverage

lib/Sisimai/Reason/VirusDetected.pm
Criterion Covered Total %
statement 23 23 100.0
branch 5 8 62.5
condition 3 4 75.0
subroutine 7 7 100.0
pod 2 4 50.0
total 40 46 86.9


line stmt bran cond sub pod time code
1             package Sisimai::Reason::VirusDetected;
2 26     26   2143 use feature ':5.10';
  26         866  
  26         1874  
3 26     26   158 use strict;
  26         45  
  26         490  
4 26     26   109 use warnings;
  26         43  
  26         7283  
5              
6 1     1 1 22 sub text { 'virusdetected' }
7 4     4 0 16 sub description { 'Email rejected due to a virus scanner on a destination host' }
8             sub match {
9             # Try to match that the given text and regular expressions
10             # @param [String] argv1 String to be matched with regular expressions
11             # @return [Integer] 0: Did not match
12             # 1: Matched
13             # @since v4.22.0
14 331     331 1 698 my $class = shift;
15 331   50     955 my $argv1 = shift // return undef;
16              
17 331         600 state $index = [
18             'it has a potentially executable attachment',
19             'the message was rejected because it contains prohibited virus or spam content',
20             'this form of attachment has been used by recent viruses or other malware',
21             'virus detected',
22             'your message was infected with a virus',
23             ];
24 331 100       822 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  1655         3545  
25 325         1003 return 0;
26             }
27              
28             sub true {
29             # The bounce reason is security error or not
30             # @param [Sisimai::Data] argvs Object to be detected the reason
31             # @return [Integer] 1: virus detected
32             # 0: virus was not detected
33             # @since v4.22.0
34             # @see http://www.ietf.org/rfc/rfc2822.txt
35 2     2 0 6 my $class = shift;
36 2   100     10 my $argvs = shift // return undef;
37              
38             # The value of "reason" isn't "virusdetected" when the value of "smtpcommand" is an SMTP com-
39             # mand to be sent before the SMTP DATA command because all the MTAs read the headers and the
40             # entire message body after the DATA command.
41 1 50       5 return 1 if $argvs->{'reason'} eq 'virusdetected';
42 1 50       6 return 0 if $argvs->{'smtpcommand'} =~ /\A(?:CONN|EHLO|HELO|MAIL|RCPT)\z/;
43 1 50       5 return 1 if __PACKAGE__->match(lc $argvs->{'diagnosticcode'});
44 1         3 return 0;
45             }
46              
47             1;
48             __END__