File Coverage

lib/Sisimai/Reason/Filtered.pm
Criterion Covered Total %
statement 32 32 100.0
branch 15 18 83.3
condition 6 8 75.0
subroutine 7 7 100.0
pod 2 4 50.0
total 62 69 89.8


line stmt bran cond sub pod time code
1             package Sisimai::Reason::Filtered;
2 45     45   1790 use feature ':5.10';
  45         73  
  45         4417  
3 45     45   233 use strict;
  45         65  
  45         862  
4 45     45   182 use warnings;
  45         76  
  45         16817  
5              
6 196     196 1 390 sub text { 'filtered' }
7 4     4 0 13 sub description { 'Email rejected due to a header content after SMTP DATA command' }
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.0.0
14 944     944 1 1321 my $class = shift;
15 944   50     1968 my $argv1 = shift // return undef;
16              
17 944         1266 state $index = [
18             'because the recipient is only accepting mail from specific email addresses', # AOL Phoenix
19             'bounced address', # SendGrid|a message to an address has previously been Bounced.
20             'due to extended inactivity new mail is not currently being accepted for this mailbox',
21             'has restricted sms e-mail', # AT&T
22             'is not accepting any mail',
23             'message rejected due to user rules',
24             'refused due to recipient preferences', # Facebook
25             'resolver.rst.notauthorized', # Microsoft Exchange
26             'this account is protected by',
27             'user not found', # Filter on MAIL.RU
28             'user reject',
29             'we failed to deliver mail because the following address recipient id refuse to receive mail', # Willcom
30             'you have been blocked by the recipient',
31             ];
32 944 100       1562 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  12272         16560  
33 941         2070 return 0;
34             }
35              
36             sub true {
37             # Rejected by domain or address filter ?
38             # @param [Sisimai::Data] 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 1130     1130 0 1720 my $class = shift;
44 1130   100     2584 my $argvs = shift // return undef;
45 1129 50       2211 return 1 if $argvs->reason eq 'filtered';
46              
47 1129   100     5595 my $tempreason = Sisimai::SMTP::Status->name($argvs->deliverystatus) || '';
48 1129 100       2563 return 0 if $tempreason eq 'suspend';
49              
50 1124         3570 require Sisimai::Reason::UserUnknown;
51 1124         1442 my $alterclass = 'Sisimai::Reason::UserUnknown';
52 1124   50     2065 my $diagnostic = lc $argvs->diagnosticcode // '';
53              
54 1124 100       5844 if( $tempreason eq 'filtered' ) {
55             # Delivery status code points "filtered".
56 49 100       134 return 1 if $alterclass->match($diagnostic);
57 9 50       31 return 1 if __PACKAGE__->match($diagnostic);
58              
59             } else {
60             # The value of "reason" isn't "filtered" when the value of "smtpcommand" is an SMTP command
61             # to be sent before the SMTP DATA command because all the MTAs read the headers and the
62             # entire message body after the DATA command.
63 1075 100       3346 return 0 if $argvs->{'smtpcommand'} =~ /\A(?:CONN|EHLO|HELO|MAIL|RCPT)\z/;
64 838 50       1772 return 1 if __PACKAGE__->match($diagnostic);
65 838 100       2271 return 1 if $alterclass->match($diagnostic);
66             }
67 693         1792 return 0;
68             }
69              
70              
71             1;
72             __END__