File Coverage

lib/Sisimai/Reason/UserUnknown.pm
Criterion Covered Total %
statement 35 35 100.0
branch 16 16 100.0
condition 5 6 83.3
subroutine 7 7 100.0
pod 2 4 50.0
total 65 68 95.5


line stmt bran cond sub pod time code
1             package Sisimai::Reason::UserUnknown;
2 59     59   1293 use feature ':5.10';
  59         106  
  59         5406  
3 59     59   328 use strict;
  59         90  
  59         2034  
4 59     59   287 use warnings;
  59         89  
  59         103979  
5              
6 727     727 1 1624 sub text { 'userunknown' }
7 4     4 0 14 sub description { "Email rejected due to a local part of a recipient's email address does not exist" }
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 1162     1162 1 1910 my $class = shift;
15 1162   50     2715 my $argv1 = shift // return undef;
16              
17 1162         1789 state $regex = qr{(?>
18             [#]5[.]1[.]1[ ]bad[ ]address
19             |[<][^ ]+[>][ ]not[ ]found
20             |[<][^ ]+[@][^ ]+[>][.][.][.][ ]blocked[ ]by[ ]
21             |550[ ]address[ ]invalid
22             |5[.]1[.]0[ ]address[ ]rejected[.]
23             |account[ ][^ ]+[ ]does[ ]not[ ]exist[ ]at[ ]the[ ]organization
24             |adresse[ ]d[ ]au[ ]moins[ ]un[ ]destinataire[ ]invalide[.][ ]invalid[ ]recipient[.][0-9a-z_]+41[68]
25             |address[ ](?:does[ ]not[ ]exist|not[ ]present[ ]in[ ]directory|unknown)
26             |archived[ ]recipient
27             |bad[-_ \t]recipient
28             |can[']t[ ]accept[ ]user
29             |does[ ]not[ ]exist[.]
30             |destination[ ](?:
31             addresses[ ]were[ ]unknown
32             |server[ ]rejected[ ]recipients
33             )
34             |email[ ]address[ ](?:does[ ]not[ ]exist|could[ ]not[ ]be[ ]found)
35             |invalid[ ](?:
36             address
37             |mailbox:?
38             |mailbox[ ]path|recipient
39             )
40             |is[ ]not[ ](?:
41             a[ ]known[ ]user
42             |a[ ]valid[ ]mailbox
43             |an[ ]active[ ]address[ ]at[ ]this[ ]host
44             )
45             |mailbox[ ](?:
46             [^ ]+[ ]does[ ]not[ ]exist
47             |[^ ]+[@][^ ]+[ ]unavailable
48             |does[ ]not[ ]exist
49             |invalid
50             |is[ ](?:inactive|unavailable)
51             |not[ ](?:present|found)
52             |unavailable
53             )
54             |nessun[ ]utente[ ]simile[ ]in[ ]questo[ ]indirizzo
55             |no[ ](?:
56             [ ][^ ]+[ ]in[ ]name[ ]directory
57             |account[ ]by[ ]that[ ]name[ ]here
58             |existe[ ](?:dicha[ ]persona|ese[ ]usuario[ ])
59             |mail[ ]box[ ]available[ ]for[ ]this[ ]user
60             |mailbox[ ](?:
61             by[ ]that[ ]name[ ]is[ ]currently[ ]available
62             |found
63             )
64             |matches[ ]to[ ]nameserver[ ]query
65             |such[ ](?:
66             address[ ]here
67             |mailbox
68             |person[ ]at[ ]this[ ]address
69             |recipient
70             |user(?:[ ]here)?
71             )
72             |thank[ ]you[ ]rejected:[ ]account[ ]unavailable:
73             |valid[ ]recipients,[ ]bye
74             )
75             |non[- ]?existent[ ]user
76             |not[ ](?:
77             a[ ]valid[ ](?:recipient|user[ ]here)
78             |a[ ]local[ ]address
79             |email[ ]addresses
80             )
81             |rcpt[ ][<][^ ]+[>][ ]does[ ]not[ ]exist
82             |recipient[ ]address[ ]rejected[.][ ][(]in[ ]reply[ ]to[ ]rcpt[ ]to[ ]command[)]
83             |recipient[ ](?:
84             [^ ]+[ ]was[ ]not[ ]found[ ]in
85             |address[ ]rejected:[ ](?:
86             access[ ]denied
87             |invalid[ ]user
88             |invalid-recipient
89             |user[ ][^ ]+[ ]does[ ]not[ ]exist
90             |user[ ]unknown[ ]in[ ][^ ]+[ ]table
91             |unknown[ ]user
92             )
93             |does[ ]not[ ]exist(?:[ ]on[ ]this[ ]system)?
94             |is[ ]not[ ]local
95             |not[ ](?:exist|found|ok)
96             |refuses[ ]to[ ]accept[ ]your[ ]mail
97             |unknown
98             )
99             |requested[ ]action[ ]not[ ]taken:[ ]mailbox[ ]unavailable
100             |resolver[.]adr[.]recipient notfound
101             |said:[ ]550[-[ ]]5[.]1[.]1[ ][^ ]+[ ]user[ ]unknown[ ]
102             |sorry,[ ](?:
103             user[ ]unknown
104             |badrcptto
105             |no[ ]mailbox[ ]here[ ]by[ ]that[ ]name
106             |your[ ]envelope[ ]recipient[ ]has[ ]been[ ]denied
107             )
108             |that[ ]domain[ ]or[ ]user[ ]isn't[ ]in[ ]my[ ]list[ ]of[ ]allowed[ ]rcpthosts
109             |the[ ](?:
110             email[ ]account[ ]that[ ]you[ ]tried[ ]to[ ]reach[ ]does[ ]not[ ]exist
111             |following[ ]recipients[ ]was[ ]undeliverable
112             |user[']s[ ]email[ ]name[ ]is[ ]not[ ]found
113             )
114             |there[ ]is[ ]no[ ]one[ ]at[ ]this[ ]address
115             |this[ ](?:
116             address[ ]no[ ]longer[ ]accepts[ ]mail
117             |email[ ]address[ ]is[ ]wrong[ ]or[ ]no[ ]longer[ ]valid
118             |recipient[ ]is[ ]in[ ]my[ ]badrecipientto[ ]list
119             |recipient[ ]is[ ]not[ ]in[ ]my[ ]validrcptto[ ]list
120             |spectator[ ]does[ ]not[ ]exist
121             |user[ ]doesn[']?t[ ]have[ ]a[ ][^ ]+[ ]account
122             )
123             |unknown[ ](?:
124             e[-]?mail[ ]address
125             |local[- ]part
126             |mailbox
127             |recipient
128             |user
129             )
130             |user[ ](?:
131             [^ ]+[ ]was[ ]not[ ]found
132             |[^ ]+[ ]does[ ]not[ ]exist
133             |does[ ]not[ ]exist
134             |missing[ ]home[ ]directory
135             |not[ ](?:active|exist|found|known)
136             |unknown
137             )
138             |utilisateur[ ]inconnu[ ]!
139             |vdeliver:[ ]invalid[ ]or[ ]unknown[ ]virtual[ ]user
140             |your[ ]envelope[ ]recipient[ ]is[ ]in[ ]my[ ]badrcptto[ ]list
141             )
142             }x;
143 1162 100       23471 return 1 if $argv1 =~ $regex;
144 804         2519 return 0;
145             }
146              
147             sub true {
148             # Whether the address is "userunknown" or not
149             # @param [Sisimai::Data] argvs Object to be detected the reason
150             # @return [Integer] 1: is unknown user
151             # 0: is not unknown user.
152             # @since v4.0.0
153             # @see http://www.ietf.org/rfc/rfc2822.txt
154 1760     1760 0 3419 my $class = shift;
155 1760   100     3870 my $argvs = shift // return undef;
156 1759 100       3771 return 1 if $argvs->reason eq 'userunknown';
157              
158 1562   100     9401 my $tempreason = Sisimai::SMTP::Status->name($argvs->deliverystatus) || '';
159 1562 100       4419 return 0 if $tempreason eq 'suspend';
160              
161 1557         3223 my $diagnostic = lc $argvs->diagnosticcode;
162 1557 100       9692 if( $tempreason eq 'userunknown' ) {
    100          
163             # *.1.1 = 'Bad destination mailbox address'
164             # Status: 5.1.1
165             # Diagnostic-Code: SMTP; 550 5.1.1 <***@example.jp>:
166             # Recipient address rejected: User unknown in local recipient table
167 374         762 state $prematches = [qw|NoRelaying Blocked MailboxFull HasMoved Rejected NotAccept|];
168 374         735 state $ModulePath = {
169             'Sisimai::Reason::NoRelaying' => 'Sisimai/Reason/NoRelaying.pm',
170             'Sisimai::Reason::Blocked' => 'Sisimai/Reason/Blocked.pm',
171             'Sisimai::Reason::MailboxFull' => 'Sisimai/Reason/MailboxFull.pm',
172             'Sisimai::Reason::HasMoved' => 'Sisimai/Reason/HasMoved.pm',
173             'Sisimai::Reason::Rejected' => 'Sisimai/Reason/Rejected.pm',
174             'Sisimai::Reason::NotAccept' => 'Sisimai/Reason/NotAccept.pm',
175             };
176 374         600 my $matchother = 0;
177              
178 374         949 for my $e ( @$prematches ) {
179             # Check the value of "Diagnostic-Code" with other error patterns.
180 2214         3803 my $p = 'Sisimai::Reason::'.$e;
181 2214         38162 require $ModulePath->{ $p };
182              
183 2214 100       8287 next unless $p->match($diagnostic);
184             # Match with reason defined in Sisimai::Reason::* except UserUnknown.
185 15         38 $matchother = 1;
186 15         28 last;
187             }
188 374 100       1630 return 1 unless $matchother; # Did not match with other message patterns
189              
190             } elsif( $argvs->smtpcommand eq 'RCPT' ) {
191             # When the SMTP command is not "RCPT", the session rejected by other
192             # reason, maybe.
193 128 100       861 return 1 if __PACKAGE__->match($diagnostic);
194             }
195 1095         6209 return 0;
196             }
197              
198             1;
199             __END__