File Coverage

lib/Sisimai/Reason/Rejected.pm
Criterion Covered Total %
statement 35 35 100.0
branch 24 24 100.0
condition 16 17 94.1
subroutine 7 7 100.0
pod 2 4 50.0
total 84 87 96.5


line stmt bran cond sub pod time code
1             package Sisimai::Reason::Rejected;
2 56     56   5345 use v5.26;
  56         254  
3 56     56   309 use strict;
  56         566  
  56         1458  
4 56     56   263 use warnings;
  56         89  
  56         35927  
5              
6 113     113 1 954 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 1217     1217 1 4261 my $class = shift;
15 1217   100     4277 my $argv1 = shift // return 0;
16              
17 1216         2418 state $isnot = [
18             "5.1.0 address rejected",
19             "ip address ",
20             "recipient address rejected",
21             ];
22 1216         2108 state $index = [
23             "access denied (in reply to mail from command)",
24             "administrative prohibition",
25             "all recipient addresses rejected : access denied",
26             "backscatter protection detected an invalid or expired email address", # MDaemon
27             "by non-member to a members-only list",
28             "can't determine purported responsible address",
29             "connections not accepted from servers without a valid sender domain",
30             "denied by secumail valid-address-filter", # SecuMail
31             "domain of sender address ",
32             "email address is on senderfilterconfig list",
33             "emetteur invalide",
34             "empty email address",
35             "empty envelope senders not allowed",
36             "from: domain is invalid. please provide a valid from:",
37             "fully qualified email address required", # McAfee
38             "invalid sender",
39             "is not a registered gateway user",
40             "mail from not owned by user",
41             "mailfrom domain is listed in spamhaus",
42             "null sender is not allowed",
43             "returned mail not accepted here",
44             "sending this from a different address or alias using the ",
45             "sender is spammer",
46             "sender not pre-approved",
47             "sender domain is empty",
48             "sender domain listed at ",
49             "sender verify failed", # Exim callout
50             "server does not accept mail from",
51             "spam reporting address", # SendGrid|a message to an address has previously been marked as Spam by the recipient.
52             "unroutable sender address",
53             "you are not allowed to post to this mailing list",
54             "your access to submit messages to this e-mail system has been rejected",
55             "your email address has been blacklisted", # MessageLabs
56             ];
57 1216         2674 state $pairs = [
58             ["after end of data:", ".", " does not exist"],
59             ["after mail from:", ".", " does not exist"],
60             ["domain ", " is a dead domain"],
61             ["email address ", "is not "],
62             ["send", "blacklisted"],
63             ["sender", " rejected"],
64             ["sender is", " list"],
65             ];
66              
67 1216 100       4937 return 0 if grep { rindex($argv1, $_) > -1 } @$isnot;
  3648         9831  
68 1055 100       2415 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  34815         59128  
69 1017 100       2452 return 1 if grep { Sisimai::String->aligned(\$argv1, $_) } @$pairs;
  7119         16603  
70 997         3400 return 0;
71             }
72              
73             sub true {
74             # Rejected by the envelope sender address or not
75             # @param [Sisimai::Fact] argvs Object to be detected the reason
76             # @return [Integer] 1: is rejected
77             # 0: is not rejected by the sender
78             # @since v4.0.0
79             # @see http://www.ietf.org/rfc/rfc2822.txt
80 929     929 0 1864 my $class = shift;
81 929   100     3001 my $argvs = shift // return 0;
82              
83 928 100       3000 return 1 if $argvs->{'reason'} eq 'rejected';
84 927   100     3898 my $tempreason = Sisimai::SMTP::Status->name($argvs->{'deliverystatus'}) || 'undefined';
85 927 100       2689 return 1 if $tempreason eq 'rejected'; # Delivery status code points "rejected".
86              
87             # Check the value of Diagnosic-Code: header with patterns
88 871         2670 my $issuedcode = lc $argvs->{'diagnosticcode'};
89 871   100     3812 my $thecommand = $argvs->{'command'} || '';
90 871 100 66     8743 if( $thecommand eq 'MAIL' ) {
    100 100        
    100 100        
91             # The session was rejected at 'MAIL FROM' command
92 82 100       316 return 1 if __PACKAGE__->match($issuedcode);
93              
94             } elsif( $thecommand eq 'DATA' ) {
95             # The session was rejected at 'DATA' command
96 98 100       360 if( $tempreason ne 'userunknown' ) {
97             # Except "userunknown"
98 97 100       408 return 1 if __PACKAGE__->match($issuedcode);
99             }
100             } elsif( $tempreason eq 'onhold' || $tempreason eq 'undefined' ||
101             $tempreason eq 'securityerror' || $tempreason eq 'systemerror' ) {
102             # Try to match with message patterns when the temporary reason is "onhold", "undefined",
103             # "securityerror", or "systemerror"
104 487 100       4400 return 1 if __PACKAGE__->match($issuedcode);
105             }
106 814         3494 return 0;
107             }
108              
109             1;
110             __END__