File Coverage

lib/Sisimai/Reason/Rejected.pm
Criterion Covered Total %
statement 33 33 100.0
branch 21 22 95.4
condition 5 6 83.3
subroutine 7 7 100.0
pod 2 4 50.0
total 68 72 94.4


line stmt bran cond sub pod time code
1             package Sisimai::Reason::Rejected;
2 48     48   1013 use feature ':5.10';
  48         78  
  48         3257  
3 48     48   235 use strict;
  48         76  
  48         803  
4 48     48   183 use warnings;
  48         84  
  48         19478  
5              
6 100     100 1 205 sub text { 'rejected' }
7 4     4 0 12 sub description { "Email rejected due to a sender's email address (envelope from)" }
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 1194     1194 1 1803 my $class = shift;
15 1194   50     2573 my $argv1 = shift // return undef;
16              
17 1194         1366 state $isnot = [
18             '5.1.0 address rejected',
19             'recipient address rejected',
20             'sender ip address rejected',
21             ];
22 1194         1551 state $index = [
23             'access denied (in reply to mail from command)',
24             'access denied (sender blacklisted)',
25             'address rejected',
26             'administrative prohibition',
27             'batv failed to verify', # SoniWall
28             'batv validation failure', # SoniWall
29             'backscatter protection detected an invalid or expired email address', # MDaemon
30             'bogus mail from', # IMail - block empty sender
31             'connections not accepted from servers without a valid sender domain',
32             'denied [bouncedeny]', # McAfee
33             'denied by secumail valid-address-filter',
34             'delivery not authorized, message refused',
35             'does not exist e2110',
36             'domain of sender address ',
37             'emetteur invalide',
38             'empty envelope senders not allowed',
39             'envelope blocked – ',
40             'error: no third-party dsns', # SpamWall - block empty sender
41             'from: domain is invalid. please provide a valid from:',
42             'fully qualified email address required', # McAfee
43             'invalid domain, see
44             'invalid sender',
45             'is not a registered gateway user',
46             'mail from not owned by user',
47             'message rejected: email address is not verified',
48             'mx records for ',
49             'null sender is not allowed',
50             'recipient addresses rejected : access denied',
51             'recipient not accepted. (batv: no tag',
52             'returned mail not accepted here',
53             'rfc 1035 violation: recursive cname records for',
54             'rule imposed mailbox access for', # MailMarshal
55             'sender address has been blacklisted',
56             'sender email address rejected',
57             'sender is spammer',
58             'sender not pre-approved',
59             'sender rejected',
60             'sender domain is empty',
61             'sender verify failed', # Exim callout
62             'syntax error: empty email address',
63             'the message has been rejected by batv defense',
64             'this server does not accept mail from',
65             'transaction failed unsigned dsn for',
66             'unroutable sender address',
67             'you are sending to/from an address that has been blacklisted',
68             ];
69 1194 100       1825 return 0 if grep { rindex($argv1, $_) > -1 } @$isnot;
  3582         7162  
70 1142 100       1868 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  51390         64188  
71 1083         2530 return 0;
72             }
73              
74             sub true {
75             # Rejected by the envelope sender address or not
76             # @param [Sisimai::Data] argvs Object to be detected the reason
77             # @return [Integer] 1: is rejected
78             # 0: is not rejected by the sender
79             # @since v4.0.0
80             # @see http://www.ietf.org/rfc/rfc2822.txt
81 937     937 0 1342 my $class = shift;
82 937   100     2084 my $argvs = shift // return undef;
83              
84 936 50       1953 return 1 if $argvs->reason eq 'rejected';
85 936   100     4587 my $tempreason = Sisimai::SMTP::Status->name($argvs->deliverystatus) || 'undefined';
86 936 100       2190 return 1 if $tempreason eq 'rejected'; # Delivery status code points "rejected".
87              
88             # Check the value of Diagnosic-Code: header with patterns
89 885         1741 my $diagnostic = lc $argvs->diagnosticcode;
90 885         3679 my $commandtxt = $argvs->smtpcommand;
91 885 100       5865 if( $commandtxt eq 'MAIL' ) {
    100          
    100          
92             # The session was rejected at 'MAIL FROM' command
93 121 100       427 return 1 if __PACKAGE__->match($diagnostic);
94              
95             } elsif( $commandtxt eq 'DATA' ) {
96             # The session was rejected at 'DATA' command
97 161 100       508 if( $tempreason ne 'userunknown' ) {
98             # Except "userunknown"
99 160 100       432 return 1 if __PACKAGE__->match($diagnostic);
100             }
101             } elsif( $tempreason =~ /\A(?:onhold|undefined|securityerror|systemerror)\z/ ) {
102             # Try to match with message patterns when the temporary reason
103             # is "onhold", "undefined", "securityerror", or "systemerror"
104 445 100       1166 return 1 if __PACKAGE__->match($diagnostic);
105             }
106 841         2583 return 0;
107             }
108              
109             1;
110             __END__