File Coverage

lib/Sisimai/Reason/Filtered.pm
Criterion Covered Total %
statement 34 34 100.0
branch 13 14 92.8
condition 8 8 100.0
subroutine 8 8 100.0
pod 2 4 50.0
total 65 68 95.5


line stmt bran cond sub pod time code
1             package Sisimai::Reason::Filtered;
2 57     57   3217 use v5.26;
  57         187  
3 57     57   251 use strict;
  57         83  
  57         1230  
4 57     57   387 use warnings;
  57         70  
  57         2437  
5 57     57   546 use Sisimai::SMTP::Command;
  57         99  
  57         18244  
6              
7 205     205 1 421 sub text { 'filtered' }
8 4     4 0 17 sub description { 'Email rejected due to a header content after SMTP DATA command' }
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.0.0
15 1098     1098 1 3064 my $class = shift;
16 1098   100     2500 my $argv1 = shift // return 0;
17              
18 1097         1400 state $index = [
19             "account is protected by",
20             "has restricted sms e-mail", # AT&T
21             "is not accepting any mail",
22             "message filtered",
23             "message rejected due to user rules",
24             "not found recipient account",
25             "recipient id refuse to receive mail", # Willcom
26             "recipient is only accepting mail from specific email addresses", # AOL Phoenix
27             "refused due to recipient preferences", # Facebook
28             "user refuses to receive this mail",
29             "user reject",
30             "you have been blocked by the recipient",
31             ];
32 1097 100       1616 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  13164         16066  
33 1088         2009 return 0;
34             }
35              
36             sub true {
37             # Rejected by domain or address filter ?
38             # @param [Sisimai::Fact] argvs Object to be detected the reason
39             # @return [Integer] 1: is filtered
40             # 0: is not filtered
41             # @since v4.0.0
42             # @see http://www.ietf.org/rfc/rfc2822.txt
43 1354     1354 0 2073 my $class = shift;
44 1354 100 100     3007 my $argvs = shift // return 0; return 1 if $argvs->{'reason'} eq 'filtered';
  1353         6671  
45              
46 1352   100     3182 my $tempreason = Sisimai::SMTP::Status->name($argvs->{'deliverystatus'}) || '';
47 1352 50       2821 return 0 if $tempreason eq 'suspend';
48              
49 1352         3109 require Sisimai::Reason::UserUnknown;
50 1352         2836 my $issuedcode = lc $argvs->{'diagnosticcode'};
51 1352   100     4119 my $thecommand = $argvs->{'command'} || '';
52 1352 100       2741 if( $tempreason eq 'filtered' ) {
53             # Delivery status code points "filtered".
54 40 100       150 return 1 if Sisimai::Reason::UserUnknown->match($issuedcode);
55 10         36 return __PACKAGE__->match($issuedcode);
56              
57             } else {
58             # The value of "reason" isn't "filtered" when the value of "command" is an SMTP command to
59             # be sent before the SMTP DATA command because all the MTAs read the headers and the entire
60             # message body after the DATA command.
61 1312 100       3777 return 0 if grep { $argvs->{'command'} eq $_ } Sisimai::SMTP::Command->ExceptDATA->@*;
  6560         9853  
62 985 100       2164 return 1 if __PACKAGE__->match($issuedcode);
63 984         2886 return Sisimai::Reason::UserUnknown->match($issuedcode);
64             }
65             }
66              
67             1;
68             __END__