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 53     53   3093 use v5.26;
  53         228  
3 53     53   280 use strict;
  53         1932  
  53         1597  
4 53     53   291 use warnings;
  53         101  
  53         3413  
5 53     53   628 use Sisimai::SMTP::Command;
  53         135  
  53         26020  
6              
7 205     205 1 708 sub text { 'filtered' }
8 4     4 0 18 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 1036     1036 1 3899 my $class = shift;
16 1036   100     7891 my $argv1 = shift // return 0;
17              
18 1035         2091 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 1035 100       2421 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  12420         22260  
33 1026         3478 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 1272     1272 0 2832 my $class = shift;
44 1272 100 100     4694 my $argvs = shift // return 0; return 1 if $argvs->{'reason'} eq 'filtered';
  1271         4535  
45              
46 1270   100     5823 my $tempreason = Sisimai::SMTP::Status->name($argvs->{'deliverystatus'}) || '';
47 1270 50       3286 return 0 if $tempreason eq 'suspend';
48              
49 1270         5243 require Sisimai::Reason::UserUnknown;
50 1270         4408 my $issuedcode = lc $argvs->{'diagnosticcode'};
51 1270   100     4987 my $thecommand = $argvs->{'command'} || '';
52 1270 100       4613 if( $tempreason eq 'filtered' ) {
53             # Delivery status code points "filtered".
54 40 100       158 return 1 if Sisimai::Reason::UserUnknown->match($issuedcode);
55 10         40 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 1230 100       5865 return 0 if grep { $argvs->{'command'} eq $_ } Sisimai::SMTP::Command->ExceptDATA->@*;
  6150         18416  
62 923 100       2757 return 1 if __PACKAGE__->match($issuedcode);
63 922         3794 return Sisimai::Reason::UserUnknown->match($issuedcode);
64             }
65             }
66              
67             1;
68             __END__