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   1172 use feature ':5.10';
  48         84  
  48         3582  
3 48     48   264 use strict;
  48         84  
  48         847  
4 48     48   194 use warnings;
  48         76  
  48         22223  
5              
6 100     100 1 811 sub text { 'rejected' }
7 4     4 0 15 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 1170     1170 1 1868 my $class = shift;
15 1170   50     2727 my $argv1 = shift // return undef;
16              
17 1170         1613 state $isnot = [
18             '5.1.0 address rejected',
19             'recipient address rejected',
20             'sender ip address rejected',
21             ];
22 1170         1607 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             "because the sender isn't on the recipient's list of senders to accept mail from",
31             'bogus mail from', # IMail - block empty sender
32             'connections not accepted from servers without a valid sender domain',
33             'denied [bouncedeny]', # McAfee
34             'denied by secumail valid-address-filter',
35             'delivery not authorized, message refused',
36             'does not exist e2110',
37             'domain of sender address ',
38             'email address is on senderfilterconfig list',
39             'emetteur invalide',
40             'empty envelope senders not allowed',
41             'envelope blocked – ',
42             'error: no third-party dsns', # SpamWall - block empty sender
43             'from: domain is invalid. please provide a valid from:',
44             'fully qualified email address required', # McAfee
45             'invalid domain, see
46             'invalid sender',
47             'is not a registered gateway user',
48             'mail from not owned by user',
49             'message rejected: email address is not verified',
50             'mx records for ',
51             'null sender is not allowed',
52             'recipient addresses rejected : access denied',
53             'recipient not accepted. (batv: no tag',
54             'returned mail not accepted here',
55             'rfc 1035 violation: recursive cname records for',
56             'rule imposed mailbox access for', # MailMarshal
57             'sender address has been blacklisted',
58             'sender email address rejected',
59             'sender is in my black list',
60             'sender is spammer',
61             'sender not pre-approved',
62             'sender rejected',
63             'sender domain is empty',
64             'sender verify failed', # Exim callout
65             'syntax error: empty email address',
66             'the message has been rejected by batv defense',
67             'this server does not accept mail from',
68             'transaction failed unsigned dsn for',
69             'unroutable sender address',
70             'you are not allowed to post to this mailing list',
71             'you are sending to/from an address that has been blacklisted',
72             'your access to submit messages to this e-mail system has been rejected'
73             ];
74 1170 100       1963 return 0 if grep { rindex($argv1, $_) > -1 } @$isnot;
  3510         7676  
75 1118 100       2137 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  55900         81606  
76 1059         3053 return 0;
77             }
78              
79             sub true {
80             # Rejected by the envelope sender address or not
81             # @param [Sisimai::Data] argvs Object to be detected the reason
82             # @return [Integer] 1: is rejected
83             # 0: is not rejected by the sender
84             # @since v4.0.0
85             # @see http://www.ietf.org/rfc/rfc2822.txt
86 917     917 0 1700 my $class = shift;
87 917   100     2219 my $argvs = shift // return undef;
88              
89 916 50       2150 return 1 if $argvs->reason eq 'rejected';
90 916   100     5269 my $tempreason = Sisimai::SMTP::Status->name($argvs->deliverystatus) || 'undefined';
91 916 100       2296 return 1 if $tempreason eq 'rejected'; # Delivery status code points "rejected".
92              
93             # Check the value of Diagnosic-Code: header with patterns
94 865         1759 my $diagnostic = lc $argvs->diagnosticcode;
95 865         4725 my $commandtxt = $argvs->smtpcommand;
96 865 100       6432 if( $commandtxt eq 'MAIL' ) {
    100          
    100          
97             # The session was rejected at 'MAIL FROM' command
98 121 100       500 return 1 if __PACKAGE__->match($diagnostic);
99              
100             } elsif( $commandtxt eq 'DATA' ) {
101             # The session was rejected at 'DATA' command
102 151 100       519 if( $tempreason ne 'userunknown' ) {
103             # Except "userunknown"
104 150 100       422 return 1 if __PACKAGE__->match($diagnostic);
105             }
106             } elsif( $tempreason =~ /\A(?:onhold|undefined|securityerror|systemerror)\z/ ) {
107             # Try to match with message patterns when the temporary reason
108             # is "onhold", "undefined", "securityerror", or "systemerror"
109 435 100       1227 return 1 if __PACKAGE__->match($diagnostic);
110             }
111 821         2549 return 0;
112             }
113              
114             1;
115             __END__