Sisimai/Lhost/V5sendmail.pm

filter: Statementstmt 92.7% 89 / 96 Branchbran 76.0% 35 / 46 Conditioncond 75.0% 27 / 36 MC/DCmcdc 59.0% 13 / 22 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 82.6% 172 / 208 CC 40 SCAR 37.4
CC
40
Cov
85%
inquire
47.0
BEGIN
1.0
BEGIN
1.0
CRAP 41.9
« Sisimai/DateTime.pm ↑ Summary Sisimai/Lhost/KDDI.pm »
1 package Sisimai::Lhost::V5sendmail;
2 35 ▶use parent 'Sisimai::Lhost';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 35 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶sub description { 'Sendmail version 5' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
8 908 ▶sub inquire {
Subroutine inquire: called CC=40 SCAR=38.5
Pod documented
9 # Detect an error from V5sendmail
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.1.2
15 908 my $class = shift;
16 908 ▶ my $mhead = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
9071
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
17 907 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
9061
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18  
19 906 ▶ return undef unless $mhead->{'subject'};
Branch: 1 branch
BranchTrueFalseTotal
unless $mhead->{"subject"} 18 888 906
20 888 ▶ return undef if index($mhead->{'subject'}, 'Returned mail: ') != 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($mhead->{"subject"}, "Returned mail: ") != 0 807 81 888
21  
22 81 state $indicators = __PACKAGE__->INDICATORS;
23 81 state $boundaries = [' ----- Unsent message follows -----', ' ----- No message was collected -----'];
24 81 state $startingof = {
25 # Error text regular expressions which defined in src/savemail.c
26 # savemail.c:485| (void) fflush(stdout);
27 # savemail.c:486| p = queuename(e->e_parent, 'x');
28 # savemail.c:487| if ((xfile = fopen(p, "r")) == NULL)
29 # savemail.c:488| {
30 # savemail.c:489| syserr("Cannot open %s", p);
31 # savemail.c:490| fprintf(fp, " ----- Transcript of session is unavailable -----\n");
32 # savemail.c:491| }
33 # savemail.c:492| else
34 # savemail.c:493| {
35 # savemail.c:494| fprintf(fp, " ----- Transcript of session follows -----\n");
36 # savemail.c:495| if (e->e_xfp != NULL)
37 # savemail.c:496| (void) fflush(e->e_xfp);
38 # savemail.c:497| while (fgets(buf, sizeof buf, xfile) != NULL)
39 # savemail.c:498| putline(buf, fp, m);
40 # savemail.c:499| (void) fclose(xfile);
41 'error' => ['While talking to '],
42 'message' => ['----- Transcript of session follows -----'],
43 };
44  
45 81 my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries);
46 81 ▶ return undef if ref($emailparts) ne 'ARRAY' || length($emailparts->[1]) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if ref $emailparts ne "ARRAY" or length $emailparts->[1] == 0 45 36 81
Condition66%2/3
ref $emailparts ne "ARRAY" or length $emailparts->[1] == 0
l!l&&r!l&&!r
04536
MC/DC50%1/2
ref $emailparts ne "ARRAY" or length $emailparts->[1] == 0
ref $emailparts ne "ARRAY" length $emailparts->[1] == 0
Truth table66%2/3
A or B
A= ref $emailparts ne "ARRAY"B= length $emailparts->[1] == 0
ABresult
1X1
011
000
47  
48 36 require Sisimai::RFC1123;
49 36 require Sisimai::SMTP::Command;
50 36 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef;
51 36 my $readcursor = 0; # (Integer) Points the current cursor position
52 36 my $recipients = 0; # (Integer) The number of 'Final-Recipient' header
53 36 my $anotherone = {}; # (Ref->Hash) Another error information
54 36 my $remotehost = ""; # (String) The last remote hostname
55 36 my $curcommand = ""; # (String) The last SMTP command
56  
57 36 for my $e ( split("\n", $emailparts->[0]) ) {
58 # Read error messages and delivery status lines from the head of the email to the previous
59 # line of the beginning of the original message.
60 262 ▶ unless( $readcursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readcursor) 36 226 262
61 # Beginning of the bounce message or message/delivery-status part
62 36 ▶ $readcursor |= $indicators->{'deliverystatus'} if index($e, $startingof->{'message'}->[0]) > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, $startingof->{"message"}[0]) != -1 36 0 36
63 36 next;
64 }
65 226 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq "" 0 226 226
Condition33%1/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
l!l&&r!l&&!r
00226
MC/DC0%0/2
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
($readcursor & $indicators->{"deliverystatus"}) == 0 $e eq ""
Truth table33%1/3
A or B
A= ($readcursor & $indicators->{"deliverystatus"}) == 0B= $e eq ""
ABresult
1X1
011
000
66  
67 # ----- Transcript of session follows -----
68 # While talking to smtp.example.com:
69 # >>> RCPT To:<kijitora@example.org>
70 # <<< 550 <kijitora@example.org>, User Unknown
71 # 550 <kijitora@example.org>... User unknown
72 # 421 example.org (smtp)... Deferred: Connection timed out during user open with example.org
73 226 $v = $dscontents->[-1];
74 226 ▶ $curcommand = Sisimai::SMTP::Command->find(substr($e, 4,)) if index($e, ">>> ") == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, ">>> ") == 0 35 191 226
75  
76 226 ▶ if( Sisimai::String->aligned(\$e, [' <', '@', '>...']) || index(uc $e, ">>> RCPT TO:") > -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('Sisimai::String'->aligned(\$e, [' <', '@', '>...']) or index(uc $e, '>>> RCPT TO:') != -1) { } 85 141 226
Condition100%3/3
"Sisimai::String"->aligned(\$e, [" <", "\@", ">..."]) or index(uc $e, ">>> RCPT TO:") != -1
l!l&&r!l&&!r
7015141
MC/DC100%2/2
"Sisimai::String"->aligned(\$e, [" <", "\@", ">..."]) or index(uc $e, ">>> RCPT TO:") != -1
"Sisimai::String"->aligned(\$e, [" <", "\@", ">..."]) index(uc $e, ">>> RCPT TO:") != -1
Truth table100%3/3
A or B
A= "Sisimai::String"->aligned(\$e, [" <", "\@", ">..."])B= index(uc $e, ">>> RCPT TO:") != -1
ABresult
1X1
011
000
77 # 550 <kijitora@example.org>... User unknown
78 # >>> RCPT To:<kijitora@example.org>
79 85 my $p0 = index($e, " ");
80 85 my $p1 = index($e, "<", $p0);
81 85 my $p2 = index($e, ">", $p1);
82 85 my $cv = Sisimai::Address->s3s4(substr($e, $p1, $p2 - $p1 + 1));
83  
84 85 ▶ if( $remotehost eq "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($remotehost eq "") 15 70 85
85 # Keep error messages before "While talking to ..." line
86 15 $anotherone->{ $recipients } .= " ".$e;
87 15 next;
88 }
89  
90 70 ▶ if( $cv eq $v->{"recipient"} || ($curcommand eq "MAIL" && index($e, "<<< ") == 0) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cv eq $v->{'recipient'} or $curcommand eq 'MAIL' and index($e, '<<< ') == 0) { } 25 45 70
Condition100%6/6
$cv eq $v->{"recipient"} or $curcommand eq "MAIL" and index($e, "<<< ") == 0
l!l&&r!l&&!r
20545
$curcommand eq "MAIL" and index($e, "<<< ") == 0
!ll&&!rl&&r
4055
MC/DC100%3/3
$cv eq $v->{"recipient"} or $curcommand eq "MAIL" and index($e, "<<< ") == 0
$cv eq $v->{"recipient"} $curcommand eq "MAIL" index($e, "<<< ") == 0
Truth table100%4/4
A or B and C
A= $cv eq $v->{"recipient"}B= $curcommand eq "MAIL"C= index($e, "<<< ") == 0
ABCresult
1XX1
0111
00X0
0100
91 # The recipient address is the same address with the last appeared address
92 # like "550 <mikeneko@example.co.jp>... User unknown"
93 # Append this line to the string which is keeping error messages
94 25 $v->{"diagnosis"} .= " ".$e;
95 25 $v->{"replycode"} = Sisimai::SMTP::Reply->find($e);
96 25 $curcommand = "";
97  
98 } else {
99 # The recipient address in this line differs from the last appeared address
100 # or is the first recipient address in this bounce message
101 45 ▶ if( $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 25 20 45
102 # There are multiple recipient addresses in the message body.
103 25 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
104 25 $v = $dscontents->[-1];
105 }
106 45 $v->{"recipient"} = $cv;
107 45 $v->{"rhost"} = $remotehost;
108 45 $v->{"replycode"} = Sisimai::SMTP::Reply->find($e);
109 45 $v->{"diagnosis"} .= " ".$e;
110 45 ▶ $v->{"command"} ||= $curcommand;
Condition66%2/3
$v->{"command"} ||= $curcommand
l!l&&r!l&&!r
03510
MC/DC50%1/2
$v->{"command"} ||= $curcommand
$v->{"command"} $curcommand
Truth table66%2/3
A ||= B
A= $v->{"command"}B= $curcommand
ABresult
1X1
011
000
111 45 $recipients++
112 }
113 } else {
114 # This line does not include a recipient address
115 141 ▶ if( index($e, $startingof->{"error"}->[0]) > -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($e, $startingof->{'error'}[0]) != -1) { } 35 106 141
116 # ... while talking to mta.example.org.:
117 35 my $cv = Sisimai::RFC1123->find($e);
118 35 ▶ $remotehost = $cv if Sisimai::RFC1123->is_internethost($cv);
Branch: 1 branch
BranchTrueFalseTotal
if "Sisimai::RFC1123"->is_internethost($cv) 35 0 35
119  
120 } else {
121 # Append this line into the error message string
122 106 ▶ if( index($e, ">>> ") == 0 || index($e, "<<< ") == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($e, '>>> ') == 0 or index($e, '<<< ') == 0) { } 45 61 106
Condition100%3/3
index($e, ">>> ") == 0 or index($e, "<<< ") == 0
l!l&&r!l&&!r
202561
MC/DC100%2/2
index($e, ">>> ") == 0 or index($e, "<<< ") == 0
index($e, ">>> ") == 0 index($e, "<<< ") == 0
Truth table100%3/3
A or B
A= index($e, ">>> ") == 0B= index($e, "<<< ") == 0
ABresult
1X1
011
000
123 # >>> DATA
124 # <<< 550 Your E-Mail is redundant. You cannot send E-Mail to yourself (shironeko@example.jp).
125 # >>> QUIT
126 # <<< 421 dns.example.org Sorry, unable to contact destination SMTP daemon.
127 # <<< 550 Requested User Mailbox not found. No such user here.
128 45 $v->{"diagnosis"} .= " ".$e
129  
130 } else {
131 # 421 Other error message
132 61 $anotherone->{ $recipients } .= " ".$e;
133 }
134 }
135 }
136 }
137  
138 36 ▶ if( $recipients == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recipients == 0) 16 20 36
139 # There is no recipient address in the error message
140 16 for my $e ( keys %$anotherone ) {
141 # Try to pick an recipient address, a reply code, and error messages
142 16 ▶ my $cv = Sisimai::Address->s3s4($anotherone->{ $e }); next unless Sisimai::Address->is_emailaddress($cv);
Branch: 1 branch
BranchTrueFalseTotal
unless "Sisimai::Address"->is_emailaddress($cv) 6 10 16
143 10 ▶ my $cr = Sisimai::SMTP::Reply->find($anotherone->{ $e }) || "";
Condition50%1/2
'Sisimai::SMTP::Reply'->find($anotherone->{$e}) || ''
l!l
100
MC/DC0%0/1
'Sisimai::SMTP::Reply'->find($anotherone->{$e}) || ''
'Sisimai::SMTP::Reply'->find($anotherone->{$e})
Truth table50%1/2
A
A= 'Sisimai::SMTP::Reply'->find($anotherone->{$e})
Aresult
11
00
144  
145 10 $dscontents->[ $e ]->{"recipient"} = $cv;
146 10 $dscontents->[ $e ]->{"replycode"} = $cr;
147 10 $dscontents->[ $e ]->{"diagnosis"} = $anotherone->{ $e };
148 10 $recipients++;
149 }
150  
151 16 ▶ if( $recipients == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recipients == 0) 6 10 16
152 # Try to pick an recipient address from the original message
153 6 my $p1 = index($emailparts->[1], "\nTo: ");
154 6 my $p2 = index($emailparts->[1], "\n", $p1 + 6);
155  
156 6 ▶ if( $p1 > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p1 > 0) 6 0 6
157 # Get the recipient address from "To:" header at the original message
158 6 my $cv = Sisimai::Address->s3s4(substr($emailparts->[1], $p1, $p2 - $p1 - 5));
159 6 ▶ return undef unless Sisimai::Address->is_emailaddress($cv);
Branch: 1 branch
BranchTrueFalseTotal
unless "Sisimai::Address"->is_emailaddress($cv) 6 0 6
160 0 $dscontents->[0]->{'recipient'} = $cv;
161 0 $recipients++;
162 }
163 }
164 }
165 30 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 0 30 30
166  
167 30 my $j = 0; for my $e ( @$dscontents ) {
168 # Tidy up the error message in e.Diagnosis
169 55 ▶ $e->{"diagnosis"} ||= $anotherone->{ $j };
Condition33%1/3
$e->{"diagnosis"} ||= $anotherone->{$j}
l!l&&r!l&&!r
5500
MC/DC0%0/2
$e->{"diagnosis"} ||= $anotherone->{$j}
$e->{"diagnosis"} $anotherone->{$j}
Truth table33%1/3
A ||= B
A= $e->{"diagnosis"}B= $anotherone->{$j}
ABresult
1X1
011
000
170 55 ▶ $e->{"command"} ||= Sisimai::SMTP::Command->find($e->{"diagnosis"});
Condition100%3/3
$e->{"command"} ||= "Sisimai::SMTP::Command"->find($e->{"diagnosis"})
l!l&&r!l&&!r
35515
MC/DC100%2/2
$e->{"command"} ||= "Sisimai::SMTP::Command"->find($e->{"diagnosis"})
$e->{"command"} "Sisimai::SMTP::Command"->find($e->{"diagnosis"})
Truth table100%3/3
A ||= B
A= $e->{"command"}B= "Sisimai::SMTP::Command"->find($e->{"diagnosis"})
ABresult
1X1
011
000
171 55 ▶ $e->{'replycode'} = Sisimai::SMTP::Reply->find($e->{'diagnosis'}) || $anotherone->{'replycode'};
Condition33%1/3
'Sisimai::SMTP::Reply'->find($e->{'diagnosis'}) || $anotherone->{'replycode'}
l!l&&r!l&&!r
5500
MC/DC0%0/2
'Sisimai::SMTP::Reply'->find($e->{'diagnosis'}) || $anotherone->{'replycode'}
'Sisimai::SMTP::Reply'->find($e->{'diagnosis'}) $anotherone->{'replycode'}
Truth table33%1/3
A || B
A= 'Sisimai::SMTP::Reply'->find($e->{'diagnosis'})B= $anotherone->{'replycode'}
ABresult
1X1
011
000
172  
173 # @example.jp, no local part
174 # Get email address from the value of Diagnostic-Code header
175 55 ▶ next if index($e->{'recipient'}, '@') > 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e->{"recipient"}, "\@") > 0 55 0 55
176 0 ▶ my $p1 = index($e->{'diagnosis'}, '<'); next if $p1 == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $p1 == -1 0 0 0
177 0 ▶ my $p2 = index($e->{'diagnosis'}, '>'); next if $p2 == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $p2 == -1 0 0 0
178 0 $e->{'recipient'} = Sisimai::Address->s3s4(substr($e->{'diagnosis'}, $p1, $p2 - $p1));
179 }
180 30 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
181 }
182  
183 35 1;
184 __END__
« Sisimai/DateTime.pm ↑ Summary Sisimai/Lhost/KDDI.pm »