Sisimai/Lhost/Postfix.pm

filter: Statementstmt 97.9% 144 / 147 Branchbran 91.3% 95 / 104 Conditioncond 70.8% 51 / 72 MC/DCmcdc 46.5% 20 / 43 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 85.0% 318 / 374 CC 85 SCAR 44.8
CC
85
Cov
90%
inquire
93.7
BEGIN
1.0
BEGIN
1.0
CRAP 88.6
« Sisimai/Lhost/Exim.pm ↑ Summary Sisimai/RFC3464.pm »
1 package Sisimai::Lhost::Postfix;
2 48 ▶use parent 'Sisimai::Lhost';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 48 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 48 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 48 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶sub description { 'Postfix: https://www.postfix.org/' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
8 1463 ▶sub inquire {
Subroutine inquire: called CC=85 SCAR=45.4
Pod documented
9 # Decode bounce messages from Postfix
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 1463 my $class = shift;
16 1463 ▶ my $mhead = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
14621
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
17 1462 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
14611
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18 1461 my $match = 0;
19  
20 1461 ▶ if( index($mhead->{'subject'}, 'SMTP server: errors from ') > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($mhead->{'subject'}, 'SMTP server: errors from ') > 0) { } 5 1456 1461
21 # src/smtpd/smtpd_chat.c:|337: post_mail_fprintf(notice, "Subject: %s SMTP server: errors from %s",
22 # src/smtpd/smtpd_chat.c:|338: var_mail_name, state->namaddr);
23 5 $match = 2;
24  
25 } else {
26 # Subject: Undelivered Mail Returned to Sender
27 1456 ▶ $match = 1 if $mhead->{'subject'} eq 'Undelivered Mail Returned to Sender';
Branch: 1 branch
BranchTrueFalseTotal
if $mhead->{"subject"} eq "Undelivered Mail Returned to Sender" 633 823 1456
28 }
29 1461 ▶ return undef if $match == 0 || $mhead->{'x-aol-ip'};
Branch: 1 branch
BranchTrueFalseTotal
if $match == 0 or $mhead->{"x-aol-ip"} 835 626 1461
Condition100%3/3
$match == 0 or $mhead->{"x-aol-ip"}
l!l&&r!l&&!r
82312626
MC/DC100%2/2
$match == 0 or $mhead->{"x-aol-ip"}
$match == 0 $mhead->{"x-aol-ip"}
Truth table100%3/3
A or B
A= $match == 0B= $mhead->{"x-aol-ip"}
ABresult
1X1
011
000
30  
31 626 require Sisimai::Eb;
32 626 require Sisimai::RFC1123;
33 626 require Sisimai::SMTP::Reply;
34 626 require Sisimai::SMTP::Status;
35 626 require Sisimai::SMTP::Command;
36 626 state $indicators = __PACKAGE__->INDICATORS;
37 626 state $boundaries = ['Content-Type: message/rfc822', 'Content-Type: text/rfc822-headers'];
38 626 state $startingof = {
39 # Postfix manual - bounce(5) - http://www.postfix.org/bounce.5.html
40 'message' => [
41 ['The ', 'Postfix '], # The Postfix program, The Postfix on <os> program
42 ['The ', 'mail system'], # The mail system
43 ['The ', 'program'], # The <name> pogram
44 ['This is the', 'Postfix'], # This is the Postfix program
45 ['This is the', 'mail system'], # This is the mail system at host <hostname>
46 ],
47 };
48  
49 626 ▶ my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries) // return undef; return undef unless $emailparts->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $emailparts->[0] 0 626 626
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
6260
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
50 626 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef;
51 626 my $permessage = {}; # (Hash) Store values of each Per-Message field
52 626 my $recipients = 0; # (Integer) The number of 'Final-Recipient' header
53 626 my $anotherset = {}; # (Hash) Another error information
54 626 my $nomessages = 0; # (Integer) Delivery report unavailable
55 626 my @commandset; # (Array) ``in reply to * command'' list
56 626 my $p = '';
57  
58 626 ▶ if( $match == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match == 2) { } 5 621 626
59 # The message body starts with 'Transcript of session follows.'
60 5 require Sisimai::SMTP::Transcript;
61 5 ▶ my $transcript = Sisimai::SMTP::Transcript->rise($emailparts->[0], 'In:', 'Out:') || return undef;
Condition50%1/2
'Sisimai::SMTP::Transcript'->rise($emailparts->[0], 'In:', 'Out:') || (return undef)
l!l
50
MC/DC0%0/1
'Sisimai::SMTP::Transcript'->rise($emailparts->[0], 'In:', 'Out:') || (return undef)
'Sisimai::SMTP::Transcript'->rise($emailparts->[0], 'In:', 'Out:')
Truth table50%1/2
A
A= 'Sisimai::SMTP::Transcript'->rise($emailparts->[0], 'In:', 'Out:')
Aresult
11
00
62 5 ▶ return undef if scalar @$transcript == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$transcript == 0 0 5 5
63  
64 5 for my $e ( @$transcript ) {
65 # Pick email addresses, error messages, and the last SMTP command.
66 40 ▶ $v ||= $dscontents->[-1];
Condition66%2/3
$v ||= $dscontents->[-1]
l!l&&r!l&&!r
3550
MC/DC0%0/2
$v ||= $dscontents->[-1]
$v $dscontents->[-1]
Truth table66%2/3
A ||= B
A= $vB= $dscontents->[-1]
ABresult
1X1
011
000
67 40 $p = $e->{'response'};
68  
69 40 ▶ if( $e->{'command'} eq $Sisimai::Eb::CeEHLO || $e->{'command'} eq $Sisimai::Eb::CeHELO ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($e->{'command'} eq $Sisimai::Eb::CeEHLO or $e->{'command'} eq $Sisimai::Eb::CeHELO) { } 5 35 40
elsif ($e->{'command'} eq $Sisimai::Eb::CeMAIL) { } 5 30 35
elsif ($e->{'command'} eq $Sisimai::Eb::CeRCPT) { } 5 25 30
Condition66%2/3
$e->{"command"} eq $Sisimai::Eb::CeEHLO or $e->{"command"} eq $Sisimai::Eb::CeHELO
l!l&&r!l&&!r
5035
MC/DC50%1/2
$e->{"command"} eq $Sisimai::Eb::CeEHLO or $e->{"command"} eq $Sisimai::Eb::CeHELO
$e->{"command"} eq $Sisimai::Eb::CeEHLO $e->{"command"} eq $Sisimai::Eb::CeHELO
Truth table66%2/3
A or B
A= $e->{"command"} eq $Sisimai::Eb::CeEHLOB= $e->{"command"} eq $Sisimai::Eb::CeHELO
ABresult
1X1
011
000
70 # Use the argument of EHLO/HELO command as a value of "lhost"
71 5 $v->{'lhost'} = $e->{'argument'};
72  
73 } elsif( $e->{'command'} eq $Sisimai::Eb::CeMAIL ) {
74 # Set the argument of "MAIL" command to pseudo To: header of the original message
75 5 ▶ $emailparts->[1] .= sprintf("To: %s\n", $e->{'argument'}) unless length $emailparts->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless length $emailparts->[1] 5 0 5
76  
77 } elsif( $e->{'command'} eq $Sisimai::Eb::CeRCPT ) {
78 # RCPT TO: <...>
79 5 ▶ if( $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 0 5 5
80 # There are multiple recipient addresses in the transcript of session
81 0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
82 0 $v = $dscontents->[-1];
83 }
84 5 $v->{'recipient'} = $e->{'argument'};
85 5 $recipients++;
86 }
87 40 ▶ next if int($p->{'reply'}) < 400;
Branch: 1 branch
BranchTrueFalseTotal
if int $p->{"reply"} < 400 35 5 40
88  
89 5 push @commandset, $e->{'command'};
90 5 ▶ $v->{'diagnosis'} ||= join ' ', $p->{'text'}->@*;
Condition33%1/3
$v->{"diagnosis"} ||= join(" ", @{$p->{"text"}})
l!l&&r!l&&!r
050
MC/DC0%0/2
$v->{"diagnosis"} ||= join(" ", @{$p->{"text"}})
$v->{"diagnosis"} join(" ", @{$p->{"text"}})
Truth table33%1/3
A ||= B
A= $v->{"diagnosis"}B= join(" ", @{$p->{"text"}})
ABresult
1X1
011
000
91 5 ▶ $v->{'replycode'} ||= $p->{'reply'};
Condition33%1/3
$v->{"replycode"} ||= $p->{"reply"}
l!l&&r!l&&!r
050
MC/DC0%0/2
$v->{"replycode"} ||= $p->{"reply"}
$v->{"replycode"} $p->{"reply"}
Truth table33%1/3
A ||= B
A= $v->{"replycode"}B= $p->{"reply"}
ABresult
1X1
011
000
92 5 ▶ $v->{'status'} ||= $p->{'status'};
Condition33%1/3
$v->{"status"} ||= $p->{"status"}
l!l&&r!l&&!r
050
MC/DC0%0/2
$v->{"status"} ||= $p->{"status"}
$v->{"status"} $p->{"status"}
Truth table33%1/3
A ||= B
A= $v->{"status"}B= $p->{"status"}
ABresult
1X1
011
000
93 }
94 } else {
95 621 my $fieldtable = Sisimai::RFC1894->FIELDTABLE;
96 621 my $readcursor = 0; # (Integer) Points the current cursor position
97  
98 # The message body is a general bounce mail message of Postfix
99 621 for my $e ( split("\n", $emailparts->[0]) ) {
100 # Read error messages and delivery status lines from the head of the email to the previous
101 # line of the beginning of the original message.
102 19823 ▶ unless( $readcursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readcursor) 3220 16603 19823
103 # Beginning of the bounce message or message/delivery-status part
104 3220 ▶ $readcursor |= $indicators->{'deliverystatus'} if grep { Sisimai::String->aligned(\$e, $_) } $startingof->{'message'}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if grep {"Sisimai::String"->aligned(\$e, $_);} @{$$startingof{"message"}} 565 2655 3220
105 3220 next;
106 }
107 16603 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq "" 4083 12520 16603
Condition66%2/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
l!l&&r!l&&!r
0408312520
MC/DC50%1/2
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
($readcursor & $indicators->{"deliverystatus"}) == 0 $e eq ""
Truth table66%2/3
A or B
A= ($readcursor & $indicators->{"deliverystatus"}) == 0B= $e eq ""
ABresult
1X1
011
000
108  
109 12520 ▶ if( my $f = Sisimai::RFC1894->match($e) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = 'Sisimai::RFC1894'->match($e)) { } 4310 8210 12520
110 # $e matched with any field defined in RFC3464
111 4310 ▶ next unless my $o = Sisimai::RFC1894->field($e);
Branch: 1 branch
BranchTrueFalseTotal
unless my $o = "Sisimai::RFC1894"->field($e) 0 4310 4310
112 4310 $v = $dscontents->[-1];
113  
114 4310 ▶ if( $o->[3] eq 'addr' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($o->[3] eq 'addr') { } 1052 3258 4310
elsif ($o->[3] eq 'code') { } 560 2698 3258
115 # Final-Recipient: rfc822; kijitora@example.jp
116 # X-Actual-Recipient: rfc822; kijitora@example.co.jp
117 1052 ▶ if( Sisimai::Address->is_emailaddress($o->[2]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Sisimai::Address"->is_emailaddress($o->[2])) 1047 5 1052
118 # The email address is a valid email address, avoid an email address without a
119 # valid domain part such as "neko@mailhost".
120 1047 ▶ if( $o->[0] eq 'final-recipient' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->[0] eq 'final-recipient') { } 555 492 1047
121 # Final-Recipient: rfc822; kijitora@example.jp
122 555 ▶ if( $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 15 540 555
123 # There are multiple recipient addresses in the message body.
124 15 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
125 15 $v = $dscontents->[-1];
126 }
127 555 $v->{'recipient'} = $o->[2];
128 555 $recipients++;
129  
130 } else {
131 # X-Actual-Recipient: rfc822; kijitora@example.co.jp
132 492 $v->{'alias'} = $o->[2];
133 }
134 }
135 } elsif( $o->[3] eq 'code' ) {
136 # Diagnostic-Code: SMTP; 550 5.1.1 <userunknown@example.jp>... User Unknown
137 560 $v->{'spec'} = $o->[1];
138 560 ▶ $v->{'spec'} = 'SMTP' if uc $v->{'spec'} eq 'X-POSTFIX';
Branch: 1 branch
BranchTrueFalseTotal
if uc $v->{"spec"} eq "X-POSTFIX" 55 505 560
139 560 $v->{'diagnosis'} = $o->[2];
140  
141 } else {
142 # Other DSN fields defined in RFC3464
143 2698 ▶ next unless exists $fieldtable->{ $o->[0] };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$fieldtable{$o->[0]} 0 2698 2698
144 2698 ▶ next if $o->[3] eq "host" && Sisimai::RFC1123->is_internethost($o->[2]) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $o->[3] eq "host" and "Sisimai::RFC1123"->is_internethost($o->[2]) == 0 16 2682 2698
Condition100%3/3
$o->[3] eq "host" and "Sisimai::RFC1123"->is_internethost($o->[2]) == 0
!ll&&!rl&&r
1670101216
MC/DC100%2/2
$o->[3] eq "host" and "Sisimai::RFC1123"->is_internethost($o->[2]) == 0
$o->[3] eq "host" "Sisimai::RFC1123"->is_internethost($o->[2]) == 0
Truth table100%3/3
A and B
A= $o->[3] eq "host"B= "Sisimai::RFC1123"->is_internethost($o->[2]) == 0
ABresult
0X0
100
111
145 2682 $v->{ $fieldtable->{ $o->[0] } } = $o->[2];
146  
147 2682 ▶ next unless $f == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $f == 1 1593 1089 2682
148 1089 $permessage->{ $fieldtable->{ $o->[0] } } = $o->[2];
149 }
150 } else {
151 # If you do so, please include this problem report. You can
152 # delete your own text from the attached returned message.
153 #
154 # The mail system
155 #
156 # <userunknown@example.co.jp>: host mx.example.co.jp[192.0.2.153] said: 550
157 # 5.1.1 <userunknown@example.co.jp>... User Unknown (in reply to RCPT TO command)
158 8210 ▶ if( index($p, 'Diagnostic-Code:') == 0 && index($e, ' ') > -1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (index($p, 'Diagnostic-Code:') == 0 and index($e, ' ') != -1) { } 821 7389 8210
elsif ('Sisimai::String'->aligned(\$e, ['X-Postfix-Sender:', 'rfc822;', '@'])) { } 523 6866 7389
Condition66%2/3
index($p, "Diagnostic-Code:") == 0 and index($e, " ") != -1
!ll&&!rl&&r
73890821
MC/DC50%1/2
index($p, "Diagnostic-Code:") == 0 and index($e, " ") != -1
index($p, "Diagnostic-Code:") == 0 index($e, " ") != -1
Truth table66%2/3
A and B
A= index($p, "Diagnostic-Code:") == 0B= index($e, " ") != -1
ABresult
0X0
100
111
159 # Continued line of the value of Diagnostic-Code header
160 821 $v->{'diagnosis'} .= ' '.Sisimai::String->sweep($e);
161 821 $e = 'Diagnostic-Code: '.$e;
162  
163 } elsif( Sisimai::String->aligned(\$e, ['X-Postfix-Sender:', 'rfc822;', '@']) ) {
164 # X-Postfix-Sender: rfc822; shironeko@example.org
165 523 $emailparts->[1] .= sprintf("X-Postfix-Sender: %s\n", substr($e, index($e, ';') + 1,));
166  
167 } else {
168 # Alternative error message and recipient
169 6866 ▶ if( index($e, ' (in reply to ') > -1 || index($e, 'command)') > -1 ) {
Branch: 4 branches
BranchTrueFalseTotal
if (index($e, ' (in reply to ') != -1 or index($e, 'command)') != -1) { } 603 6263 6866
elsif ('Sisimai::String'->aligned(\$e, ['<', '@', '>', '(expanded from <', '):'])) { } 40 6223 6263
elsif (index($e, '<') == 0 and 'Sisimai::String'->aligned(\$e, ['<', '@', '>:'])) { } 514 5709 6223
elsif (index($e, '--- Delivery report unavailable ---') != -1) { } 5 5704 5709
Condition100%3/3
index($e, " (in reply to ") != -1 or index($e, "command)") != -1
l!l&&r!l&&!r
3802236263
MC/DC100%2/2
index($e, " (in reply to ") != -1 or index($e, "command)") != -1
index($e, " (in reply to ") != -1 index($e, "command)") != -1
Truth table100%3/3
A or B
A= index($e, " (in reply to ") != -1B= index($e, "command)") != -1
ABresult
1X1
011
000
170 # 5.1.1 <userunknown@example.co.jp>... User Unknown (in reply to RCPT TO
171 603 ▶ my $cv = Sisimai::SMTP::Command->find($e); push @commandset, $cv if $cv;
Branch: 1 branch
BranchTrueFalseTotal
if $cv 459 144 603
172 603 ▶ $anotherset->{'diagnosis'} .= ' '.$e if $anotherset->{'diagnosis'};
Branch: 1 branch
BranchTrueFalseTotal
if $anotherset->{"diagnosis"} 581 22 603
173  
174 } elsif( Sisimai::String->aligned(\$e, ['<', '@', '>', '(expanded from <', '):']) ) {
175 # <r@example.ne.jp> (expanded from <kijitora@example.org>): user ...
176 40 my $p1 = index($e, '> ');
177 40 my $p2 = index($e, '(expanded from ', $p1);
178 40 my $p3 = index($e, '>): ', $p2 + 14);
179 40 $anotherset->{'recipient'} = Sisimai::Address->s3s4(substr($e, 0, $p1));
180 40 $anotherset->{'alias'} = Sisimai::Address->s3s4(substr($e, $p2 + 15, $p3 - $p2 - 15));
181 40 $anotherset->{'diagnosis'} = substr($e, $p3 + 3,);
182  
183 ▶ } elsif( index($e, '<') == 0 && Sisimai::String->aligned(\$e, ['<', '@', '>:']) ) {
Condition100%3/3
index($e, "<") == 0 and "Sisimai::String"->aligned(\$e, ["<", "\@", ">:"])
!ll&&!rl&&r
569910514
MC/DC100%2/2
index($e, "<") == 0 and "Sisimai::String"->aligned(\$e, ["<", "\@", ">:"])
index($e, "<") == 0 "Sisimai::String"->aligned(\$e, ["<", "\@", ">:"])
Truth table100%3/3
A and B
A= index($e, "<") == 0B= "Sisimai::String"->aligned(\$e, ["<", "\@", ">:"])
ABresult
0X0
100
111
184 # <kijitora@exmaple.jp>: ...
185 514 $anotherset->{'recipient'} = Sisimai::Address->s3s4(substr($e, 0, index($e, '>')));
186 514 $anotherset->{'diagnosis'} = substr($e, index($e, '>:') + 2,);
187  
188 } elsif( index($e, '--- Delivery report unavailable ---') > -1 ) {
189 # postfix-3.1.4/src/bounce/bounce_notify_util.c
190 # bounce_notify_util.c:602|if (bounce_info->log_handle == 0
191 # bounce_notify_util.c:602||| bounce_log_rewind(bounce_info->log_handle)) {
192 # bounce_notify_util.c:602|if (IS_FAILURE_TEMPLATE(bounce_info->template)) {
193 # bounce_notify_util.c:602| post_mail_fputs(bounce, "");
194 # bounce_notify_util.c:602| post_mail_fputs(bounce, "\t--- delivery report unavailable ---");
195 # bounce_notify_util.c:602| count = 1; /* xxx don't abort */
196 # bounce_notify_util.c:602|}
197 # bounce_notify_util.c:602|} else {
198 5 $nomessages = 1;
199  
200 } else {
201 # Get an error message continued from the previous line
202 5704 ▶ next unless $anotherset->{'diagnosis'};
Branch: 1 branch
BranchTrueFalseTotal
unless $anotherset->{"diagnosis"} 3686 2018 5704
203 2018 ▶ $anotherset->{'diagnosis'} .= ' '.substr($e, 4,) if index($e, ' ') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, " ") == 0 876 1142 2018
204 }
205 }
206 } # End of message/delivery-status
207 } continue {
208 # Save the current line for the next loop
209 19823 $p = $e;
210 }
211 } # End of for()
212  
213 626 ▶ unless( $recipients ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($recipients) 81 545 626
214 # Fallback: get a recipient address from error messages
215 81 for my $e ( 'recipient', 'alias' ) {
216 # Set a valid recipient address picked from $anotherset
217 147 ▶ next unless Sisimai::Address->is_emailaddress($anotherset->{ $e });
Branch: 1 branch
BranchTrueFalseTotal
unless "Sisimai::Address"->is_emailaddress($anotherset->{$e}) 127 20 147
218 20 $dscontents->[-1]->{'recipient'} = $anotherset->{ $e };
219 20 $recipients++;
220 20 last;
221 }
222  
223 81 ▶ if( $recipients == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recipients == 0) 61 20 81
224 # Get a recipient address from message/rfc822 part if the delivery report was unavailable:
225 # '--- Delivery report unavailable ---'
226 61 my $p1 = index($emailparts->[1], "\nTo: ");
227 61 my $p2 = index($emailparts->[1], "\n", $p1 + 6);
228 61 ▶ if( $nomessages && $p1 > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nomessages and $p1 > 0) 5 56 61
Condition66%2/3
$nomessages and $p1 > 0
!ll&&!rl&&r
5605
MC/DC50%1/2
$nomessages and $p1 > 0
$nomessages $p1 > 0
Truth table66%2/3
A and B
A= $nomessagesB= $p1 > 0
ABresult
0X0
100
111
229 # Try to get a recipient address from To: field in the original
230 # message at message/rfc822 part
231 5 $dscontents->[-1]->{'recipient'} = Sisimai::Address->s3s4(substr($emailparts->[1], $p1 + 5, $p2 - $p1 - 5));
232 5 $recipients++;
233 }
234 }
235 }
236 626 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 56 570 626
237  
238 570 for my $e ( @$dscontents ) {
239 # Set default values if each value is empty.
240 585 ▶ $e->{ $_ } ||= $permessage->{ $_ } || '' for keys %$permessage;
Condition60%3/5
$e->{$_} ||= $permessage->{$_} || ""
l!l&&r!l&&!r
1089300
$permessage->{$_} || ''
l!l
300
MC/DC0%0/2
$e->{$_} ||= $permessage->{$_} || ""
$e->{$_} $permessage->{$_}
Truth table66%2/3
A ||= B
A= $e->{$_}B= $permessage->{$_}
ABresult
1X1
011
000
241  
242 585 ▶ if( $anotherset->{'diagnosis'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($anotherset->{"diagnosis"}) 554 31 585
243 # Copy alternative error message
244 554 $anotherset->{'diagnosis'} = Sisimai::String->sweep($anotherset->{'diagnosis'});
245 554 ▶ $e->{'diagnosis'} ||= $anotherset->{'diagnosis'};
Condition66%2/3
$e->{"diagnosis"} ||= $anotherset->{"diagnosis"}
l!l&&r!l&&!r
539150
MC/DC0%0/2
$e->{"diagnosis"} ||= $anotherset->{"diagnosis"}
$e->{"diagnosis"} $anotherset->{"diagnosis"}
Truth table66%2/3
A ||= B
A= $e->{"diagnosis"}B= $anotherset->{"diagnosis"}
ABresult
1X1
011
000
246  
247 554 ▶ if( $e->{'diagnosis'} =~ /\A\d+\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{'diagnosis'} =~ /\A\d+\z/u) { } 0 554 554
248 # Override the value of diagnostic code message
249 0 $e->{'diagnosis'} = $anotherset->{'diagnosis'};
250  
251 } else {
252 # More detailed error message is in "$anotherset"
253 554 my $as = ''; # status
254 554 my $ar = ''; # replycode
255  
256 554 ▶ if( Sisimai::SMTP::Status->is_ambiguous($e->{'status'}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Sisimai::SMTP::Status"->is_ambiguous($e->{"status"})) 192 362 554
257 # Check the value of D.S.N. in $anotherset is neither an empty nor *.0.0.
258 192 ▶ $as = Sisimai::SMTP::Status->find($anotherset->{'diagnosis'}) || '';
Condition100%2/2
'Sisimai::SMTP::Status'->find($anotherset->{'diagnosis'}) || ''
l!l
10182
MC/DC100%1/1
'Sisimai::SMTP::Status'->find($anotherset->{'diagnosis'}) || ''
'Sisimai::SMTP::Status'->find($anotherset->{'diagnosis'})
Truth table100%2/2
A
A= 'Sisimai::SMTP::Status'->find($anotherset->{'diagnosis'})
Aresult
11
00
259 192 ▶ $e->{'status'} = $as unless Sisimai::SMTP::Status->is_ambiguous($as);
Branch: 1 branch
BranchTrueFalseTotal
unless "Sisimai::SMTP::Status"->is_ambiguous($as) 10 182 192
260 }
261  
262 554 ▶ if( $e->{'replycode'} eq '' || substr($e->{'replycode'}, -2, 2) eq '00' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"replycode"} eq "" or substr($e->{"replycode"}, -2, 2) eq "00") 554 0 554
Condition33%1/3
$e->{"replycode"} eq "" or substr($e->{"replycode"}, -2, 2) eq "00"
l!l&&r!l&&!r
55400
MC/DC0%0/2
$e->{"replycode"} eq "" or substr($e->{"replycode"}, -2, 2) eq "00"
$e->{"replycode"} eq "" substr($e->{"replycode"}, -2, 2) eq "00"
Truth table33%1/3
A or B
A= $e->{"replycode"} eq ""B= substr($e->{"replycode"}, -2, 2) eq "00"
ABresult
1X1
011
000
263 # Check the value of SMTP reply code in $anotherset
264 554 ▶ $ar = Sisimai::SMTP::Reply->find($anotherset->{'diagnosis'}) || '';
Condition100%2/2
'Sisimai::SMTP::Reply'->find($anotherset->{'diagnosis'}) || ''
l!l
48173
MC/DC100%1/1
'Sisimai::SMTP::Reply'->find($anotherset->{'diagnosis'}) || ''
'Sisimai::SMTP::Reply'->find($anotherset->{'diagnosis'})
Truth table100%2/2
A
A= 'Sisimai::SMTP::Reply'->find($anotherset->{'diagnosis'})
Aresult
11
00
265 554 ▶ if( length($ar) > 0 && substr($ar, -2, 2) ne '00' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $ar > 0 and substr($ar, -2, 2) ne "00") 481 73 554
Condition66%2/3
length $ar > 0 and substr($ar, -2, 2) ne "00"
!ll&&!rl&&r
730481
MC/DC50%1/2
length $ar > 0 and substr($ar, -2, 2) ne "00"
length $ar > 0 substr($ar, -2, 2) ne "00"
Truth table66%2/3
A and B
A= length $ar > 0B= substr($ar, -2, 2) ne "00"
ABresult
0X0
100
111
266 # The SMTP reply code is neither an empty nor *00
267 481 $e->{'replycode'} = $ar;
268 }
269 }
270  
271 554 while(1) {
272 # Replace $e->{'diagnosis'} with the value of $anotherset->{'diagnosis'} when
273 # all the following conditions have not matched.
274 554 ▶ last if length($as.$ar) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if length $as . $ar == 0 73 481 554
275 481 ▶ last if length($anotherset->{'diagnosis'}) < length($e->{'diagnosis'});
Branch: 1 branch
BranchTrueFalseTotal
if length $anotherset->{"diagnosis"} < length $e->{"diagnosis"} 0 481 481
276 481 ▶ last if index($anotherset->{'diagnosis'}, $e->{'diagnosis'}) == -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($anotherset->{"diagnosis"}, $e->{"diagnosis"}) == -1 32 449 481
277  
278 449 $e->{'diagnosis'} = $anotherset->{'diagnosis'};
279 449 last;
280 }
281 }
282 }
283 585 $e->{'diagnosis'} = Sisimai::String->sweep($e->{'diagnosis'});
284 585 ▶ $e->{'command'} = shift @commandset || Sisimai::SMTP::Command->find($e->{'diagnosis'}) || '';
Condition100%5/5
shift @commandset || 'Sisimai::SMTP::Command'->find($e->{'diagnosis'}) || ''
l!l
469116
shift @commandset or "Sisimai::SMTP::Command"->find($e->{"diagnosis"})
l!l&&r!l&&!r
4645116
MC/DC100%2/2
shift @commandset || 'Sisimai::SMTP::Command'->find($e->{'diagnosis'}) || ''
shift @commandset "Sisimai::SMTP::Command"->find($e->{"diagnosis"})
Truth table100%3/3
A or B
A= shift @commandsetB= "Sisimai::SMTP::Command"->find($e->{"diagnosis"})
ABresult
1X1
011
000
285 585 ▶ $e->{'command'} ||= $Sisimai::Eb::CeHELO if index($e->{'diagnosis'}, 'refused to talk to me:') > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($e->{"diagnosis"}, "refused to talk to me:") != -1 39 546 585
Condition33%1/3
$e->{"command"} ||= $Sisimai::Eb::CeHELO
l!l&&r!l&&!r
0390
MC/DC0%0/2
$e->{"command"} ||= $Sisimai::Eb::CeHELO
$e->{"command"} $Sisimai::Eb::CeHELO
Truth table33%1/3
A ||= B
A= $e->{"command"}B= $Sisimai::Eb::CeHELO
ABresult
1X1
011
000
286 585 ▶ $e->{'spec'} ||= 'SMTP' if Sisimai::String->aligned(\$e->{'diagnosis'}, ['host ', ' said:']);
Branch: 1 branch
BranchTrueFalseTotal
if "Sisimai::String"->aligned(\$e->{"diagnosis"}, ["host ", " said:"]) 420 165 585
Condition100%2/2
$e->{"spec"} ||= "SMTP"
l!l
4155
MC/DC100%1/1
$e->{"spec"} ||= "SMTP"
$e->{"spec"}
Truth table100%2/2
A
A= $e->{"spec"}
Aresult
11
00
287 }
288 570 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
289 }
290  
291 48 1;
292 __END__
« Sisimai/Lhost/Exim.pm ↑ Summary Sisimai/RFC3464.pm »