Sisimai/Lhost/Exim.pm

filter: Statementstmt 97.2% 179 / 184 Branchbran 85.8% 115 / 134 Conditioncond 70.5% 67 / 95 MC/DCmcdc 50.8% 29 / 57 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 83.2% 398 / 478 CC 115 SCAR 49.3
CC
115
Cov
87%
inquire
144.1
BEGIN
1.0
BEGIN
1.0
CRAP 138.1
« Sisimai/Fact.pm ↑ Summary Sisimai/Lhost/Postfix.pm »
1 package Sisimai::Lhost::Exim;
2 52 ▶use parent 'Sisimai::Lhost';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 52 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 52 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 52 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶sub description { 'Exim' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
8 1411 ▶sub inquire {
Subroutine inquire: called CC=115 SCAR=49.7
Pod documented
9 # Detect an error from Exim Internet Mailer
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 decode or the arguments are missing
14 # @since v4.0.0
15 1411 my $class = shift;
16 1411 ▶ my $mhead = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
14083
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
17 1408 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
14053
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18 1405 ▶ return undef if grep { index($$mbody, $_) > 0 } __PACKAGE__->BannerDTAG->@*;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($$mbody, $_) > 0;} @{__PACKAGE__->BannerDTAG} 10 1395 1405
19  
20 # Message-Id: <E1P1YNN-0003AD-Ga@example.org>
21 # X-Failed-Recipients: kijitora@example.ed.jp
22 1395 ▶ my $messageidv = $mhead->{"message-id"} || "";
Condition100%2/2
$mhead->{'message-id'} || ''
l!l
1290105
MC/DC100%1/1
$mhead->{'message-id'} || ''
$mhead->{'message-id'}
Truth table100%2/2
A
A= $mhead->{'message-id'}
Aresult
11
00
23 1395 my $emailtitle = [
24 "Delivery Status Notification",
25 "Mail delivery failed",
26 "Mail failure",
27 "Message frozen",
28 "Warning: message ",
29 "error(s) in forwarding or filtering",
30 ];
31 1395 ▶ my $proceedsto = 0; $proceedsto++ if index($mhead->{"from"}, "Mail Delivery System") > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($mhead->{"from"}, "Mail Delivery System") != -1 326 1069 1395
32  
33 1395 ▶ while( $messageidv ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($messageidv ne "") 1290 105 1395
34 # Message-Id: <E1P1YNN-0003AD-Ga@example.org>
35 1290 ▶ last if index($messageidv, '<') != 0 || index($messageidv, '-') != 8 || index($messageidv, '@') != 18;
Branch: 1 branch
BranchTrueFalseTotal
if index($messageidv, "<") != 0 or index($messageidv, "-") != 8 or index($messageidv, "\@") != 18 1067 223 1290
Condition83%5/6
index($messageidv, "<") != 0 or index($messageidv, "-") != 8 or index($messageidv, "\@") != 18
l!l&&r!l&&!r
10670223
index($messageidv, "<") != 0 or index($messageidv, "-") != 8
l!l&&r!l&&!r
411026223
MC/DC66%2/3
index($messageidv, "<") != 0 or index($messageidv, "-") != 8 or index($messageidv, "\@") != 18
index($messageidv, "<") != 0 index($messageidv, "-") != 8 index($messageidv, "\@") != 18
Truth table75%3/4
A or B or C
A= index($messageidv, "<") != 0B= index($messageidv, "-") != 8C= index($messageidv, "\@") != 18
ABCresult
1XX1
01X1
0011
0000
36 223 $proceedsto++; last;
37 }
38 1395 for my $e ( @$emailtitle ) {
39 # Subject: Mail delivery failed: returning message to sender
40 # Subject: Mail delivery failed
41 # Subject: Message frozen
42 4528 ▶ next if index($mhead->{"subject"}, $e) < 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($mhead->{"subject"}, $e) == -1 3649 879 4528
43 879 $proceedsto++; last;
44 }
45  
46 # Exim clones of the third Parties
47 # 1. McAfee Saas (Formerly MXLogic)
48 1395 ▶ my $thirdparty = 0; $thirdparty ||= 1 if exists $mhead->{"x-mx-bounce"};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mhead->{"x-mx-bounce"} 11 1384 1395
Condition50%1/2
$thirdparty ||= 1
l!l
011
MC/DC0%0/1
$thirdparty ||= 1
$thirdparty
Truth table50%1/2
A
A= $thirdparty
Aresult
11
00
49 1395 ▶ $thirdparty ||= 1 if exists $mhead->{"x-mxl-hash"};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mhead->{"x-mxl-hash"} 0 1395 1395
Condition0%0/2
$thirdparty ||= 1
l!l
00
MC/DC0%0/1
$thirdparty ||= 1
$thirdparty
Truth table0%0/2
A
A= $thirdparty
Aresult
11
00
50 1395 ▶ $thirdparty ||= 1 if exists $mhead->{"x-mxl-notehash"};
Branch: 1 branch
BranchTrueFalseTotal
if exists $mhead->{"x-mxl-notehash"} 11 1384 1395
Condition50%1/2
$thirdparty ||= 1
l!l
110
MC/DC0%0/1
$thirdparty ||= 1
$thirdparty
Truth table50%1/2
A
A= $thirdparty
Aresult
11
00
51 1395 ▶ $thirdparty ||= 1 if index($messageidv, "<mxl~") > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($messageidv, "<mxl~") != -1 16 1379 1395
Condition100%2/2
$thirdparty ||= 1
l!l
115
MC/DC100%1/1
$thirdparty ||= 1
$thirdparty
Truth table100%2/2
A
A= $thirdparty
Aresult
11
00
52 1395 ▶ return undef if $proceedsto < 2 && $thirdparty == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $proceedsto < 2 and $thirdparty == 0 1094 301 1395
Condition66%2/3
$proceedsto < 2 and $thirdparty == 0
!ll&&!rl&&r
30101094
MC/DC50%1/2
$proceedsto < 2 and $thirdparty == 0
$proceedsto < 2 $thirdparty == 0
Truth table66%2/3
A and B
A= $proceedsto < 2B= $thirdparty == 0
ABresult
0X0
100
111
53  
54 301 require Sisimai::Eb;
55 301 require Sisimai::Reason;
56 301 require Sisimai::Address;
57 301 require Sisimai::SMTP::Command;
58 301 require Sisimai::SMTP::Failure;
59 301 state $indicators = __PACKAGE__->INDICATORS;
60 301 state $boundaries = [
61 # deliver.c:6423| if (bounce_return_body) fprintf(f,
62 # deliver.c:6424|"------ This is a copy of the message, including all the headers. ------\n");
63 # deliver.c:6425| else fprintf(f,
64 # deliver.c:6426|"------ This is a copy of the message's headers. ------\n");
65 '------ This is a copy of the message, including all the headers. ------',
66 'Content-Type: message/rfc822',
67 "Included is a copy of the message header:\n-----------------------------------------", # MXLogic
68 ];
69 301 state $startingof = {
70 # Error text strings which defined in exim/src/deliver.c
71 #
72 # deliver.c:6292| fprintf(f,
73 # deliver.c:6293|"This message was created automatically by mail delivery software.\n");
74 # deliver.c:6294| if (to_sender)
75 # deliver.c:6295| {
76 # deliver.c:6296| fprintf(f,
77 # deliver.c:6297|"\nA message that you sent could not be delivered to one or more of its\n"
78 # deliver.c:6298|"recipients. This is a permanent error. The following address(es) failed:\n");
79 # deliver.c:6299| }
80 # deliver.c:6300| else
81 # deliver.c:6301| {
82 # deliver.c:6302| fprintf(f,
83 # deliver.c:6303|"\nA message sent by\n\n <%s>\n\n"
84 # deliver.c:6304|"could not be delivered to one or more of its recipients. The following\n"
85 # deliver.c:6305|"address(es) failed:\n", sender_address);
86 # deliver.c:6306| }
87 "alias" => [" an undisclosed address"],
88 "command" => ["SMTP error from remote ", "LMTP error after "],
89 'deliverystatus' => ["Content-Type: message/delivery-status"],
90 'frozen' => [" has been frozen", " was frozen on arrival"],
91 'message' => [
92 "This message was created automatically by mail delivery software.",
93 "A message that you sent was rejected by the local scannning code",
94 "A message that you sent contained one or more recipient addresses ",
95 "A message that you sent could not be delivered to all of its recipients",
96 " has been frozen",
97 " was frozen on arrival",
98 " router encountered the following error(s):",
99 ],
100 };
101 301 state $messagesof = {
102 # find exim/ -type f -exec grep 'message = US' {} /dev/null \;
103 # route.c:1158| DEBUG(D_uid) debug_printf("getpwnam() returned NULL (user not found)\n");
104 $Sisimai::Eb::ReUSER => ["user not found"],
105 # parser.c:666| *errorptr = string_sprintf("%s (expected word or \"<\")", *errorptr);
106 # parser.c:701| if(bracket_count++ > 5) FAILED(US"angle-brackets nested too deep");
107 # parser.c:738| FAILED(US"domain missing in source-routed address");
108 # parser.c:747| : string_sprintf("malformed address: %.32s may not follow %.*s",
109 $Sisimai::Eb::ReCOMM => [
110 "angle-brackets nested too deep",
111 'expected word or "<"',
112 "domain missing in source-routed address",
113 "malformed address:",
114 ],
115 };
116 301 state $delayedfor = [
117 # deliver.c:7475| "No action is required on your part. Delivery attempts will continue for\n"
118 # smtp.c:3508| US"retry time not reached for any host after a long failure period" :
119 # deliver.c:7459| print_address_error(addr, f, US"Delay reason: ");
120 "No action is required on your part",
121 "retry time not reached for any host after a long failure period",
122 "Delay reason: ",
123 ];
124  
125 301 ▶ if( index($$mbody, "\n----- This is a copy ") > -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($$mbody, "\n----- This is a copy ") != -1) 5 296 301
126 # There are extremely rare cases where there are only five hyphens.
127 # https://github.com/sisimai/set-of-emails/blob/master/maildir/bsd/lhost-exim-05.eml
128 # ----- This is a copy of the message, including all the headers. ------
129 5 my $p0 = index($$mbody, "\n----- This is a copy ");
130 5 substr($$mbody, $p0 + 1, 1, "--");
131 }
132  
133 301 ▶ my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries) // return undef; return undef unless $emailparts->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $emailparts->[0] 0 301 301
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
3010
MC/DC0%0/1
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
"Sisimai::RFC5322"->part($mbody, $boundaries)
Truth table50%1/2
A
A= "Sisimai::RFC5322"->part($mbody, $boundaries)
Aresult
11
00
134 301 my $fieldtable = Sisimai::RFC1894->FIELDTABLE;
135 301 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef;
136 301 my $readcursor = 0; # Points the current cursor position
137 301 my $nextcursor = 0;
138 301 my $recipients = 0; # The number of 'Final-Recipient' header
139 301 my $boundary00 = ''; # Boundary string
140  
141 # Get the boundary string and set regular expression for matching with the boundary string.
142 301 ▶ $boundary00 = Sisimai::RFC2045->boundary($mhead->{'content-type'}) if $mhead->{'content-type'};
Branch: 1 branch
BranchTrueFalseTotal
if $mhead->{"content-type"} 119 182 301
143  
144 301 my $p1 = -1; my $p2 = -1;
145 301 for my $e ( split("\n", $emailparts->[0]) ) {
146 # Read error messages and delivery status lines from the head of the email to the previous
147 # line of the beginning of the original message.
148 4434 ▶ unless( $readcursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readcursor) 1039 3395 4434
149 # Beginning of the bounce message or message/delivery-status part
150 1039 ▶ if( grep { index($e, $_) > -1 } $startingof->{'message'}->@* ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {index($e, $_) != -1;} @{$$startingof{"message"}}) 296 743 1039
151 # Check the message defined in $startingof->{"message"}, {"frozen"}
152 296 $readcursor |= $indicators->{'deliverystatus'};
153 296 ▶ next unless grep { index($e, $_) > -1 } $startingof->{'frozen'}->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {index($e, $_) != -1;} @{$$startingof{"frozen"}} 296 0 296
154 }
155 }
156 4138 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq "" 1554 2584 4138
Condition100%3/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
l!l&&r!l&&!r
7438112584
MC/DC100%2/2
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
($readcursor & $indicators->{"deliverystatus"}) == 0 $e eq ""
Truth table100%3/3
A or B
A= ($readcursor & $indicators->{"deliverystatus"}) == 0B= $e eq ""
ABresult
1X1
011
000
157  
158 # This message was created automatically by mail delivery software.
159 #
160 # A message that you sent could not be delivered to one or more of its
161 # recipients. This is a permanent error. The following address(es) failed:
162 #
163 # kijitora@example.jp
164 # SMTP error from remote mail server after RCPT TO:<kijitora@example.jp>:
165 # host neko.example.jp [192.0.2.222]: 550 5.1.1 <kijitora@example.jp>... User Unknown
166 2584 $v = $dscontents->[-1];
167  
168 2584 my $cv = "";
169 2584 my $ce = 0;
170 2584 while(1) {
171 # Check if the line matche the following patterns:
172 2584 ▶ last if index($e, ' ') != 0; # The line should start with " " (2 spaces)
Branch: 1 branch
BranchTrueFalseTotal
if index($e, " ") != 0 1547 1037 2584
173 1037 ▶ last if index($e, '@' ) < 2; # "@" should be included (email)
Branch: 1 branch
BranchTrueFalseTotal
if index($e, "\@") < 2 483 554 1037
174 554 ▶ last if index($e, '.' ) < 2; # "." should be included (domain part)
Branch: 1 branch
BranchTrueFalseTotal
if index($e, ".") < 2 0 554 554
175 554 ▶ last if index($e, 'pipe to |') > -1; # Exclude "pipe to /path/to/prog" line
Branch: 1 branch
BranchTrueFalseTotal
if index($e, "pipe to |") != -1 10 544 554
176  
177 544 my $cx = substr($e, 2, 1);
178 544 ▶ last if $cx eq " "; # The 3rd character is " "
Branch: 1 branch
BranchTrueFalseTotal
if $cx eq " " 270 274 544
179 274 ▶ last if $thirdparty == 0 && $cx eq "<"; # MXLogic returns " <neko@example.jp>:..."
Branch: 1 branch
BranchTrueFalseTotal
if $thirdparty == 0 and $cx eq "<" 10 264 274
Condition100%3/3
$thirdparty == 0 and $cx eq "<"
!ll&&!rl&&r
1624810
MC/DC100%2/2
$thirdparty == 0 and $cx eq "<"
$thirdparty == 0 $cx eq "<"
Truth table100%3/3
A and B
A= $thirdparty == 0B= $cx eq "<"
ABresult
0X0
100
111
180  
181 264 $ce = 1; last;
182 }
183  
184 2584 ▶ if( $ce == 1 || grep { index($e, $_) > 0 } $startingof->{"alias"}->@* ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ce == 1 or grep {index($e, $_) > 0;} @{$$startingof{'alias'}}) { } 264 2320 2584
elsif (index($e, ' (generated from ') > 0 or index($e, ' generated by ') > 0) { } 36 2284 2320
Condition66%2/3
$ce == 1 or grep {index($e, $_) > 0;} @{$$startingof{"alias"}}
l!l&&r!l&&!r
26402320
MC/DC50%1/2
$ce == 1 or grep {index($e, $_) > 0;} @{$$startingof{"alias"}}
$ce == 1 grep {index($e, $_) > 0;} @{$$startingof{"alias"}}
Truth table66%2/3
A or B
A= $ce == 1B= grep {index($e, $_) > 0;} @{$$startingof{"alias"}}
ABresult
1X1
011
000
185 # The line is including an email address
186 264 ▶ if( $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 10 254 264
187 # There are multiple recipient addresses in the message body.
188 10 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
189 10 $v = $dscontents->[-1];
190 }
191  
192 264 ▶ if( grep { index($e, $_) > 0 } $startingof->{"alias"}->@* ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {index($e, $_) > 0;} @{$$startingof{'alias'}}) { } 0 264 264
193 # The line does not include an email address
194 # deliver.c:4549| printed = US"an undisclosed address";
195 # an undisclosed address
196 # (generated from kijitora@example.jp)
197 0 $cv = substr($e, 2,);
198  
199 } else {
200 # kijitora@example.jp
201 # sabineko@example.jp: forced freeze
202 # mikeneko@example.jp <nekochan@example.org>: ...
203 264 $p1 = index($e, "<");
204 264 $p2 = index($e, ">:");
205  
206 264 ▶ if( $p1 > 1 && $p2 > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p1 > 1 and $p2 > 1) { } 21 243 264
Condition66%2/3
$p1 > 1 and $p2 > 1
!ll&&!rl&&r
243021
MC/DC50%1/2
$p1 > 1 and $p2 > 1
$p1 > 1 $p2 > 1
Truth table66%2/3
A and B
A= $p1 > 1B= $p2 > 1
ABresult
0X0
100
111
207 # There are an email address and an error message in the line
208 # parser.c:743| while (bracket_count-- > 0) if (*s++ != '>')
209 # parser.c:744| {
210 # parser.c:745| *errorptr = s[-1] == 0
211 # parser.c:746| ? US"'>' missing at end of address"
212 # parser.c:747| : string_sprintf("malformed address: %.32s may not follow %.*s",
213 # parser.c:748| s-1, (int)(s - US mailbox - 1), mailbox);
214 # parser.c:749| goto PARSE_FAILED;
215 # parser.c:750| }
216 21 $cv = Sisimai::Address->s3s4(substr($e, $p1, $p2 - $p1 - 1));
217 21 $v->{'diagnosis'} = substr($e, $p2 + 1,);
218  
219 } else {
220 # There is an email address only in the line
221 # kijitora@example.jp
222 243 $cv = Sisimai::Address->s3s4(substr($e, 2,));
223 }
224 264 ▶ next unless Sisimai::Address->is_emailaddress($cv);
Branch: 1 branch
BranchTrueFalseTotal
unless "Sisimai::Address"->is_emailaddress($cv) 0 264 264
225 }
226 264 $v->{'recipient'} = $cv;
227 264 $recipients++;
228  
229 ▶ } elsif( index($e, " (generated from ") > 0 || index($e, " generated by ") > 0 ) {
Condition100%3/3
index($e, " (generated from ") > 0 or index($e, " generated by ") > 0
l!l&&r!l&&!r
6302284
MC/DC100%2/2
index($e, " (generated from ") > 0 or index($e, " generated by ") > 0
index($e, " (generated from ") > 0 index($e, " generated by ") > 0
Truth table100%3/3
A or B
A= index($e, " (generated from ") > 0B= index($e, " generated by ") > 0
ABresult
1X1
011
000
230 # (generated from kijitora@example.jp)
231 # pipe to |/bin/echo "Some pipe output"
232 # generated by userx@myhost.test.ex
233 36 for my $f ( split(" ", $e) ) {
234 # Find the alias address
235 118 ▶ next if index($f, '@') < 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($f, "\@") == -1 87 31 118
236 31 $v->{'alias'} = Sisimai::Address->s3s4($f);
237 }
238 } else {
239 2284 ▶ if( grep { index($e, $_) > -1 } $startingof->{'frozen'}->@* ) {
Branch: 2 branches
BranchTrueFalseTotal
if (grep {index($e, $_) != -1;} @{$$startingof{'frozen'}}) { } 0 2284 2284
elsif ($boundary00) { } 355 1929 2284
240 # Message *** has been frozen by the system filter.
241 # Message *** was frozen on arrival by ACL.
242 0 $v->{'alterrors'} .= $e.' ';
243  
244 } elsif( $boundary00 ) {
245 # --NNNNNNNNNN-eximdsn-MMMMMMMMMM
246 # Content-type: message/delivery-status
247 # ...
248 355 ▶ if( Sisimai::RFC1894->match($e) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('Sisimai::RFC1894'->match($e)) { } 160 195 355
249 # $e matched with any field defined in RFC3464
250 160 ▶ next unless my $o = Sisimai::RFC1894->field($e);
Branch: 1 branch
BranchTrueFalseTotal
unless my $o = "Sisimai::RFC1894"->field($e) 0 160 160
251  
252 160 ▶ if( $o->[3] eq 'addr' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($o->[3] eq 'addr') { } 30 130 160
elsif ($o->[3] eq 'code') { } 20 110 130
253 # Final-Recipient: rfc822;|/bin/echo "Some pipe output"
254 30 ▶ next unless $o->[0] eq 'final-recipient';
Branch: 1 branch
BranchTrueFalseTotal
unless $o->[0] eq "final-recipient" 0 30 30
255 30 ▶ $v->{'spec'} ||= rindex($o->[2], '@') > -1 ? 'SMTP' : 'X-UNIX';
Branch: 1 branch
BranchTrueFalseTotal
rindex($o->[2], '@') != -1 ? : 25 5 30
Condition33%1/3
$v->{"spec"} ||= rindex($o->[2], "\@") != -1 ? "SMTP" : "X-UNIX"
l!l&&r!l&&!r
0300
MC/DC0%0/2
$v->{"spec"} ||= rindex($o->[2], "\@") != -1 ? "SMTP" : "X-UNIX"
$v->{"spec"} rindex($o->[2], "\@") != -1 ? "SMTP" : "X-UNIX"
Truth table33%1/3
A ||= B
A= $v->{"spec"}B= rindex($o->[2], "\@") != -1 ? "SMTP" : "X-UNIX"
ABresult
1X1
011
000
256  
257 } elsif( $o->[3] eq 'code' ) {
258 # Diagnostic-Code: SMTP; 550 5.1.1 <userunknown@example.jp>... User Unknown
259 20 $v->{'spec'} = uc $o->[1];
260 20 $v->{'diagnosis'} = $o->[2];
261  
262 } else {
263 # Other DSN fields defined in RFC3464
264 110 ▶ next unless exists $fieldtable->{ $o->[0] };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$fieldtable{$o->[0]} 0 110 110
265 110 $v->{ $fieldtable->{ $o->[0] } } = $o->[2];
266 }
267 } else {
268 # Error message ?
269 195 ▶ next if $nextcursor;
Branch: 1 branch
BranchTrueFalseTotal
if $nextcursor 5 190 195
270  
271 # Content-type: message/delivery-status
272 190 ▶ $nextcursor = 1 if index($e, $startingof->{'deliverystatus'}->[0]) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, $startingof->{"deliverystatus"}[0]) == 0 30 160 190
273 190 ▶ $v->{'alterrors'} .= $e.' ' if index($e, ' ') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, " ") == 0 80 110 190
274 }
275 } else {
276 # There is no boundary string in $boundary00
277 1929 ▶ if( scalar @$dscontents == $recipients ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$dscontents == $recipients) { } 711 1218 1929
278 # Error message
279 711 $v->{'diagnosis'} .= $e.' ';
280  
281 } else {
282 # Error message when email address above does not include '@' and domain part.
283 # pipe to |/path/to/prog ...
284 # generated by kijitora@example.com
285 1218 ▶ next unless index($e, " ") == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless index($e, " ") == 0 1172 46 1218
286 46 $v->{"diagnosis"} .= $e." ";
287 }
288 }
289 }
290 }
291  
292 301 ▶ if( $recipients ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recipients) { } 254 47 301
293 # Check "an undisclosed address", "unroutable address"
294 254 for my $q ( @$dscontents ) {
295 # Replace the recipient address with the value of "alias"
296 264 ▶ next unless $q->{'alias'};
Branch: 1 branch
BranchTrueFalseTotal
unless $q->{"alias"} 258 6 264
297 6 ▶ if( ! $q->{'recipient'} || rindex($q->{'recipient'}, '@') == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $q->{"recipient"} or rindex($q->{"recipient"}, "\@") == -1) 0 6 6
Condition33%1/3
not $q->{"recipient"} or rindex($q->{"recipient"}, "\@") == -1
l!l&&r!l&&!r
006
MC/DC0%0/2
not $q->{"recipient"} or rindex($q->{"recipient"}, "\@") == -1
not $q->{"recipient"} rindex($q->{"recipient"}, "\@") == -1
Truth table33%1/3
not(A) or B
A= not $q->{"recipient"}B= rindex($q->{"recipient"}, "\@") == -1
ABresult
1X1
011
000
298 # The value of "recipient" is empty or does not include "@"
299 0 $q->{'recipient'} = $q->{'alias'};
300 }
301 }
302 } else {
303 # Fallback for getting recipient addresses
304 47 ▶ if( defined $mhead->{'x-failed-recipients'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mhead->{"x-failed-recipients"}) 25 22 47
305 # X-Failed-Recipients: kijitora@example.jp
306 25 my @rcptinhead = split(',', $mhead->{'x-failed-recipients'});
307 25 for my $e ( @rcptinhead ) { s/\A[ ]+//, s/[ ]+\z// for $e }
308 25 $recipients = scalar @rcptinhead;
309  
310 25 for my $e ( @rcptinhead ) {
311 # Insert each recipient address into @$dscontents
312 25 $dscontents->[-1]->{'recipient'} = $e;
313 25 ▶ next if scalar @$dscontents == $recipients;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$dscontents == $recipients 25 0 25
314 0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
315 }
316 }
317 }
318 301 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 22 279 301
319  
320 # Get the name of the local MTA
321 # Received: from marutamachi.example.org (c192128.example.net [192.0.2.128])
322 279 ▶ my $receivedby = $mhead->{'received'} || [];
Condition50%1/2
$mhead->{'received'} || []
l!l
2790
MC/DC0%0/1
$mhead->{'received'} || []
$mhead->{'received'}
Truth table50%1/2
A
A= $mhead->{'received'}
Aresult
11
00
323 279 my $recvdtoken = Sisimai::RFC5322->received($receivedby->[-1]);
324  
325 279 for my $e ( @$dscontents ) {
326 # Check the error message, the rhost, the lhost, and the smtp command.
327 289 ▶ $e->{"alterrors"} ||= "";
Condition100%2/2
$e->{"alterrors"} ||= ""
l!l
30259
MC/DC100%1/1
$e->{"alterrors"} ||= ""
$e->{"alterrors"}
Truth table100%2/2
A
A= $e->{"alterrors"}
Aresult
11
00
328 289 ▶ if( ! $e->{'diagnosis'} && length($boundary00) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $e->{"diagnosis"} and length $boundary00 > 0) 10 279 289
Condition66%2/3
not $e->{"diagnosis"} and length $boundary00 > 0
!ll&&!rl&&r
279010
MC/DC50%1/2
not $e->{"diagnosis"} and length $boundary00 > 0
not $e->{"diagnosis"} length $boundary00 > 0
Truth table66%2/3
not(A) and B
A= not $e->{"diagnosis"}B= length $boundary00 > 0
ABresult
0X0
100
111
329 # Empty Diagnostic-Code: or error message
330 # --NNNNNNNNNN-eximdsn-MMMMMMMMMM
331 # Content-type: message/delivery-status
332 #
333 # Reporting-MTA: dns; the.local.host.name
334 #
335 # Action: failed
336 # Final-Recipient: rfc822;/a/b/c
337 # Status: 5.0.0
338 #
339 # Action: failed
340 # Final-Recipient: rfc822;|/p/q/r
341 # Status: 5.0.0
342 10 ▶ $e->{'diagnosis'} = $dscontents->[0]->{'diagnosis'} || '';
Condition50%1/2
$dscontents->[0]{'diagnosis'} || ''
l!l
010
MC/DC0%0/1
$dscontents->[0]{'diagnosis'} || ''
$dscontents->[0]{'diagnosis'}
Truth table50%1/2
A
A= $dscontents->[0]{'diagnosis'}
Aresult
11
00
343 10 ▶ $e->{'spec'} ||= $dscontents->[0]->{'spec'};
Condition33%1/3
$e->{"spec"} ||= $dscontents->[0]{"spec"}
l!l&&r!l&&!r
1000
MC/DC0%0/2
$e->{"spec"} ||= $dscontents->[0]{"spec"}
$e->{"spec"} $dscontents->[0]{"spec"}
Truth table33%1/3
A ||= B
A= $e->{"spec"}B= $dscontents->[0]{"spec"}
ABresult
1X1
011
000
344 10 ▶ $e->{'alterrors'} = $dscontents->[0]->{'alterrors'} if $dscontents->[0]->{'alterrors'};
Branch: 1 branch
BranchTrueFalseTotal
if $dscontents->[0]{"alterrors"} 10 0 10
345 }
346  
347 289 ▶ if( $e->{'alterrors'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"alterrors"}) 30 259 289
348 # Copy alternative error message
349 30 ▶ $e->{'diagnosis'} ||= $e->{'alterrors'};
Condition66%2/3
$e->{"diagnosis"} ||= $e->{"alterrors"}
l!l&&r!l&&!r
20100
MC/DC0%0/2
$e->{"diagnosis"} ||= $e->{"alterrors"}
$e->{"diagnosis"} $e->{"alterrors"}
Truth table66%2/3
A ||= B
A= $e->{"diagnosis"}B= $e->{"alterrors"}
ABresult
1X1
011
000
350  
351 30 ▶ if( index($e->{'diagnosis'}, '-') == 0 || substr($e->{'diagnosis'}, -2, 2) eq '__' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (index($e->{'diagnosis'}, '-') == 0 or substr($e->{'diagnosis'}, -2, 2) eq '__') { } 0 30 30
elsif (length $e->{'diagnosis'} < length $e->{'alterrors'}) { } 20 10 30
Condition33%1/3
index($e->{"diagnosis"}, "-") == 0 or substr($e->{"diagnosis"}, -2, 2) eq "__"
l!l&&r!l&&!r
0030
MC/DC0%0/2
index($e->{"diagnosis"}, "-") == 0 or substr($e->{"diagnosis"}, -2, 2) eq "__"
index($e->{"diagnosis"}, "-") == 0 substr($e->{"diagnosis"}, -2, 2) eq "__"
Truth table33%1/3
A or B
A= index($e->{"diagnosis"}, "-") == 0B= substr($e->{"diagnosis"}, -2, 2) eq "__"
ABresult
1X1
011
000
352 # Override the value of diagnostic code message
353 0 $e->{'diagnosis'} = $e->{'alterrors'};
354  
355 } elsif( length($e->{'diagnosis'}) < length($e->{'alterrors'}) ) {
356 # Override the value of diagnostic code message with the value of alterrors because
357 # the latter includes the former.
358 20 $e->{'alterrors'} =~ y/ //s;
359 20 ▶ $e->{'diagnosis'} = $e->{'alterrors'} if index(lc $e->{'alterrors'}, lc $e->{'diagnosis'}) > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index(lc $e->{"alterrors"}, lc $e->{"diagnosis"}) != -1 20 0 20
360 }
361 30 delete $e->{'alterrors'};
362 }
363 289 $p1 = index($e->{'diagnosis'}, '__');
364 289 ▶ $e->{'diagnosis'} = substr($e->{'diagnosis'}, 0, $p1) if $p1 > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $p1 > 1 0 289 289
365  
366 289 ▶ unless( $e->{'rhost'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($e->{"rhost"}) 269 20 289
367 # Get the remote host name
368 # host neko.example.jp [192.0.2.222]: 550 5.1.1 <kijitora@example.jp>... User Unknown
369 269 $p1 = index($e->{'diagnosis'}, 'host ');
370 269 $p2 = index($e->{'diagnosis'}, ' ', $p1 + 5);
371 269 ▶ $e->{'rhost'} = substr($e->{'diagnosis'}, $p1 + 5, $p2 - $p1 - 5) if $p1 > -1;
Branch: 1 branch
BranchTrueFalseTotal
if $p1 > -1 193 76 269
372 269 ▶ $e->{'rhost'} ||= $recvdtoken->[1];
Condition66%2/3
$e->{"rhost"} ||= $recvdtoken->[1]
l!l&&r!l&&!r
193760
MC/DC0%0/2
$e->{"rhost"} ||= $recvdtoken->[1]
$e->{"rhost"} $recvdtoken->[1]
Truth table66%2/3
A ||= B
A= $e->{"rhost"}B= $recvdtoken->[1]
ABresult
1X1
011
000
373 }
374 289 ▶ $e->{'lhost'} ||= $recvdtoken->[0];
Condition100%3/3
$e->{"lhost"} ||= $recvdtoken->[0]
l!l&&r!l&&!r
302536
MC/DC100%2/2
$e->{"lhost"} ||= $recvdtoken->[0]
$e->{"lhost"} $recvdtoken->[0]
Truth table100%3/3
A ||= B
A= $e->{"lhost"}B= $recvdtoken->[0]
ABresult
1X1
011
000
375  
376 289 ▶ unless( $e->{'command'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($e->{"command"}) 289 0 289
377 # Get the SMTP command name for the session
378 289 SMTP: for my $r ( $startingof->{"command"}->@* ) {
379 # Verify each regular expression of SMTP commands
380 395 ▶ next if index($e->{'diagnosis'}, $r) < 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e->{"diagnosis"}, $r) == -1 182 213 395
381 213 ▶ $e->{'command'} = Sisimai::SMTP::Command->find($e->{'diagnosis'}) || next;
Condition100%2/2
'Sisimai::SMTP::Command'->find($e->{'diagnosis'}) || (next)
l!l
18330
MC/DC100%1/1
'Sisimai::SMTP::Command'->find($e->{'diagnosis'}) || (next)
'Sisimai::SMTP::Command'->find($e->{'diagnosis'})
Truth table100%2/2
A
A= 'Sisimai::SMTP::Command'->find($e->{'diagnosis'})
Aresult
11
00
382 183 last;
383 }
384  
385 # Detect the reason of bounce
386 289 ▶ if( $e->{'command'} eq $Sisimai::Eb::CeHELO || $e->{'command'} eq $Sisimai::Eb::CeEHLO ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($e->{'command'} eq $Sisimai::Eb::CeHELO or $e->{'command'} eq $Sisimai::Eb::CeEHLO) { } 5 284 289
elsif ($e->{'command'} eq $Sisimai::Eb::CeMAIL) { } 76 208 284
Condition66%2/3
$e->{"command"} eq $Sisimai::Eb::CeHELO or $e->{"command"} eq $Sisimai::Eb::CeEHLO
l!l&&r!l&&!r
05284
MC/DC50%1/2
$e->{"command"} eq $Sisimai::Eb::CeHELO or $e->{"command"} eq $Sisimai::Eb::CeEHLO
$e->{"command"} eq $Sisimai::Eb::CeHELO $e->{"command"} eq $Sisimai::Eb::CeEHLO
Truth table66%2/3
A or B
A= $e->{"command"} eq $Sisimai::Eb::CeHELOB= $e->{"command"} eq $Sisimai::Eb::CeEHLO
ABresult
1X1
011
000
387 # HELO | Connected to 192.0.2.135 but my name was rejected.
388 5 $e->{'reason'} = $Sisimai::Eb::ReBLOC;
389  
390 } elsif( $e->{'command'} eq $Sisimai::Eb::CeMAIL ) {
391 # MAIL | Connected to 192.0.2.135 but sender was rejected.
392 76 $e->{'reason'} = $Sisimai::Eb::Re___1;
393  
394 } else {
395 # Try to match the error message with each message pattern
396 208 SESSION: for my $r ( keys %$messagesof ) {
397 # Check each message pattern
398 416 ▶ next unless grep { index($e->{'diagnosis'}, $_) > -1 } $messagesof->{ $r }->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {index($e->{"diagnosis"}, $_) != -1;} @{$$messagesof{$r}} 411 5 416
399 5 $e->{'reason'} = $r;
400 5 last;
401 }
402 208 ▶ $e->{'reason'} ||= $Sisimai::Eb::ReTIME if grep { index($e->{'diagnosis'}, $_) > -1 } @$delayedfor;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($e->{"diagnosis"}, $_) != -1;} @$delayedfor 0 208 208
Condition0%0/3
$e->{"reason"} ||= $Sisimai::Eb::ReTIME
l!l&&r!l&&!r
000
MC/DC0%0/2
$e->{"reason"} ||= $Sisimai::Eb::ReTIME
$e->{"reason"} $Sisimai::Eb::ReTIME
Truth table0%0/3
A ||= B
A= $e->{"reason"}B= $Sisimai::Eb::ReTIME
ABresult
1X1
011
000
403 }
404 }
405  
406 # Prefer the value of smtp reply code in Diagnostic-Code: field
407 # See set-of-emails/maildir/bsd/exim-20.eml
408 #
409 # Action: failed
410 # Final-Recipient: rfc822;userx@test.ex
411 # Status: 5.0.0
412 # Remote-MTA: dns; 127.0.0.1
413 # Diagnostic-Code: smtp; 450 TEMPERROR: retry timeout exceeded
414 #
415 # The value of "Status:" indicates permanent error but the value of SMTP reply code in
416 # Diagnostic-Code: field is "TEMPERROR"!!!!
417 289 ▶ my $cr = Sisimai::SMTP::Reply->find($e->{'diagnosis'}, $e->{'status'}) || '';
Condition100%2/2
'Sisimai::SMTP::Reply'->find($e->{'diagnosis'}, $e->{'status'}) || ''
l!l
22465
MC/DC100%1/1
'Sisimai::SMTP::Reply'->find($e->{'diagnosis'}, $e->{'status'}) || ''
'Sisimai::SMTP::Reply'->find($e->{'diagnosis'}, $e->{'status'})
Truth table100%2/2
A
A= 'Sisimai::SMTP::Reply'->find($e->{'diagnosis'}, $e->{'status'})
Aresult
11
00
418 289 ▶ my $cs = Sisimai::SMTP::Status->find($e->{'diagnosis'}, $cr) || '';
Condition100%2/2
'Sisimai::SMTP::Status'->find($e->{'diagnosis'}, $cr) || ''
l!l
139150
MC/DC100%1/1
'Sisimai::SMTP::Status'->find($e->{'diagnosis'}, $cr) || ''
'Sisimai::SMTP::Status'->find($e->{'diagnosis'}, $cr)
Truth table100%2/2
A
A= 'Sisimai::SMTP::Status'->find($e->{'diagnosis'}, $cr)
Aresult
11
00
419 289 ▶ my $re = $e->{'reason'} || '';
Condition100%2/2
$e->{'reason'} || ''
l!l
86203
MC/DC100%1/1
$e->{'reason'} || ''
$e->{'reason'}
Truth table100%2/2
A
A= $e->{'reason'}
Aresult
11
00
420 289 my $cv = "";
421  
422 289 ▶ if( Sisimai::SMTP::Failure->is_temporary($cr) || $re eq $Sisimai::Eb::ReTIME ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Sisimai::SMTP::Failure"->is_temporary($cr) or $re eq $Sisimai::Eb::ReTIME) 10 279 289
Condition66%2/3
"Sisimai::SMTP::Failure"->is_temporary($cr) or $re eq $Sisimai::Eb::ReTIME
l!l&&r!l&&!r
100279
MC/DC50%1/2
"Sisimai::SMTP::Failure"->is_temporary($cr) or $re eq $Sisimai::Eb::ReTIME
"Sisimai::SMTP::Failure"->is_temporary($cr) $re eq $Sisimai::Eb::ReTIME
Truth table66%2/3
A or B
A= "Sisimai::SMTP::Failure"->is_temporary($cr)B= $re eq $Sisimai::Eb::ReTIME
ABresult
1X1
011
000
423 # Set the pseudo status code as a temporary error
424 10 ▶ $cv = Sisimai::SMTP::Status->code($re, 1) if Sisimai::Reason->is_explicit($re);
Branch: 1 branch
BranchTrueFalseTotal
if "Sisimai::Reason"->is_explicit($re) 0 10 10
425 }
426 289 ▶ $e->{'replycode'} ||= $cr;
Condition66%2/3
$e->{"replycode"} ||= $cr
l!l&&r!l&&!r
022465
MC/DC50%1/2
$e->{"replycode"} ||= $cr
$e->{"replycode"} $cr
Truth table66%2/3
A ||= B
A= $e->{"replycode"}B= $cr
ABresult
1X1
011
000
427 289 ▶ $e->{'status'} ||= Sisimai::SMTP::Status->prefer($cv, $cs, $cr);
Condition100%3/3
$e->{"status"} ||= "Sisimai::SMTP::Status"->prefer($cv, $cs, $cr)
l!l&&r!l&&!r
30129130
MC/DC100%2/2
$e->{"status"} ||= "Sisimai::SMTP::Status"->prefer($cv, $cs, $cr)
$e->{"status"} "Sisimai::SMTP::Status"->prefer($cv, $cs, $cr)
Truth table100%3/3
A ||= B
A= $e->{"status"}B= "Sisimai::SMTP::Status"->prefer($cv, $cs, $cr)
ABresult
1X1
011
000
428 289 ▶ $e->{'command'} ||= '';
Condition100%2/2
$e->{"command"} ||= ""
l!l
183106
MC/DC100%1/1
$e->{"command"} ||= ""
$e->{"command"}
Truth table100%2/2
A
A= $e->{"command"}
Aresult
11
00
429 }
430 279 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
431 }
432  
433 52 1;
434 __END__
« Sisimai/Fact.pm ↑ Summary Sisimai/Lhost/Postfix.pm »