Sisimai/Lhost/IMailServer.pm

filter: Statementstmt 96.3% 53 / 55 Branchbran 86.3% 19 / 22 Conditioncond 87.5% 21 / 24 MC/DCmcdc 76.9% 10 / 13 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 90.9% 111 / 122 CC 25 SCAR 30.6
CC
25
Cov
92%
inquire
25.5
BEGIN
1.0
BEGIN
1.0
CRAP 21.4
« Sisimai/Lhost/MailMarshal.pm ↑ Summary Sisimai/Reason.pm »
1 package Sisimai::Lhost::IMailServer;
2 36 ▶use parent 'Sisimai::Lhost';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 36 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶sub description { 'Progress iMail Server: https://community.progress.com/s/products/imailserver' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
8 893 ▶sub inquire {
Subroutine inquire: called CC=25 SCAR=32.4
Pod documented
9 # Detect an error from Progress iMail Server
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.1
15 893 my $class = shift;
16 893 ▶ my $mhead = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
8921
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
17 892 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
8911
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18  
19 # X-Mailer: <SMTP32 v8.22>
20 891 ▶ my $match = 0; $match ||= 1 if index($mhead->{'subject'}, 'Undeliverable Mail ') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($mhead->{"subject"}, "Undeliverable Mail ") == 0 5 886 891
Condition50%1/2
$match ||= 1
l!l
05
MC/DC0%0/1
$match ||= 1
$match
Truth table50%1/2
A
A= $match
Aresult
11
00
21 891 ▶ $match ||= 1 if defined $mhead->{'x-mailer'} && index($mhead->{'x-mailer'}, '<SMTP32 v') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mhead->{"x-mailer"} and index($mhead->{"x-mailer"}, "<SMTP32 v") == 0 26 865 891
Condition100%5/5
defined $mhead->{"x-mailer"} and index($mhead->{"x-mailer"}, "<SMTP32 v") == 0
!ll&&!rl&&r
7937226
$match ||= 1
l!l
521
MC/DC100%2/2
defined $mhead->{"x-mailer"} and index($mhead->{"x-mailer"}, "<SMTP32 v") == 0
defined $mhead->{"x-mailer"} index($mhead->{"x-mailer"}, "<SMTP32 v") == 0
MC/DC100%1/1
$match ||= 1
$match
Truth table100%3/3
A and B
A= defined $mhead->{"x-mailer"}B= index($mhead->{"x-mailer"}, "<SMTP32 v") == 0
ABresult
0X0
100
111
Truth table100%2/2
A
A= $match
Aresult
11
00
22 891 ▶ return undef unless $match;
Branch: 1 branch
BranchTrueFalseTotal
unless $match 865 26 891
23  
24 26 require Sisimai::Eb;
25 26 state $boundaries = ['Original message follows.'];
26 26 state $startingof = {'error' => ['Body of message generated response:']};
27 26 state $messagesof = {
28 $Sisimai::Eb::ReUSER => ['Unknown user', 'Invalid final delivery userid'],
29 $Sisimai::Eb::ReTIME => ['Delivery failed '],
30 };
31  
32 26 ▶ my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries) // return undef; return undef unless $emailparts->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $emailparts->[0] 0 26 26
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
260
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
33 26 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef;
34 26 my $recipients = 0; # (Integer) The number of 'Final-Recipient' header
35  
36 26 for my $e ( split("\n", $emailparts->[0]) ) {
37 # Read error messages and delivery status lines from the head of the email to the previous
38 # line of the beginning of the original message.
39  
40 # Unknown user: kijitora@example.com
41 #
42 # Original message follows.
43 96 $v = $dscontents->[-1];
44  
45 96 my $p0 = index($e, ': ');
46 96 ▶ if( ($p0 > 8 && Sisimai::String->aligned(\$e, [': ', '@'])) || index($e, 'undeliverable ') == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p0 > 8 and 'Sisimai::String'->aligned(\$e, [': ', '@']) or index($e, 'undeliverable ') == 0) { } 26 70 96
Condition100%6/6
$p0 > 8 and "Sisimai::String"->aligned(\$e, [": ", "\@"]) or index($e, "undeliverable ") == 0
l!l&&r!l&&!r
21570
$p0 > 8 and "Sisimai::String"->aligned(\$e, [": ", "\@"])
!ll&&!rl&&r
651021
MC/DC100%3/3
$p0 > 8 and "Sisimai::String"->aligned(\$e, [": ", "\@"]) or index($e, "undeliverable ") == 0
$p0 > 8 "Sisimai::String"->aligned(\$e, [": ", "\@"]) index($e, "undeliverable ") == 0
Truth table80%4/5
A and B or C
A= $p0 > 8B= "Sisimai::String"->aligned(\$e, [": ", "\@"])C= index($e, "undeliverable ") == 0
ABCresult
11X1
0X11
1011
0X00
1000
47 # Unknown user: kijitora@example.com
48 # undeliverable to kijitora@example.com
49 26 ▶ if( $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 0 26 26
50 # There are multiple recipient addresses in the message body.
51 0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
52 0 $v = $dscontents->[-1];
53 }
54 26 $v->{'diagnosis'} = $e;
55 26 $v->{'recipient'} = Sisimai::Address->s3s4($e);
56 26 $recipients++;
57  
58 } else {
59 # Other error message text
60 70 ▶ $v->{'alterrors'} //= '';
Condition100%2/2
$v->{"alterrors"} //= ""
l!l
655
MC/DC100%1/1
$v->{"alterrors"} //= ""
$v->{"alterrors"}
Truth table100%2/2
A
A= $v->{"alterrors"}
Aresult
11
00
61 70 ▶ $v->{'alterrors'} .= ' '.$e if $v->{'alterrors'};
Branch: 1 branch
BranchTrueFalseTotal
if $v->{"alterrors"} 25 45 70
62 70 ▶ $v->{'alterrors'} = $e if index($e, $startingof->{'error'}->[0]) > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, $startingof->{"error"}[0]) != -1 5 65 70
63 }
64 }
65 26 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 0 26 26
66  
67 26 require Sisimai::SMTP::Command;
68 26 for my $e ( @$dscontents ) {
69 26 ▶ if( exists $e->{'alterrors'} && $e->{'alterrors'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $e->{"alterrors"} and $e->{"alterrors"}) 5 21 26
Condition66%2/3
exists $e->{"alterrors"} and $e->{"alterrors"}
!ll&&!rl&&r
2105
MC/DC50%1/2
exists $e->{"alterrors"} and $e->{"alterrors"}
exists $e->{"alterrors"} $e->{"alterrors"}
Truth table66%2/3
A and B
A= exists $e->{"alterrors"}B= $e->{"alterrors"}
ABresult
0X0
100
111
70 # Copy alternative error message
71 5 $e->{'diagnosis'} = $e->{'alterrors'}.' '.$e->{'diagnosis'};
72 5 delete $e->{'alterrors'};
73 }
74 26 $e->{'command'} = Sisimai::SMTP::Command->find($e->{'diagnosis'});
75  
76 26 SESSION: for my $r ( keys %$messagesof ) {
77 # Verify each regular expression of session errors
78 47 ▶ next unless grep { index($e->{'diagnosis'}, $_) > -1 } $messagesof->{ $r }->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {index($e->{"diagnosis"}, $_) != -1;} @{$$messagesof{$r}} 31 16 47
79 16 $e->{'reason'} = $r;
80 16 last;
81 }
82 }
83 26 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
84 }
85  
86 36 1;
87 __END__
« Sisimai/Lhost/MailMarshal.pm ↑ Summary Sisimai/Reason.pm »