File Coverage

lib/Sisimai/Reason/VirusDetected.pm
Criterion Covered Total %
statement 28 28 100.0
branch 6 8 75.0
condition 4 4 100.0
subroutine 8 8 100.0
pod 2 4 50.0
total 48 52 92.3


line stmt bran cond sub pod time code
1             package Sisimai::Reason::VirusDetected;
2 32     32   3055 use v5.26;
  32         125  
3 32     32   214 use strict;
  32         73  
  32         888  
4 32     32   160 use warnings;
  32         77  
  32         1982  
5 32     32   193 use Sisimai::SMTP::Command;
  32         61  
  32         10872  
6              
7 1     1 1 18 sub text { 'virusdetected' }
8 4     4 0 16 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 414     414 1 2167 my $class = shift;
16 414   100     1671 my $argv1 = shift // return 0;
17              
18 413         897 state $index = ["it has a potentially executable attachment"];
19 413         896 state $pairs = [
20             ["message was ", "ected", " virus"],
21             ["virus", " detected"],
22             ];
23 413 50       1304 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  413         2502  
24 413 100       1180 return 1 if grep { Sisimai::String->aligned(\$argv1, $_) } @$pairs;
  826         2709  
25 401         1296 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 4     4 0 13 my $class = shift;
36 4   100     10 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 3 100       10 return 1 if $argvs->{'reason'} eq 'virusdetected';
42 2 50       8 return 0 if grep { $argvs->{'command'} eq $_ } Sisimai::SMTP::Command->ExceptDATA->@*;
  10         18  
43 2         6 return __PACKAGE__->match(lc $argvs->{'diagnosticcode'});
44             }
45              
46             1;
47             __END__