File Coverage

lib/Sisimai/Reason/UserUnknown.pm
Criterion Covered Total %
statement 42 44 95.4
branch 17 20 85.0
condition 6 6 100.0
subroutine 8 8 100.0
pod 2 4 50.0
total 75 82 91.4


line stmt bran cond sub pod time code
1             package Sisimai::Reason::UserUnknown;
2 63     63   2151 use v5.26;
  63         229  
3 63     63   326 use strict;
  63         132  
  63         1964  
4 63     63   281 use warnings;
  63         136  
  63         3134  
5 63     63   399 use Sisimai::String;
  63         155  
  63         51516  
6              
7 742     742 1 3103 sub text { 'userunknown' }
8 4     4 0 24 sub description { "Email rejected due to a local part of a recipient's email address does not exist" }
9             sub match {
10             # Try to match that the given text and regular expressions
11             # @param [String] argv1 String to be matched with regular expressions
12             # @return [Integer] 0: Did not match
13             # 1: Matched
14             # @since v4.0.0
15 1340     1340 1 3027 my $class = shift;
16 1340   100     4056 my $argv1 = shift // return 0;
17              
18 1339         2888 state $index = [
19             "#5.1.1 bad address",
20             "550 address invalid",
21             "5.1.0 address rejected.",
22             "address not present in directory",
23             "address unknown",
24             "badrcptto",
25             "can't accept user",
26             "destination addresses were unknown",
27             "destination server rejected recipients",
28             "domain or user isn't in my list of allowed rcpthosts",
29             "email account that you tried to reach does not exist",
30             "email address could not be found",
31             "invalid address",
32             "invalid mailbox",
33             "is not a known user",
34             "is not a valid mailbox",
35             "mailbox does not exist",
36             "mailbox invalid",
37             "mailbox not present",
38             "mailbox not found",
39             "nessun utente simile in questo indirizzo",
40             "no account by that name here",
41             "no existe dicha persona",
42             "no existe ese usuario ",
43             "no such recipient",
44             "no such user",
45             "no thank you rejected: account unavailable",
46             "no valid recipients, bye",
47             "not a valid recipient",
48             "not a valid user here",
49             "not a local address",
50             "not email addresses",
51             "recipient address rejected. (in reply to rcpt to command)",
52             "recipient address rejected: access denied",
53             "recipient address rejected: userunknown",
54             "recipient is in my badrecipientto list",
55             "recipient is not accepted",
56             "recipient is not in my validrcptto list",
57             "recipient is not local",
58             "recipient not ok",
59             "recipient refuses to accept your mail",
60             "recipient unknown",
61             "recipients was undeliverable",
62             "spectator does not exist",
63             "there is no one at this address",
64             "unknown mailbox",
65             "unknown recipient",
66             "unknown user",
67             "user missing home directory",
68             "user not known",
69             "user unknown",
70             "utilisateur inconnu !",
71             "weil die adresse nicht gefunden wurde oder keine e-mails empfangen kann",
72             "your envelope recipient has been denied",
73             ];
74 1339         3300 state $pairs = [
75             ["<", "> not found"],
76             ["<", ">... blocked by "],
77             ["account ", " does not exist at the organization"],
78             ["address", " no longer"],
79             ["address", " not exist"],
80             ["bad", "recipient"],
81             ["invalid", "recipient"],
82             ["invalid", "user"],
83             ["mailbox ", "does not exist"],
84             ["mailbox ", "unavailable"],
85             ["no ", " in name directory"],
86             ["no ", "mail", "box "],
87             ["no ", "such", "address"],
88             ["non", "existent user"],
89             ["rcpt <", " does not exist"],
90             ["rcpt (", "t exist "],
91             ["recipient no", "found"],
92             ["recipient ", " not exist"],
93             ["recipient ", " was not found in"],
94             ["this user doesn't have a ", " account"],
95             ["unknown e", "mail address"],
96             ["unknown local", "part"],
97             ["user ", " not exist"],
98             ["user ", "not found"],
99             ["user (", ") unknown"],
100             ];
101              
102 1339 100       3523 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  72306         127148  
103 1011 100       2704 return 1 if grep { Sisimai::String->aligned(\$argv1, $_) } @$pairs;
  25275         52375  
104 965         4848 return 0;
105             }
106              
107             sub true {
108             # Whether the address is "userunknown" or not
109             # @param [Sisimai::Fact] argvs Object to be detected the reason
110             # @return [Integer] 1: is unknown user
111             # 0: is not unknown user.
112             # @since v4.0.0
113             # @see http://www.ietf.org/rfc/rfc2822.txt
114 1944     1944 0 5462 my $class = shift;
115 1944   100     7714 my $argvs = shift // return 0;
116              
117 1943         8682 require Sisimai::SMTP::Command;
118 1943 100       7967 return 1 if $argvs->{'reason'} eq 'userunknown';
119 1826 100       7761 return 0 if grep { $argvs->{'command'} eq $_ } Sisimai::SMTP::Command->BeforeRCPT->@*;
  10956         24092  
120              
121 1645   100     7486 my $tempreason = Sisimai::SMTP::Status->name($argvs->{'deliverystatus'}) || '';
122 1645 50       4922 return 0 if $tempreason eq 'suspend';
123              
124 1645         5477 my $issuedcode = lc $argvs->{'diagnosticcode'};
125 1645 100       7180 if( $tempreason eq 'userunknown' ) {
    100          
126             # *.1.1 = 'Bad destination mailbox address'
127             # Status: 5.1.1
128             # Diagnostic-Code: SMTP; 550 5.1.1 <***@example.jp>:
129             # Recipient address rejected: User unknown in local recipient table
130 450         1018 state $prematches = [qw|NoRelaying Blocked MailboxFull HasMoved Rejected NotAccept|];
131 450         1108 state $ModulePath = {
132             'Sisimai::Reason::NoRelaying' => 'Sisimai/Reason/NoRelaying.pm',
133             'Sisimai::Reason::Blocked' => 'Sisimai/Reason/Blocked.pm',
134             'Sisimai::Reason::MailboxFull' => 'Sisimai/Reason/MailboxFull.pm',
135             'Sisimai::Reason::HasMoved' => 'Sisimai/Reason/HasMoved.pm',
136             'Sisimai::Reason::Rejected' => 'Sisimai/Reason/Rejected.pm',
137             'Sisimai::Reason::NotAccept' => 'Sisimai/Reason/NotAccept.pm',
138             };
139 450         975 my $matchother = 0;
140              
141 450         1157 for my $e ( @$prematches ) {
142             # Check the value of "Diagnostic-Code" with other error patterns.
143 2700         4279 my $p = 'Sisimai::Reason::'.$e;
144 2700         61647 require $ModulePath->{ $p };
145              
146 2700 50       15916 next unless $p->match($issuedcode);
147             # Match with reason defined in Sisimai::Reason::* except UserUnknown.
148 0         0 $matchother = 1;
149 0         0 last;
150             }
151 450 50       2501 return 1 unless $matchother; # Did not match with other message patterns
152              
153             } elsif( $argvs->{'command'} eq 'RCPT' ) {
154             # When the SMTP command is not "RCPT", the session rejected by other reason, maybe.
155 208 100       752 return 1 if __PACKAGE__->match($issuedcode);
156             }
157 1087         4930 return 0;
158             }
159              
160             1;
161             __END__