| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Sisimai::Reason; |
|
2
|
78
|
|
|
78
|
|
1381
|
use feature ':5.10'; |
|
|
78
|
|
|
|
|
153
|
|
|
|
78
|
|
|
|
|
6031
|
|
|
3
|
78
|
|
|
78
|
|
553
|
use strict; |
|
|
78
|
|
|
|
|
213
|
|
|
|
78
|
|
|
|
|
1553
|
|
|
4
|
78
|
|
|
78
|
|
348
|
use warnings; |
|
|
78
|
|
|
|
|
137
|
|
|
|
78
|
|
|
|
|
108437
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
my $ModulePath = __PACKAGE__->path; |
|
7
|
|
|
|
|
|
|
my $GetRetried = __PACKAGE__->retry; |
|
8
|
|
|
|
|
|
|
my $ClassOrder = [ |
|
9
|
|
|
|
|
|
|
[qw|MailboxFull MesgTooBig ExceedLimit Suspend HasMoved NoRelaying UserUnknown |
|
10
|
|
|
|
|
|
|
Filtered Rejected HostUnknown SpamDetected TooManyConn Blocked |
|
11
|
|
|
|
|
|
|
|], |
|
12
|
|
|
|
|
|
|
[qw|MailboxFull SpamDetected PolicyViolation VirusDetected NoRelaying |
|
13
|
|
|
|
|
|
|
SecurityError SystemError NetworkError Suspend Expired ContentError |
|
14
|
|
|
|
|
|
|
SystemFull NotAccept MailerError |
|
15
|
|
|
|
|
|
|
|], |
|
16
|
|
|
|
|
|
|
[qw|MailboxFull MesgTooBig ExceedLimit Suspend UserUnknown Filtered Rejected |
|
17
|
|
|
|
|
|
|
HostUnknown SpamDetected TooManyConn Blocked SpamDetected SecurityError |
|
18
|
|
|
|
|
|
|
SystemError NetworkError Suspend Expired ContentError HasMoved SystemFull |
|
19
|
|
|
|
|
|
|
NotAccept MailerError NoRelaying SyntaxError OnHold |
|
20
|
|
|
|
|
|
|
|], |
|
21
|
|
|
|
|
|
|
]; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub retry { |
|
24
|
|
|
|
|
|
|
# Reason list better to retry detecting an error reason |
|
25
|
|
|
|
|
|
|
# @return [Array] Reason list |
|
26
|
|
|
|
|
|
|
return { |
|
27
|
155
|
|
|
155
|
0
|
1038
|
'undefined' => 1, 'onhold' => 1, 'systemerror' => 1, 'securityerror' => 1, |
|
28
|
|
|
|
|
|
|
'networkerror' => 1, 'hostunknown' => 1, 'userunknown'=> 1 |
|
29
|
|
|
|
|
|
|
}; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub index { |
|
33
|
|
|
|
|
|
|
# All the error reason list Sisimai support |
|
34
|
|
|
|
|
|
|
# @return [Array] Reason list |
|
35
|
83
|
|
|
83
|
0
|
736
|
return [qw| |
|
36
|
|
|
|
|
|
|
Blocked ContentError ExceedLimit Expired Filtered HasMoved HostUnknown |
|
37
|
|
|
|
|
|
|
MailboxFull MailerError MesgTooBig NetworkError NotAccept OnHold |
|
38
|
|
|
|
|
|
|
Rejected NoRelaying SpamDetected VirusDetected PolicyViolation SecurityError |
|
39
|
|
|
|
|
|
|
Suspend SystemError SystemFull TooManyConn UserUnknown SyntaxError |
|
40
|
|
|
|
|
|
|
|]; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub path { |
|
44
|
|
|
|
|
|
|
# Returns Sisimai::Reason::* module path table |
|
45
|
|
|
|
|
|
|
# @return [Hash] Module path table |
|
46
|
|
|
|
|
|
|
# @since v4.25.6 |
|
47
|
79
|
|
|
79
|
0
|
251
|
my $class = shift; |
|
48
|
79
|
|
|
|
|
265
|
my $index = __PACKAGE__->index; |
|
49
|
79
|
|
|
|
|
209
|
my $table = {}; |
|
50
|
79
|
|
|
|
|
2965
|
$table->{ __PACKAGE__.'::'.$_ } = 'Sisimai/Reason/'.$_.'.pm' for @$index; |
|
51
|
79
|
|
|
|
|
288
|
return $table; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub get { |
|
55
|
|
|
|
|
|
|
# Detect the bounce reason |
|
56
|
|
|
|
|
|
|
# @param [Sisimai::Data] argvs Parsed email object |
|
57
|
|
|
|
|
|
|
# @return [String, Undef] Bounce reason or Undef if the argument |
|
58
|
|
|
|
|
|
|
# is missing or invalid object |
|
59
|
|
|
|
|
|
|
# @see anotherone |
|
60
|
2064
|
|
|
2064
|
0
|
5537
|
my $class = shift; |
|
61
|
2064
|
|
100
|
|
|
4673
|
my $argvs = shift // return undef; |
|
62
|
2063
|
50
|
|
|
|
4950
|
return undef unless ref $argvs eq 'Sisimai::Data'; |
|
63
|
|
|
|
|
|
|
|
|
64
|
2063
|
100
|
|
|
|
5455
|
unless( exists $GetRetried->{ $argvs->reason } ) { |
|
65
|
|
|
|
|
|
|
# Return reason text already decided except reason match with the |
|
66
|
|
|
|
|
|
|
# regular expression of ->retry() method. |
|
67
|
1674
|
50
|
|
|
|
10825
|
return $argvs->reason if $argvs->reason; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
2063
|
100
|
|
|
|
10760
|
return 'delivered' if substr($argvs->deliverystatus, 0, 2) eq '2.'; |
|
70
|
|
|
|
|
|
|
|
|
71
|
2061
|
|
|
|
|
10349
|
my $reasontext = ''; |
|
72
|
2061
|
100
|
66
|
|
|
4431
|
if( $argvs->diagnostictype eq 'SMTP' || $argvs->diagnostictype eq '' ) { |
|
73
|
|
|
|
|
|
|
# Diagnostic-Code: SMTP; ... or empty value |
|
74
|
1980
|
|
|
|
|
9408
|
for my $e ( @{ $ClassOrder->[0] } ) { |
|
|
1980
|
|
|
|
|
4917
|
|
|
75
|
|
|
|
|
|
|
# Check the value of Diagnostic-Code: and the value of Status:, it is a |
|
76
|
|
|
|
|
|
|
# deliverystats, with true() method in each Sisimai::Reason::* class. |
|
77
|
17680
|
|
|
|
|
34243
|
my $p = 'Sisimai::Reason::'.$e; |
|
78
|
17680
|
|
|
|
|
297273
|
require $ModulePath->{ $p }; |
|
79
|
|
|
|
|
|
|
|
|
80
|
17680
|
100
|
|
|
|
75489
|
next unless $p->true($argvs); |
|
81
|
1491
|
|
|
|
|
6468
|
$reasontext = $p->text; |
|
82
|
1491
|
|
|
|
|
2551
|
last; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
2061
|
100
|
66
|
|
|
7261
|
if( not $reasontext || $reasontext eq 'undefined' ) { |
|
87
|
|
|
|
|
|
|
# Bounce reason is not detected yet. |
|
88
|
570
|
|
|
|
|
1643
|
$reasontext = __PACKAGE__->anotherone($argvs); |
|
89
|
570
|
50
|
|
|
|
1996
|
$reasontext = '' if $reasontext eq 'undefined'; |
|
90
|
570
|
100
|
50
|
|
|
1454
|
$reasontext ||= 'expired' if $argvs->action eq 'delayed'; |
|
91
|
570
|
100
|
|
|
|
4502
|
return $reasontext if $reasontext; |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Try to match with message patterns in Sisimai::Reason::Vacation |
|
94
|
31
|
|
|
|
|
3136
|
require Sisimai::Reason::Vacation; |
|
95
|
31
|
50
|
|
|
|
110
|
$reasontext = 'vacation' if Sisimai::Reason::Vacation->match(lc $argvs->diagnosticcode); |
|
96
|
31
|
100
|
50
|
|
|
119
|
$reasontext ||= 'onhold' if $argvs->diagnosticcode; |
|
97
|
31
|
|
100
|
|
|
318
|
$reasontext ||= 'undefined'; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
1522
|
|
|
|
|
5728
|
return $reasontext; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub anotherone { |
|
103
|
|
|
|
|
|
|
# Detect the other bounce reason, fall back method for get() |
|
104
|
|
|
|
|
|
|
# @param [Sisimai::Data] argvs Parsed email object |
|
105
|
|
|
|
|
|
|
# @return [String, Undef] Bounce reason or Undef if the argument |
|
106
|
|
|
|
|
|
|
# is missing or invalid object |
|
107
|
|
|
|
|
|
|
# @see get |
|
108
|
571
|
|
|
571
|
0
|
1000
|
my $class = shift; |
|
109
|
571
|
|
100
|
|
|
2010
|
my $argvs = shift // return undef; |
|
110
|
|
|
|
|
|
|
|
|
111
|
570
|
50
|
|
|
|
1377
|
return undef unless ref $argvs eq 'Sisimai::Data'; |
|
112
|
570
|
100
|
|
|
|
1143
|
return $argvs->reason if $argvs->reason; |
|
113
|
|
|
|
|
|
|
|
|
114
|
483
|
|
|
|
|
3413
|
require Sisimai::SMTP::Status; |
|
115
|
483
|
|
50
|
|
|
1096
|
my $statuscode = $argvs->deliverystatus // ''; |
|
116
|
483
|
|
100
|
|
|
2731
|
my $reasontext = Sisimai::SMTP::Status->name($statuscode) || ''; |
|
117
|
|
|
|
|
|
|
|
|
118
|
483
|
|
|
|
|
771
|
TRY_TO_MATCH: while(1) { |
|
119
|
483
|
|
50
|
|
|
1214
|
my $diagnostic = lc $argvs->diagnosticcode // ''; |
|
120
|
483
|
100
|
|
|
|
3156
|
my $trytomatch = $reasontext eq '' ? 1 : 0; |
|
121
|
483
|
100
|
50
|
|
|
1453
|
$trytomatch ||= 1 if $reasontext eq 'expired'; |
|
122
|
483
|
100
|
50
|
|
|
1613
|
$trytomatch ||= 1 if exists $GetRetried->{ $reasontext }; |
|
123
|
483
|
100
|
50
|
|
|
999
|
$trytomatch ||= 1 if $argvs->diagnostictype ne 'SMTP'; |
|
124
|
483
|
100
|
|
|
|
2849
|
last unless $trytomatch; |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# Could not decide the reason by the value of Status: |
|
127
|
434
|
|
|
|
|
572
|
for my $e ( @{ $ClassOrder->[1] } ) { |
|
|
434
|
|
|
|
|
1120
|
|
|
128
|
|
|
|
|
|
|
# Trying to match with other patterns in Sisimai::Reason::* classes |
|
129
|
4045
|
|
|
|
|
6798
|
my $p = 'Sisimai::Reason::'.$e; |
|
130
|
4045
|
|
|
|
|
83480
|
require $ModulePath->{ $p }; |
|
131
|
|
|
|
|
|
|
|
|
132
|
4045
|
100
|
|
|
|
18619
|
next unless $p->match($diagnostic); |
|
133
|
288
|
|
|
|
|
840
|
$reasontext = lc $e; |
|
134
|
288
|
|
|
|
|
458
|
last; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
434
|
100
|
|
|
|
1303
|
last(TRY_TO_MATCH) if $reasontext; |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# Check the value of Status: |
|
139
|
70
|
50
|
33
|
|
|
822
|
if( (my $v = substr($statuscode, 0, 3)) =~ /\A[45][.]6\z/ ) { |
|
|
|
50
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# X.6.0 Other or undefined media error |
|
141
|
0
|
|
|
|
|
0
|
$reasontext = 'contenterror'; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
} elsif( $v eq '5.7' || $v eq '4.7' ) { |
|
144
|
|
|
|
|
|
|
# X.7.0 Other or undefined security status |
|
145
|
0
|
|
|
|
|
0
|
$reasontext = 'securityerror'; |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
} elsif( $argvs->diagnostictype eq 'X-UNIX' || $argvs->diagnostictype eq 'X-POSTFIX' ) { |
|
148
|
|
|
|
|
|
|
# Diagnostic-Code: X-UNIX; ... |
|
149
|
14
|
|
|
|
|
140
|
$reasontext = 'mailererror'; |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
} else { |
|
152
|
|
|
|
|
|
|
# 50X Syntax Error? |
|
153
|
56
|
|
|
|
|
4415
|
require Sisimai::Reason::SyntaxError; |
|
154
|
56
|
100
|
|
|
|
481
|
$reasontext = 'syntaxerror' if Sisimai::Reason::SyntaxError->true($argvs); |
|
155
|
|
|
|
|
|
|
} |
|
156
|
70
|
100
|
|
|
|
322
|
last(TRY_TO_MATCH) if $reasontext; |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# Check the value of Action: field, first |
|
159
|
51
|
100
|
|
|
|
159
|
if( $argvs->action =~ /\A(?:delayed|expired)/ ) { |
|
160
|
|
|
|
|
|
|
# Action: delayed, expired |
|
161
|
15
|
|
|
|
|
128
|
$reasontext = 'expired'; |
|
162
|
|
|
|
|
|
|
} else { |
|
163
|
|
|
|
|
|
|
# Check the value of SMTP command |
|
164
|
36
|
|
50
|
|
|
243
|
my $commandtxt = $argvs->smtpcommand // ''; |
|
165
|
36
|
100
|
66
|
|
|
799
|
if( $commandtxt eq 'EHLO' || $commandtxt eq 'HELO' ) { |
|
166
|
|
|
|
|
|
|
# Rejected at connection or after EHLO|HELO |
|
167
|
5
|
|
|
|
|
13
|
$reasontext = 'blocked'; |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
} |
|
170
|
51
|
|
|
|
|
178
|
last(TRY_TO_MATCH); |
|
171
|
|
|
|
|
|
|
} |
|
172
|
483
|
|
|
|
|
1180
|
return $reasontext; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub match { |
|
176
|
|
|
|
|
|
|
# Detect the bounce reason from given text |
|
177
|
|
|
|
|
|
|
# @param [String] argv1 Error message |
|
178
|
|
|
|
|
|
|
# @return [String] Bounce reason |
|
179
|
186
|
|
|
186
|
1
|
131693
|
my $class = shift; |
|
180
|
186
|
|
50
|
|
|
406
|
my $argv1 = shift // return undef; |
|
181
|
|
|
|
|
|
|
|
|
182
|
186
|
|
|
|
|
229
|
my $reasontext = ''; |
|
183
|
186
|
|
|
|
|
320
|
my $diagnostic = lc $argv1; |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
# Diagnostic-Code: SMTP; ... or empty value |
|
186
|
186
|
|
|
|
|
188
|
for my $e ( @{ $ClassOrder->[2] } ) { |
|
|
186
|
|
|
|
|
339
|
|
|
187
|
|
|
|
|
|
|
# Check the value of Diagnostic-Code: and the value of Status:, it is a |
|
188
|
|
|
|
|
|
|
# deliverystats, with true() method in each Sisimai::Reason::* class. |
|
189
|
2144
|
|
|
|
|
2930
|
my $p = 'Sisimai::Reason::'.$e; |
|
190
|
2144
|
|
|
|
|
6877
|
require $ModulePath->{ $p }; |
|
191
|
|
|
|
|
|
|
|
|
192
|
2144
|
100
|
|
|
|
4993
|
next unless $p->match($diagnostic); |
|
193
|
142
|
|
|
|
|
327
|
$reasontext = $p->text; |
|
194
|
142
|
|
|
|
|
199
|
last; |
|
195
|
|
|
|
|
|
|
} |
|
196
|
186
|
100
|
|
|
|
537
|
return $reasontext if $reasontext; |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
# Check the value of $typestring |
|
199
|
44
|
100
|
|
|
|
290
|
my $typestring = uc($argv1) =~ /\A(SMTP|X-.+);/ ? uc($1) : ''; |
|
200
|
44
|
100
|
|
|
|
86
|
if( $typestring eq 'X-UNIX' ) { |
|
201
|
|
|
|
|
|
|
# X-Unix; ... |
|
202
|
2
|
|
|
|
|
3
|
$reasontext = 'mailererror'; |
|
203
|
|
|
|
|
|
|
} else { |
|
204
|
|
|
|
|
|
|
# Detect the bounce reason from "Status:" code |
|
205
|
42
|
|
|
|
|
143
|
require Sisimai::SMTP::Status; |
|
206
|
42
|
|
100
|
|
|
103
|
my $statuscode = Sisimai::SMTP::Status->find($argv1) || ''; |
|
207
|
42
|
|
100
|
|
|
92
|
$reasontext = Sisimai::SMTP::Status->name($statuscode) || 'undefined'; |
|
208
|
|
|
|
|
|
|
} |
|
209
|
44
|
|
|
|
|
126
|
return $reasontext; |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
1; |
|
213
|
|
|
|
|
|
|
__END__ |