File Coverage

lib/Sisimai/Reason/VirusDetected.pm
Criterion Covered Total %
statement 28 28 100.0
branch 7 8 87.5
condition 4 4 100.0
subroutine 8 8 100.0
pod 2 4 50.0
total 49 52 94.2


line stmt bran cond sub pod time code
1             package Sisimai::Reason::VirusDetected;
2 46     46   2675 use v5.26;
  46         128  
3 46     46   1449 use strict;
  46         77  
  46         1118  
4 46     46   156 use warnings;
  46         63  
  46         2154  
5 46     46   198 use Sisimai::SMTP::Command;
  46         77  
  46         11881  
6              
7 6     6 1 35 sub text { 'virusdetected' }
8 4     4 0 17 sub description { 'Email rejected due to a virus scanner on a destination host' }
9             sub match {
10             # Try to match that the given text and regular expressions
11             # @param [String] argv1 String to be matched with regular expressions
12             # @return [Integer] 0: Did not match
13             # 1: Matched
14             # @since v4.22.0
15 990     990 1 2795 my $class = shift;
16 990   100     2056 my $argv1 = shift // return 0;
17              
18 989         2382 state $index = ["it has a potentially executable attachment"];
19 989         1142 state $pairs = [
20             ["message was ", "ected", " virus"],
21             ["virus", " detected"],
22             ];
23 989 50       1475 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  989         2382  
24 989 100       1342 return 1 if grep { Sisimai::String->aligned(\$argv1, $_) } @$pairs;
  1978         3032  
25 977         1974 return 0;
26             }
27              
28             sub true {
29             # The bounce reason is "virusdetected" or not
30             # @param [Sisimai::Fact] 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 611     611 0 1004 my $class = shift;
36 611   100     1451 my $argvs = shift // return 0;
37              
38             # The value of "reason" isn't "virusdetected" when the value of "command" is an SMTP command to
39             # be sent before the SMTP DATA command because all the MTAs read the headers and the entire
40             # message body after the DATA command.
41 610 100       1485 return 1 if $argvs->{'reason'} eq 'virusdetected';
42 609 100       1447 return 0 if grep { $argvs->{'command'} eq $_ } Sisimai::SMTP::Command->ExceptDATA->@*;
  3045         4282  
43 473         1480 return __PACKAGE__->match(lc $argvs->{'diagnosticcode'});
44             }
45              
46             1;
47             __END__