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 67     67   1519 use v5.26;
  67         185  
3 67     67   246 use strict;
  67         86  
  67         1257  
4 67     67   218 use warnings;
  67         90  
  67         2594  
5 67     67   285 use Sisimai::String;
  67         81  
  67         36496  
6              
7 747     747 1 2373 sub text { 'userunknown' }
8 4     4 0 18 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 1407     1407 1 2793 my $class = shift;
16 1407   100     2682 my $argv1 = shift // return 0;
17              
18 1406         2172 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 1406         2599 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 ", "doesn't exist"],
99             ["user ", "not found"],
100             ["user (", ") unknown"],
101             ["user <", "> unknown"],
102             ];
103              
104 1406 100       2594 return 1 if grep { rindex($argv1, $_) > -1 } @$index;
  75924         88612  
105 1078 100       2237 return 1 if grep { Sisimai::String->aligned(\$argv1, $_) } @$pairs;
  29106         35938  
106 1032         3122 return 0;
107             }
108              
109             sub true {
110             # Whether the address is "userunknown" or not
111             # @param [Sisimai::Fact] argvs Object to be detected the reason
112             # @return [Integer] 1: is unknown user
113             # 0: is not unknown user.
114             # @since v4.0.0
115             # @see http://www.ietf.org/rfc/rfc2822.txt
116 2031     2031 0 3037 my $class = shift;
117 2031   100     4273 my $argvs = shift // return 0;
118              
119 2030         5637 require Sisimai::SMTP::Command;
120 2030 100       4810 return 1 if $argvs->{'reason'} eq 'userunknown';
121 1913 100       4345 return 0 if grep { $argvs->{'command'} eq $_ } Sisimai::SMTP::Command->BeforeRCPT->@*;
  11478         14627  
122              
123 1722   100     4397 my $tempreason = Sisimai::SMTP::Status->name($argvs->{'deliverystatus'}) || '';
124 1722 50       3197 return 0 if $tempreason eq 'suspend';
125              
126 1722         3843 my $issuedcode = lc $argvs->{'diagnosticcode'};
127 1722 100       5481 if( $tempreason eq 'userunknown' ) {
    100          
128             # *.1.1 = 'Bad destination mailbox address'
129             # Status: 5.1.1
130             # Diagnostic-Code: SMTP; 550 5.1.1 <***@example.jp>:
131             # Recipient address rejected: User unknown in local recipient table
132 455         723 state $prematches = [qw|NoRelaying Blocked MailboxFull HasMoved Rejected NotAccept|];
133 455         908 state $ModulePath = {
134             'Sisimai::Reason::NoRelaying' => 'Sisimai/Reason/NoRelaying.pm',
135             'Sisimai::Reason::Blocked' => 'Sisimai/Reason/Blocked.pm',
136             'Sisimai::Reason::MailboxFull' => 'Sisimai/Reason/MailboxFull.pm',
137             'Sisimai::Reason::HasMoved' => 'Sisimai/Reason/HasMoved.pm',
138             'Sisimai::Reason::Rejected' => 'Sisimai/Reason/Rejected.pm',
139             'Sisimai::Reason::NotAccept' => 'Sisimai/Reason/NotAccept.pm',
140             };
141 455         620 my $matchother = 0;
142              
143 455         764 for my $e ( @$prematches ) {
144             # Check the value of "Diagnostic-Code" with other error patterns.
145 2730         2821 my $p = 'Sisimai::Reason::'.$e;
146 2730         43539 require $ModulePath->{ $p };
147              
148 2730 50       10386 next unless $p->match($issuedcode);
149             # Match with reason defined in Sisimai::Reason::* except UserUnknown.
150 0         0 $matchother = 1;
151 0         0 last;
152             }
153 455 50       1770 return 1 unless $matchother; # Did not match with other message patterns
154              
155             } elsif( $argvs->{'command'} eq 'RCPT' ) {
156             # When the SMTP command is not "RCPT", the session rejected by other reason, maybe.
157 213 100       523 return 1 if __PACKAGE__->match($issuedcode);
158             }
159 1159         2674 return 0;
160             }
161              
162             1;
163             __END__