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   2156 use feature ':5.10';
  45         83  
  45         4009  
3 45     45   260 use strict;
  45         83  
  45         962  
4 45     45   192 use warnings;
  45         78  
  45         18823  
5              
6 188     188 1 477 sub text { 'filtered' }
7 4     4 0 16 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 934     934 1 1332 my $class = shift;
15 934   50     2010 my $argv1 = shift // return undef;
16              
17 934         1451 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             'not found recipient account',
25             'refused due to recipient preferences', # Facebook
26             'resolver.rst.notauthorized', # Microsoft Exchange
27             'this account is protected by',
28             'user not found', # Filter on MAIL.RU
29             'user reject',
30             'we failed to deliver mail because the following address recipient id refuse to receive mail', # Willcom
31             'you have been blocked by the recipient',
32             ];
33 934 100       1876 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  13076         20394  
34 931         2199 return 0;
35             }
36              
37             sub true {
38             # Rejected by domain or address filter ?
39             # @param [Sisimai::Data] argvs Object to be detected the reason
40             # @return [Integer] 1: is filtered
41             # 0: is not filtered
42             # @since v4.0.0
43             # @see http://www.ietf.org/rfc/rfc2822.txt
44 1102     1102 0 1957 my $class = shift;
45 1102   100     2535 my $argvs = shift // return undef;
46 1101 50       2671 return 1 if $argvs->reason eq 'filtered';
47              
48 1101   100     6246 my $tempreason = Sisimai::SMTP::Status->name($argvs->deliverystatus) || '';
49 1101 100       2769 return 0 if $tempreason eq 'suspend';
50              
51 1096         3904 require Sisimai::Reason::UserUnknown;
52 1096         2165 my $alterclass = 'Sisimai::Reason::UserUnknown';
53 1096   50     2354 my $diagnostic = lc $argvs->diagnosticcode // '';
54              
55 1096 100       6902 if( $tempreason eq 'filtered' ) {
56             # Delivery status code points "filtered".
57 41 100       139 return 1 if $alterclass->match($diagnostic);
58 9 50       34 return 1 if __PACKAGE__->match($diagnostic);
59              
60             } else {
61             # The value of "reason" isn't "filtered" when the value of "smtpcommand" is an SMTP command
62             # to be sent before the SMTP DATA command because all the MTAs read the headers and the
63             # entire message body after the DATA command.
64 1055 100       3858 return 0 if $argvs->{'smtpcommand'} =~ /\A(?:CONN|EHLO|HELO|MAIL|RCPT)\z/;
65 828 50       2068 return 1 if __PACKAGE__->match($diagnostic);
66 828 100       2612 return 1 if $alterclass->match($diagnostic);
67             }
68 683         2130 return 0;
69             }
70              
71              
72             1;
73             __END__