| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Sisimai::Lhost::Exim; |
|
2
|
30
|
|
|
30
|
|
6475
|
use parent 'Sisimai::Lhost'; |
|
|
30
|
|
|
|
|
56
|
|
|
|
30
|
|
|
|
|
159
|
|
|
3
|
30
|
|
|
30
|
|
1952
|
use feature ':5.10'; |
|
|
30
|
|
|
|
|
52
|
|
|
|
30
|
|
|
|
|
2132
|
|
|
4
|
30
|
|
|
30
|
|
160
|
use strict; |
|
|
30
|
|
|
|
|
56
|
|
|
|
30
|
|
|
|
|
710
|
|
|
5
|
30
|
|
|
30
|
|
143
|
use warnings; |
|
|
30
|
|
|
|
|
68
|
|
|
|
30
|
|
|
|
|
92897
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
1
|
1233
|
sub description { 'Exim' } |
|
8
|
|
|
|
|
|
|
sub make { |
|
9
|
|
|
|
|
|
|
# Detect an error from Exim |
|
10
|
|
|
|
|
|
|
# @param [Hash] mhead Message headers of a bounce email |
|
11
|
|
|
|
|
|
|
# @param [String] mbody Message body of a bounce email |
|
12
|
|
|
|
|
|
|
# @return [Hash] Bounce data list and message/rfc822 part |
|
13
|
|
|
|
|
|
|
# @return [Undef] failed to parse or the arguments are missing |
|
14
|
|
|
|
|
|
|
# @since v4.0.0 |
|
15
|
543
|
|
|
543
|
1
|
1370
|
my $class = shift; |
|
16
|
543
|
|
100
|
|
|
1334
|
my $mhead = shift // return undef; |
|
17
|
542
|
|
50
|
|
|
1225
|
my $mbody = shift // return undef; |
|
18
|
542
|
|
|
|
|
702
|
my $match = 0; |
|
19
|
542
|
50
|
|
|
|
1603
|
return undef if $mhead->{'from'} =~/[@].+[.]mail[.]ru[>]?/; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Message-Id: |
|
22
|
|
|
|
|
|
|
# X-Failed-Recipients: kijitora@example.ed.jp |
|
23
|
542
|
100
|
|
|
|
1343
|
$match++ if index($mhead->{'from'}, 'Mail Delivery System') == 0; |
|
24
|
|
|
|
|
|
|
$match++ if defined $mhead->{'message-id'} && |
|
25
|
542
|
100
|
100
|
|
|
3250
|
$mhead->{'message-id'} =~ /\A[<]\w{7}[-]\w{6}[-]\w{2}[@]/; |
|
26
|
542
|
100
|
|
|
|
5848
|
$match++ if $mhead->{'subject'} =~ qr{(?: |
|
27
|
|
|
|
|
|
|
Mail[ ]delivery[ ]failed(:[ ]returning[ ]message[ ]to[ ]sender)? |
|
28
|
|
|
|
|
|
|
|Warning:[ ]message[ ][^ ]+[ ]delayed[ ]+ |
|
29
|
|
|
|
|
|
|
|Delivery[ ]Status[ ]Notification |
|
30
|
|
|
|
|
|
|
|Mail[ ]failure |
|
31
|
|
|
|
|
|
|
|Message[ ]frozen |
|
32
|
|
|
|
|
|
|
|error[(]s[)][ ]in[ ]forwarding[ ]or[ ]filtering |
|
33
|
|
|
|
|
|
|
) |
|
34
|
|
|
|
|
|
|
}x; |
|
35
|
542
|
100
|
|
|
|
2078
|
return undef if $match < 2; |
|
36
|
|
|
|
|
|
|
|
|
37
|
223
|
|
|
|
|
427
|
state $indicators = __PACKAGE__->INDICATORS; |
|
38
|
223
|
|
|
|
|
326
|
state $rebackbone = qr{^(?: |
|
39
|
|
|
|
|
|
|
# deliver.c:6423| if (bounce_return_body) fprintf(f, |
|
40
|
|
|
|
|
|
|
# deliver.c:6424|"------ This is a copy of the message, including all the headers. ------\n"); |
|
41
|
|
|
|
|
|
|
# deliver.c:6425| else fprintf(f, |
|
42
|
|
|
|
|
|
|
# deliver.c:6426|"------ This is a copy of the message's headers. ------\n"); |
|
43
|
|
|
|
|
|
|
[-]+[ ]This[ ]is[ ]a[ ]copy[ ]of[ ](?:the|your)[ ]message,[ ]including[ ]all[ ]the[ ]headers[.][ ][-]+ |
|
44
|
|
|
|
|
|
|
|Content-Type:[ ]*message/rfc822\n(?:[\s\t]+.*?\n\n)? |
|
45
|
|
|
|
|
|
|
) |
|
46
|
|
|
|
|
|
|
}msx; |
|
47
|
223
|
|
|
|
|
351
|
state $startingof = { 'deliverystatus' => ['Content-type: message/delivery-status'] }; |
|
48
|
223
|
|
|
|
|
293
|
state $markingsof = { |
|
49
|
|
|
|
|
|
|
# Error text regular expressions which defined in exim/src/deliver.c |
|
50
|
|
|
|
|
|
|
# |
|
51
|
|
|
|
|
|
|
# deliver.c:6292| fprintf(f, |
|
52
|
|
|
|
|
|
|
# deliver.c:6293|"This message was created automatically by mail delivery software.\n"); |
|
53
|
|
|
|
|
|
|
# deliver.c:6294| if (to_sender) |
|
54
|
|
|
|
|
|
|
# deliver.c:6295| { |
|
55
|
|
|
|
|
|
|
# deliver.c:6296| fprintf(f, |
|
56
|
|
|
|
|
|
|
# deliver.c:6297|"\nA message that you sent could not be delivered to one or more of its\n" |
|
57
|
|
|
|
|
|
|
# deliver.c:6298|"recipients. This is a permanent error. The following address(es) failed:\n"); |
|
58
|
|
|
|
|
|
|
# deliver.c:6299| } |
|
59
|
|
|
|
|
|
|
# deliver.c:6300| else |
|
60
|
|
|
|
|
|
|
# deliver.c:6301| { |
|
61
|
|
|
|
|
|
|
# deliver.c:6302| fprintf(f, |
|
62
|
|
|
|
|
|
|
# deliver.c:6303|"\nA message sent by\n\n <%s>\n\n" |
|
63
|
|
|
|
|
|
|
# deliver.c:6304|"could not be delivered to one or more of its recipients. The following\n" |
|
64
|
|
|
|
|
|
|
# deliver.c:6305|"address(es) failed:\n", sender_address); |
|
65
|
|
|
|
|
|
|
# deliver.c:6306| } |
|
66
|
|
|
|
|
|
|
'alias' => qr/\A([ ]+an undisclosed address)\z/, |
|
67
|
|
|
|
|
|
|
'message' => qr{\A(?> |
|
68
|
|
|
|
|
|
|
This[ ]message[ ]was[ ]created[ ]automatically[ ]by[ ]mail[ ]delivery[ ]software[.] |
|
69
|
|
|
|
|
|
|
|A[ ]message[ ]that[ ]you[ ]sent[ ]was[ ]rejected[ ]by[ ]the[ ]local[ ]scannning[ ]code |
|
70
|
|
|
|
|
|
|
|A[ ]message[ ]that[ ]you[ ]sent[ ]contained[ ]one[ ]or[ ]more[ ]recipient[ ]addresses[ ] |
|
71
|
|
|
|
|
|
|
|A[ ]message[ ]that[ ]you[ ]sent[ ]could[ ]not[ ]be[ ]delivered[ ]to[ ]all[ ]of[ ]its[ ]recipients |
|
72
|
|
|
|
|
|
|
|Message[ ][^ ]+[ ](?:has[ ]been[ ]frozen|was[ ]frozen[ ]on[ ]arrival) |
|
73
|
|
|
|
|
|
|
|The[ ][^ ]+[ ]router[ ]encountered[ ]the[ ]following[ ]error[(]s[)]: |
|
74
|
|
|
|
|
|
|
) |
|
75
|
|
|
|
|
|
|
}x, |
|
76
|
|
|
|
|
|
|
'frozen' => qr/\AMessage [^ ]+ (?:has been frozen|was frozen on arrival)/, |
|
77
|
|
|
|
|
|
|
}; |
|
78
|
223
|
|
|
|
|
348
|
state $recommands = [ |
|
79
|
|
|
|
|
|
|
# transports/smtp.c:564| *message = US string_sprintf("SMTP error from remote mail server after %s%s: " |
|
80
|
|
|
|
|
|
|
# transports/smtp.c:837| string_sprintf("SMTP error from remote mail server after RCPT TO:<%s>: " |
|
81
|
|
|
|
|
|
|
qr/SMTP error from remote (?:mail server|mailer) after ([A-Za-z]{4})/, |
|
82
|
|
|
|
|
|
|
qr/SMTP error from remote (?:mail server|mailer) after end of ([A-Za-z]{4})/, |
|
83
|
|
|
|
|
|
|
qr/LMTP error after ([A-Za-z]{4})/, |
|
84
|
|
|
|
|
|
|
qr/LMTP error after end of ([A-Za-z]{4})/, |
|
85
|
|
|
|
|
|
|
]; |
|
86
|
223
|
|
|
|
|
365
|
state $messagesof = { |
|
87
|
|
|
|
|
|
|
# find exim/ -type f -exec grep 'message = US' {} /dev/null \; |
|
88
|
|
|
|
|
|
|
# route.c:1158| DEBUG(D_uid) debug_printf("getpwnam() returned NULL (user not found)\n"); |
|
89
|
|
|
|
|
|
|
'userunknown' => ['user not found'], |
|
90
|
|
|
|
|
|
|
# transports/smtp.c:3524| addr->message = US"all host address lookups failed permanently"; |
|
91
|
|
|
|
|
|
|
# routers/dnslookup.c:331| addr->message = US"all relevant MX records point to non-existent hosts"; |
|
92
|
|
|
|
|
|
|
# route.c:1826| uschar *message = US"Unrouteable address"; |
|
93
|
|
|
|
|
|
|
'hostunknown' => [ |
|
94
|
|
|
|
|
|
|
'all host address lookups failed permanently', |
|
95
|
|
|
|
|
|
|
'all relevant MX records point to non-existent hosts', |
|
96
|
|
|
|
|
|
|
'Unrouteable address', |
|
97
|
|
|
|
|
|
|
], |
|
98
|
|
|
|
|
|
|
# transports/appendfile.c:2567| addr->user_message = US"mailbox is full"; |
|
99
|
|
|
|
|
|
|
# transports/appendfile.c:3049| addr->message = string_sprintf("mailbox is full " |
|
100
|
|
|
|
|
|
|
# transports/appendfile.c:3050| "(quota exceeded while writing to file %s)", filename); |
|
101
|
|
|
|
|
|
|
'mailboxfull' => [ |
|
102
|
|
|
|
|
|
|
'mailbox is full', |
|
103
|
|
|
|
|
|
|
'error: quota exceed', |
|
104
|
|
|
|
|
|
|
], |
|
105
|
|
|
|
|
|
|
# routers/dnslookup.c:328| addr->message = US"an MX or SRV record indicated no SMTP service"; |
|
106
|
|
|
|
|
|
|
# transports/smtp.c:3502| addr->message = US"no host found for existing SMTP connection"; |
|
107
|
|
|
|
|
|
|
'notaccept' => [ |
|
108
|
|
|
|
|
|
|
'an MX or SRV record indicated no SMTP service', |
|
109
|
|
|
|
|
|
|
'no host found for existing SMTP connection', |
|
110
|
|
|
|
|
|
|
], |
|
111
|
|
|
|
|
|
|
# parser.c:666| *errorptr = string_sprintf("%s (expected word or \"<\")", *errorptr); |
|
112
|
|
|
|
|
|
|
# parser.c:701| if(bracket_count++ > 5) FAILED(US"angle-brackets nested too deep"); |
|
113
|
|
|
|
|
|
|
# parser.c:738| FAILED(US"domain missing in source-routed address"); |
|
114
|
|
|
|
|
|
|
# parser.c:747| : string_sprintf("malformed address: %.32s may not follow %.*s", |
|
115
|
|
|
|
|
|
|
'syntaxerror' => [ |
|
116
|
|
|
|
|
|
|
'angle-brackets nested too deep', |
|
117
|
|
|
|
|
|
|
'expected word or "<"', |
|
118
|
|
|
|
|
|
|
'domain missing in source-routed address', |
|
119
|
|
|
|
|
|
|
'malformed address:', |
|
120
|
|
|
|
|
|
|
], |
|
121
|
|
|
|
|
|
|
# deliver.c:5614| addr->message = US"delivery to file forbidden"; |
|
122
|
|
|
|
|
|
|
# deliver.c:5624| addr->message = US"delivery to pipe forbidden"; |
|
123
|
|
|
|
|
|
|
# transports/pipe.c:1156| addr->user_message = US"local delivery failed"; |
|
124
|
|
|
|
|
|
|
'systemerror' => [ |
|
125
|
|
|
|
|
|
|
'delivery to file forbidden', |
|
126
|
|
|
|
|
|
|
'delivery to pipe forbidden', |
|
127
|
|
|
|
|
|
|
'local delivery failed', |
|
128
|
|
|
|
|
|
|
'LMTP error after ', |
|
129
|
|
|
|
|
|
|
], |
|
130
|
|
|
|
|
|
|
# deliver.c:5425| new->message = US"Too many \"Received\" headers - suspected mail loop"; |
|
131
|
|
|
|
|
|
|
'contenterror' => ['Too many "Received" headers'], |
|
132
|
|
|
|
|
|
|
}; |
|
133
|
223
|
|
|
|
|
302
|
state $delayedfor = [ |
|
134
|
|
|
|
|
|
|
# retry.c:902| addr->message = (addr->message == NULL)? US"retry timeout exceeded" : |
|
135
|
|
|
|
|
|
|
# deliver.c:7475| "No action is required on your part. Delivery attempts will continue for\n" |
|
136
|
|
|
|
|
|
|
# smtp.c:3508| US"retry time not reached for any host after a long failure period" : |
|
137
|
|
|
|
|
|
|
# smtp.c:3508| US"all hosts have been failing for a long time and were last tried " |
|
138
|
|
|
|
|
|
|
# "after this message arrived"; |
|
139
|
|
|
|
|
|
|
# deliver.c:7459| print_address_error(addr, f, US"Delay reason: "); |
|
140
|
|
|
|
|
|
|
# deliver.c:7586| "Message %s has been frozen%s.\nThe sender is <%s>.\n", message_id, |
|
141
|
|
|
|
|
|
|
# receive.c:4021| moan_tell_someone(freeze_tell, NULL, US"Message frozen on arrival", |
|
142
|
|
|
|
|
|
|
# receive.c:4022| "Message %s was frozen on arrival by %s.\nThe sender is <%s>.\n", |
|
143
|
|
|
|
|
|
|
'retry timeout exceeded', |
|
144
|
|
|
|
|
|
|
'No action is required on your part', |
|
145
|
|
|
|
|
|
|
'retry time not reached for any host after a long failure period', |
|
146
|
|
|
|
|
|
|
'all hosts have been failing for a long time and were last tried', |
|
147
|
|
|
|
|
|
|
'Delay reason: ', |
|
148
|
|
|
|
|
|
|
'has been frozen', |
|
149
|
|
|
|
|
|
|
'was frozen on arrival by ', |
|
150
|
|
|
|
|
|
|
]; |
|
151
|
|
|
|
|
|
|
|
|
152
|
223
|
|
|
|
|
1677
|
require Sisimai::RFC1894; |
|
153
|
223
|
|
|
|
|
1012
|
my $fieldtable = Sisimai::RFC1894->FIELDTABLE; |
|
154
|
223
|
|
|
|
|
943
|
my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; |
|
155
|
223
|
|
|
|
|
1064
|
my $emailsteak = Sisimai::RFC5322->fillet($mbody, $rebackbone); |
|
156
|
223
|
|
|
|
|
439
|
my $readcursor = 0; # (Integer) Points the current cursor position |
|
157
|
223
|
|
|
|
|
414
|
my $nextcursor = 0; |
|
158
|
223
|
|
|
|
|
317
|
my $recipients = 0; # (Integer) The number of 'Final-Recipient' header |
|
159
|
223
|
|
|
|
|
356
|
my $localhost0 = ''; # (String) Local MTA |
|
160
|
223
|
|
|
|
|
340
|
my $boundary00 = ''; # (String) Boundary string |
|
161
|
223
|
|
|
|
|
364
|
my $v = undef; |
|
162
|
|
|
|
|
|
|
|
|
163
|
223
|
100
|
|
|
|
646
|
if( $mhead->{'content-type'} ) { |
|
164
|
|
|
|
|
|
|
# Get the boundary string and set regular expression for matching with |
|
165
|
|
|
|
|
|
|
# the boundary string. |
|
166
|
41
|
|
|
|
|
271
|
$boundary00 = Sisimai::MIME->boundary($mhead->{'content-type'}); |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
223
|
|
|
|
|
1572
|
for my $e ( split("\n", $emailsteak->[0]) ) { |
|
170
|
|
|
|
|
|
|
# Read error messages and delivery status lines from the head of the email |
|
171
|
|
|
|
|
|
|
# to the previous line of the beginning of the original message. |
|
172
|
2707
|
100
|
|
|
|
4100
|
unless( $readcursor ) { |
|
173
|
|
|
|
|
|
|
# Beginning of the bounce message or message/delivery-status part |
|
174
|
263
|
100
|
|
|
|
1870
|
if( $e =~ $markingsof->{'message'} ) { |
|
175
|
223
|
|
|
|
|
473
|
$readcursor |= $indicators->{'deliverystatus'}; |
|
176
|
223
|
50
|
|
|
|
985
|
next unless $e =~ $markingsof->{'frozen'}; |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
} |
|
179
|
2484
|
100
|
|
|
|
3939
|
next unless $readcursor & $indicators->{'deliverystatus'}; |
|
180
|
2444
|
100
|
|
|
|
3364
|
next unless length $e; |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# This message was created automatically by mail delivery software. |
|
183
|
|
|
|
|
|
|
# |
|
184
|
|
|
|
|
|
|
# A message that you sent could not be delivered to one or more of its |
|
185
|
|
|
|
|
|
|
# recipients. This is a permanent error. The following address(es) failed: |
|
186
|
|
|
|
|
|
|
# |
|
187
|
|
|
|
|
|
|
# kijitora@example.jp |
|
188
|
|
|
|
|
|
|
# SMTP error from remote mail server after RCPT TO:: |
|
189
|
|
|
|
|
|
|
# host neko.example.jp [192.0.2.222]: 550 5.1.1 ... User Unknown |
|
190
|
1829
|
|
|
|
|
2111
|
$v = $dscontents->[-1]; |
|
191
|
|
|
|
|
|
|
|
|
192
|
1829
|
100
|
100
|
|
|
14698
|
if( $e =~ /\A[ \t]{2}([^ \t]+[@][^ \t]+[.]?[a-zA-Z]+)(:.+)?\z/ || |
|
|
|
100
|
66
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
193
|
|
|
|
|
|
|
$e =~ /\A[ \t]{2}[^ \t]+[@][^ \t]+[.][a-zA-Z]+[ ]<(.+?[@].+?)>:.+\z/ || |
|
194
|
|
|
|
|
|
|
$e =~ $markingsof->{'alias'} ) { |
|
195
|
|
|
|
|
|
|
# kijitora@example.jp |
|
196
|
|
|
|
|
|
|
# sabineko@example.jp: forced freeze |
|
197
|
|
|
|
|
|
|
# mikeneko@example.jp : ... |
|
198
|
|
|
|
|
|
|
# |
|
199
|
|
|
|
|
|
|
# deliver.c:4549| printed = US"an undisclosed address"; |
|
200
|
|
|
|
|
|
|
# an undisclosed address |
|
201
|
|
|
|
|
|
|
# (generated from kijitora@example.jp) |
|
202
|
187
|
|
|
|
|
611
|
my $r = $1; |
|
203
|
|
|
|
|
|
|
|
|
204
|
187
|
100
|
|
|
|
521
|
if( $v->{'recipient'} ) { |
|
205
|
|
|
|
|
|
|
# There are multiple recipient addresses in the message body. |
|
206
|
5
|
|
|
|
|
35
|
push @$dscontents, __PACKAGE__->DELIVERYSTATUS; |
|
207
|
5
|
|
|
|
|
20
|
$v = $dscontents->[-1]; |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
|
|
210
|
187
|
100
|
|
|
|
540
|
if( $e =~ /\A[ \t]+[^ \t]+[@][^ \t]+[.][a-zA-Z]+[ ]<(.+?[@].+?)>:.+\z/ ) { |
|
211
|
|
|
|
|
|
|
# parser.c:743| while (bracket_count-- > 0) if (*s++ != '>') |
|
212
|
|
|
|
|
|
|
# parser.c:744| { |
|
213
|
|
|
|
|
|
|
# parser.c:745| *errorptr = s[-1] == 0 |
|
214
|
|
|
|
|
|
|
# parser.c:746| ? US"'>' missing at end of address" |
|
215
|
|
|
|
|
|
|
# parser.c:747| : string_sprintf("malformed address: %.32s may not follow %.*s", |
|
216
|
|
|
|
|
|
|
# parser.c:748| s-1, (int)(s - US mailbox - 1), mailbox); |
|
217
|
|
|
|
|
|
|
# parser.c:749| goto PARSE_FAILED; |
|
218
|
|
|
|
|
|
|
# parser.c:750| } |
|
219
|
5
|
|
|
|
|
16
|
$r = $1; |
|
220
|
5
|
|
|
|
|
14
|
$v->{'diagnosis'} = $e; |
|
221
|
|
|
|
|
|
|
} |
|
222
|
187
|
|
|
|
|
417
|
$v->{'recipient'} = $r; |
|
223
|
187
|
|
|
|
|
303
|
$recipients++; |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
} elsif( $e =~ /\A[ ]+[(]generated[ ]from[ ](.+)[)]\z/ || |
|
226
|
|
|
|
|
|
|
$e =~ /\A[ ]+generated[ ]by[ ]([^ \t]+[@][^ \t]+)/ ) { |
|
227
|
|
|
|
|
|
|
# (generated from kijitora@example.jp) |
|
228
|
|
|
|
|
|
|
# pipe to |/bin/echo "Some pipe output" |
|
229
|
|
|
|
|
|
|
# generated by userx@myhost.test.ex |
|
230
|
31
|
|
|
|
|
128
|
$v->{'alias'} = $1; |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
} else { |
|
233
|
1611
|
50
|
|
|
|
2603
|
next unless length $e; |
|
234
|
|
|
|
|
|
|
|
|
235
|
1611
|
50
|
|
|
|
3464
|
if( $e =~ $markingsof->{'frozen'} ) { |
|
236
|
|
|
|
|
|
|
# Message *** has been frozen by the system filter. |
|
237
|
|
|
|
|
|
|
# Message *** was frozen on arrival by ACL. |
|
238
|
0
|
|
|
|
|
0
|
$v->{'alterrors'} .= $e.' '; |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
} else { |
|
241
|
1611
|
100
|
|
|
|
2255
|
if( $boundary00 ) { |
|
242
|
|
|
|
|
|
|
# --NNNNNNNNNN-eximdsn-MMMMMMMMMM |
|
243
|
|
|
|
|
|
|
# Content-type: message/delivery-status |
|
244
|
|
|
|
|
|
|
# ... |
|
245
|
355
|
100
|
|
|
|
803
|
if( Sisimai::RFC1894->match($e) ) { |
|
246
|
|
|
|
|
|
|
# $e matched with any field defined in RFC3464 |
|
247
|
160
|
50
|
|
|
|
395
|
next unless my $o = Sisimai::RFC1894->field($e); |
|
248
|
|
|
|
|
|
|
|
|
249
|
160
|
100
|
|
|
|
554
|
if( $o->[-1] eq 'addr' ) { |
|
|
|
100
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
# Final-Recipient: rfc822;|/bin/echo "Some pipe output" |
|
251
|
30
|
50
|
|
|
|
232
|
next unless $o->[0] eq 'final-recipient'; |
|
252
|
30
|
100
|
33
|
|
|
245
|
$v->{'spec'} ||= rindex($o->[2], '@') > -1 ? 'SMTP' : 'X-UNIX'; |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
} elsif( $o->[-1] eq 'code' ) { |
|
255
|
|
|
|
|
|
|
# Diagnostic-Code: SMTP; 550 5.1.1 ... User Unknown |
|
256
|
20
|
|
|
|
|
125
|
$v->{'spec'} = uc $o->[1]; |
|
257
|
20
|
|
|
|
|
83
|
$v->{'diagnosis'} = $o->[2]; |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
} else { |
|
260
|
|
|
|
|
|
|
# Other DSN fields defined in RFC3464 |
|
261
|
110
|
50
|
|
|
|
285
|
next unless exists $fieldtable->{ $o->[0] }; |
|
262
|
110
|
|
|
|
|
383
|
$v->{ $fieldtable->{ $o->[0] } } = $o->[2]; |
|
263
|
|
|
|
|
|
|
} |
|
264
|
|
|
|
|
|
|
} else { |
|
265
|
|
|
|
|
|
|
# Error message ? |
|
266
|
195
|
50
|
|
|
|
381
|
next if $nextcursor; |
|
267
|
|
|
|
|
|
|
# Content-type: message/delivery-status |
|
268
|
195
|
50
|
|
|
|
516
|
$nextcursor = 1 if index($e, $startingof->{'deliverystatus'}) == 0; |
|
269
|
195
|
100
|
|
|
|
820
|
$v->{'alterrors'} .= $e.' ' if index($e, ' ') == 0; |
|
270
|
|
|
|
|
|
|
} |
|
271
|
|
|
|
|
|
|
} else { |
|
272
|
1256
|
100
|
|
|
|
1797
|
if( scalar @$dscontents == $recipients ) { |
|
273
|
|
|
|
|
|
|
# Error message |
|
274
|
524
|
50
|
|
|
|
981
|
next unless length $e; |
|
275
|
524
|
|
|
|
|
1551
|
$v->{'diagnosis'} .= $e.' '; |
|
276
|
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
} else { |
|
278
|
|
|
|
|
|
|
# Error message when email address above does not include '@' |
|
279
|
|
|
|
|
|
|
# and domain part. |
|
280
|
732
|
100
|
|
|
|
1155
|
if( $e =~ m<\A[ ]+pipe[ ]to[ ][|]/[^ ]+> ) { |
|
281
|
|
|
|
|
|
|
# pipe to |/path/to/prog ... |
|
282
|
|
|
|
|
|
|
# generated by kijitora@example.com |
|
283
|
5
|
|
|
|
|
17
|
$v->{'diagnosis'} = $e; |
|
284
|
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
} else { |
|
286
|
727
|
100
|
|
|
|
1629
|
next unless index($e, ' ') == 0; |
|
287
|
61
|
|
|
|
|
275
|
$v->{'alterrors'} .= $e.' '; |
|
288
|
|
|
|
|
|
|
} |
|
289
|
|
|
|
|
|
|
} |
|
290
|
|
|
|
|
|
|
} |
|
291
|
|
|
|
|
|
|
} |
|
292
|
|
|
|
|
|
|
} |
|
293
|
|
|
|
|
|
|
} |
|
294
|
|
|
|
|
|
|
|
|
295
|
223
|
100
|
|
|
|
789
|
if( $recipients ) { |
|
296
|
|
|
|
|
|
|
# Check "an undisclosed address", "unroutable address" |
|
297
|
182
|
|
|
|
|
353
|
for my $q ( @$dscontents ) { |
|
298
|
|
|
|
|
|
|
# Replace the recipient address with the value of "alias" |
|
299
|
187
|
100
|
|
|
|
507
|
next unless $q->{'alias'}; |
|
300
|
6
|
50
|
33
|
|
|
45
|
if( ! $q->{'recipient'} || rindex($q->{'recipient'}, '@') == -1 ) { |
|
301
|
|
|
|
|
|
|
# The value of "recipient" is empty or does not include "@" |
|
302
|
0
|
|
|
|
|
0
|
$q->{'recipient'} = $q->{'alias'}; |
|
303
|
|
|
|
|
|
|
} |
|
304
|
|
|
|
|
|
|
} |
|
305
|
|
|
|
|
|
|
} else { |
|
306
|
|
|
|
|
|
|
# Fallback for getting recipient addresses |
|
307
|
41
|
100
|
|
|
|
291
|
if( defined $mhead->{'x-failed-recipients'} ) { |
|
308
|
|
|
|
|
|
|
# X-Failed-Recipients: kijitora@example.jp |
|
309
|
30
|
|
|
|
|
141
|
my @rcptinhead = split(',', $mhead->{'x-failed-recipients'}); |
|
310
|
30
|
|
|
|
|
81
|
for my $e ( @rcptinhead ) { $e =~ s/\A[ ]+//; $e =~ s/[ ]+\z// } |
|
|
30
|
|
|
|
|
78
|
|
|
|
30
|
|
|
|
|
73
|
|
|
311
|
30
|
|
|
|
|
54
|
$recipients = scalar @rcptinhead; |
|
312
|
|
|
|
|
|
|
|
|
313
|
30
|
|
|
|
|
67
|
for my $e ( @rcptinhead ) { |
|
314
|
|
|
|
|
|
|
# Insert each recipient address into @$dscontents |
|
315
|
30
|
|
|
|
|
69
|
$dscontents->[-1]->{'recipient'} = $e; |
|
316
|
30
|
50
|
|
|
|
110
|
next if scalar @$dscontents == $recipients; |
|
317
|
0
|
|
|
|
|
0
|
push @$dscontents, __PACKAGE__->DELIVERYSTATUS; |
|
318
|
|
|
|
|
|
|
} |
|
319
|
|
|
|
|
|
|
} |
|
320
|
|
|
|
|
|
|
} |
|
321
|
223
|
100
|
|
|
|
548
|
return undef unless $recipients; |
|
322
|
|
|
|
|
|
|
|
|
323
|
212
|
100
|
|
|
|
283
|
if( scalar @{ $mhead->{'received'} } ) { |
|
|
212
|
|
|
|
|
598
|
|
|
324
|
|
|
|
|
|
|
# Get the name of local MTA |
|
325
|
|
|
|
|
|
|
# Received: from marutamachi.example.org (c192128.example.net [192.0.2.128]) |
|
326
|
206
|
50
|
|
|
|
1471
|
$localhost0 = $1 if $mhead->{'received'}->[-1] =~ /from[ \t]([^ ]+) /; |
|
327
|
|
|
|
|
|
|
} |
|
328
|
|
|
|
|
|
|
|
|
329
|
212
|
|
|
|
|
460
|
for my $e ( @$dscontents ) { |
|
330
|
|
|
|
|
|
|
# Set default values if each value is empty. |
|
331
|
217
|
|
66
|
|
|
857
|
$e->{'lhost'} ||= $localhost0; |
|
332
|
|
|
|
|
|
|
|
|
333
|
217
|
100
|
100
|
|
|
657
|
if( ! $e->{'diagnosis'} && length($boundary00) > 0 ) { |
|
334
|
|
|
|
|
|
|
# Empty Diagnostic-Code: or error message |
|
335
|
|
|
|
|
|
|
# --NNNNNNNNNN-eximdsn-MMMMMMMMMM |
|
336
|
|
|
|
|
|
|
# Content-type: message/delivery-status |
|
337
|
|
|
|
|
|
|
# |
|
338
|
|
|
|
|
|
|
# Reporting-MTA: dns; the.local.host.name |
|
339
|
|
|
|
|
|
|
# |
|
340
|
|
|
|
|
|
|
# Action: failed |
|
341
|
|
|
|
|
|
|
# Final-Recipient: rfc822;/a/b/c |
|
342
|
|
|
|
|
|
|
# Status: 5.0.0 |
|
343
|
|
|
|
|
|
|
# |
|
344
|
|
|
|
|
|
|
# Action: failed |
|
345
|
|
|
|
|
|
|
# Final-Recipient: rfc822;|/p/q/r |
|
346
|
|
|
|
|
|
|
# Status: 5.0.0 |
|
347
|
10
|
|
50
|
|
|
79
|
$e->{'diagnosis'} = $dscontents->[0]->{'diagnosis'} || ''; |
|
348
|
10
|
|
33
|
|
|
34
|
$e->{'spec'} ||= $dscontents->[0]->{'spec'}; |
|
349
|
|
|
|
|
|
|
|
|
350
|
10
|
50
|
|
|
|
39
|
if( $dscontents->[0]->{'alterrors'} ) { |
|
351
|
|
|
|
|
|
|
# The value of "alterrors" is also copied |
|
352
|
10
|
|
|
|
|
32
|
$e->{'alterrors'} = $dscontents->[0]->{'alterrors'}; |
|
353
|
|
|
|
|
|
|
} |
|
354
|
|
|
|
|
|
|
} |
|
355
|
|
|
|
|
|
|
|
|
356
|
217
|
50
|
66
|
|
|
618
|
if( exists $e->{'alterrors'} && $e->{'alterrors'} ) { |
|
357
|
|
|
|
|
|
|
# Copy alternative error message |
|
358
|
45
|
|
66
|
|
|
219
|
$e->{'diagnosis'} ||= $e->{'alterrors'}; |
|
359
|
|
|
|
|
|
|
|
|
360
|
45
|
50
|
33
|
|
|
288
|
if( index($e->{'diagnosis'}, '-') == 0 || substr($e->{'diagnosis'}, -2, 2) eq '__' ) { |
|
361
|
|
|
|
|
|
|
# Override the value of diagnostic code message |
|
362
|
0
|
0
|
|
|
|
0
|
$e->{'diagnosis'} = $e->{'alterrors'} if $e->{'alterrors'}; |
|
363
|
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
} else { |
|
365
|
|
|
|
|
|
|
# Check the both value and try to match |
|
366
|
45
|
100
|
|
|
|
176
|
if( length($e->{'diagnosis'}) < length($e->{'alterrors'}) ) { |
|
367
|
|
|
|
|
|
|
# Check the value of alterrors |
|
368
|
20
|
|
|
|
|
316
|
my $rxdiagnosis = qr/\Q$e->{'diagnosis'}\E/i; |
|
369
|
20
|
50
|
|
|
|
297
|
if( $e->{'alterrors'} =~ $rxdiagnosis ) { |
|
370
|
|
|
|
|
|
|
# Override the value of diagnostic code message because |
|
371
|
|
|
|
|
|
|
# the value of alterrors includes the value of diagnosis. |
|
372
|
20
|
|
|
|
|
72
|
$e->{'diagnosis'} = $e->{'alterrors'}; |
|
373
|
|
|
|
|
|
|
} |
|
374
|
|
|
|
|
|
|
} |
|
375
|
|
|
|
|
|
|
} |
|
376
|
45
|
|
|
|
|
87
|
delete $e->{'alterrors'}; |
|
377
|
|
|
|
|
|
|
} |
|
378
|
217
|
|
|
|
|
1315
|
$e->{'diagnosis'} = Sisimai::String->sweep($e->{'diagnosis'}); |
|
379
|
217
|
|
|
|
|
695
|
$e->{'diagnosis'} =~ s/\b__.+\z//; |
|
380
|
|
|
|
|
|
|
|
|
381
|
217
|
100
|
|
|
|
565
|
unless( $e->{'rhost'} ) { |
|
382
|
|
|
|
|
|
|
# Get the remote host name |
|
383
|
|
|
|
|
|
|
# host neko.example.jp [192.0.2.222]: 550 5.1.1 ... User Unknown |
|
384
|
187
|
100
|
|
|
|
1017
|
$e->{'rhost'} = $1 if $e->{'diagnosis'} =~ /host[ \t]+([^ \t]+)[ \t]\[.+\]:[ \t]/; |
|
385
|
|
|
|
|
|
|
|
|
386
|
187
|
50
|
100
|
|
|
548
|
if( ! $e->{'rhost'} && scalar @{ $mhead->{'received'} } ) { |
|
|
115
|
|
|
|
|
428
|
|
|
387
|
|
|
|
|
|
|
# Get localhost and remote host name from Received header. |
|
388
|
115
|
|
|
|
|
251
|
my $r0 = $mhead->{'received'}; |
|
389
|
115
|
|
|
|
|
135
|
$e->{'rhost'} = pop @{ Sisimai::RFC5322->received($r0->[-1]) }; |
|
|
115
|
|
|
|
|
398
|
|
|
390
|
|
|
|
|
|
|
} |
|
391
|
|
|
|
|
|
|
} |
|
392
|
|
|
|
|
|
|
|
|
393
|
217
|
50
|
|
|
|
574
|
unless( $e->{'command'} ) { |
|
394
|
|
|
|
|
|
|
# Get the SMTP command name for the session |
|
395
|
217
|
|
|
|
|
487
|
SMTP: for my $r ( @$recommands ) { |
|
396
|
|
|
|
|
|
|
# Verify each regular expression of SMTP commands |
|
397
|
383
|
100
|
|
|
|
2163
|
next unless $e->{'diagnosis'} =~ $r; |
|
398
|
172
|
|
|
|
|
507
|
$e->{'command'} = uc $1; |
|
399
|
172
|
|
|
|
|
337
|
last; |
|
400
|
|
|
|
|
|
|
} |
|
401
|
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
# Detect the reason of bounce |
|
403
|
217
|
100
|
66
|
|
|
1150
|
if( $e->{'command'} eq 'HELO' || $e->{'command'} eq 'EHLO' ) { |
|
|
|
100
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
# HELO | Connected to 192.0.2.135 but my name was rejected. |
|
405
|
5
|
|
|
|
|
29
|
$e->{'reason'} = 'blocked'; |
|
406
|
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
} elsif( $e->{'command'} eq 'MAIL' ) { |
|
408
|
|
|
|
|
|
|
# MAIL | Connected to 192.0.2.135 but sender was rejected. |
|
409
|
|
|
|
|
|
|
# $e->{'reason'} = 'rejected'; |
|
410
|
71
|
|
|
|
|
211
|
$e->{'reason'} = 'onhold'; |
|
411
|
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
} else { |
|
413
|
|
|
|
|
|
|
# Verify each regular expression of session errors |
|
414
|
141
|
|
|
|
|
589
|
SESSION: for my $r ( keys %$messagesof ) { |
|
415
|
|
|
|
|
|
|
# Check each regular expression |
|
416
|
936
|
100
|
|
|
|
989
|
next unless grep { index($e->{'diagnosis'}, $_) > -1 } @{ $messagesof->{ $r } }; |
|
|
2314
|
|
|
|
|
5984
|
|
|
|
936
|
|
|
|
|
1612
|
|
|
417
|
15
|
|
|
|
|
40
|
$e->{'reason'} = $r; |
|
418
|
15
|
|
|
|
|
56
|
last; |
|
419
|
|
|
|
|
|
|
} |
|
420
|
|
|
|
|
|
|
|
|
421
|
141
|
100
|
|
|
|
478
|
unless( $e->{'reason'} ) { |
|
422
|
|
|
|
|
|
|
# The reason "expired" |
|
423
|
126
|
100
|
|
|
|
314
|
$e->{'reason'} = 'expired' if grep { index($e->{'diagnosis'}, $_) > -1 } @$delayedfor; |
|
|
882
|
|
|
|
|
2133
|
|
|
424
|
|
|
|
|
|
|
} |
|
425
|
|
|
|
|
|
|
} |
|
426
|
|
|
|
|
|
|
} |
|
427
|
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
STATUS: { |
|
429
|
|
|
|
|
|
|
# Prefer the value of smtp reply code in Diagnostic-Code: |
|
430
|
|
|
|
|
|
|
# See set-of-emails/maildir/bsd/exim-20.eml |
|
431
|
|
|
|
|
|
|
# Action: failed |
|
432
|
|
|
|
|
|
|
# Final-Recipient: rfc822;userx@test.ex |
|
433
|
|
|
|
|
|
|
# Status: 5.0.0 |
|
434
|
|
|
|
|
|
|
# Remote-MTA: dns; 127.0.0.1 |
|
435
|
|
|
|
|
|
|
# Diagnostic-Code: smtp; 450 TEMPERROR: retry timeout exceeded |
|
436
|
|
|
|
|
|
|
# The value of "Status:" indicates permanent error but the value |
|
437
|
|
|
|
|
|
|
# of SMTP reply code in Diagnostic-Code: field is "TEMPERROR"!!!! |
|
438
|
217
|
|
100
|
|
|
326
|
my $sv = $e->{'status'} || Sisimai::SMTP::Status->find($e->{'diagnosis'}) || ''; |
|
|
217
|
|
|
|
|
1413
|
|
|
439
|
217
|
|
100
|
|
|
1370
|
my $rv = $e->{'replycode'} || Sisimai::SMTP::Reply->find($e->{'diagnosis'}) || ''; |
|
440
|
217
|
|
|
|
|
567
|
my $s1 = 0; # First character of Status as integer |
|
441
|
217
|
|
|
|
|
300
|
my $r1 = 0; # First character of SMTP reply code as integer |
|
442
|
217
|
|
|
|
|
301
|
my $v1 = 0; |
|
443
|
|
|
|
|
|
|
|
|
444
|
217
|
|
|
|
|
262
|
FIND_CODE: while(1) { |
|
445
|
|
|
|
|
|
|
# "Status:" field did not exist in the bounce message |
|
446
|
217
|
100
|
|
|
|
519
|
last if $sv; |
|
447
|
100
|
100
|
|
|
|
211
|
last unless $rv; |
|
448
|
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
# Check SMTP reply code |
|
450
|
|
|
|
|
|
|
# Generate pseudo DSN code from SMTP reply code |
|
451
|
60
|
|
|
|
|
212
|
$r1 = substr($rv, 0, 1); |
|
452
|
60
|
100
|
|
|
|
273
|
if( $r1 == 4 ) { |
|
|
|
50
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
# Get the internal DSN(temporary error) |
|
454
|
10
|
|
50
|
|
|
44
|
$sv = Sisimai::SMTP::Status->code($e->{'reason'}, 1) || ''; |
|
455
|
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
} elsif( $r1 == 5 ) { |
|
457
|
|
|
|
|
|
|
# Get the internal DSN(permanent error) |
|
458
|
50
|
|
100
|
|
|
169
|
$sv = Sisimai::SMTP::Status->code($e->{'reason'}, 0) || ''; |
|
459
|
|
|
|
|
|
|
} |
|
460
|
60
|
|
|
|
|
100
|
last; |
|
461
|
|
|
|
|
|
|
} |
|
462
|
|
|
|
|
|
|
|
|
463
|
217
|
100
|
|
|
|
654
|
$s1 = substr($sv, 0, 1) if $sv; |
|
464
|
217
|
|
|
|
|
347
|
$v1 = $s1 + $r1; |
|
465
|
217
|
100
|
|
|
|
552
|
$v1 += substr($e->{'status'}, 0, 1) if $e->{'status'}; |
|
466
|
|
|
|
|
|
|
|
|
467
|
217
|
100
|
|
|
|
441
|
if( $v1 > 0 ) { |
|
468
|
|
|
|
|
|
|
# Status or SMTP reply code exists |
|
469
|
|
|
|
|
|
|
# Set pseudo DSN into the value of "status" accessor |
|
470
|
177
|
100
|
|
|
|
480
|
$e->{'status'} = $sv if $r1 > 0; |
|
471
|
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
} else { |
|
473
|
|
|
|
|
|
|
# Neither Status nor SMTP reply code exist |
|
474
|
40
|
100
|
100
|
|
|
268
|
if( $e->{'reason'} eq 'expired' || $e->{'reason'} eq 'mailboxfull' ) { |
|
475
|
|
|
|
|
|
|
# Set pseudo DSN (temporary error) |
|
476
|
15
|
|
50
|
|
|
50
|
$sv = Sisimai::SMTP::Status->code($e->{'reason'}, 1) || ''; |
|
477
|
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
} else { |
|
479
|
|
|
|
|
|
|
# Set pseudo DSN (permanent error) |
|
480
|
25
|
|
100
|
|
|
82
|
$sv = Sisimai::SMTP::Status->code($e->{'reason'}, 0) || ''; |
|
481
|
|
|
|
|
|
|
} |
|
482
|
|
|
|
|
|
|
} |
|
483
|
217
|
|
100
|
|
|
734
|
$e->{'status'} ||= $sv; |
|
484
|
|
|
|
|
|
|
} |
|
485
|
217
|
|
100
|
|
|
635
|
$e->{'command'} ||= ''; |
|
486
|
|
|
|
|
|
|
} |
|
487
|
212
|
|
|
|
|
1513
|
return { 'ds' => $dscontents, 'rfc822' => $emailsteak->[1] }; |
|
488
|
|
|
|
|
|
|
} |
|
489
|
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
1; |
|
491
|
|
|
|
|
|
|
__END__ |