Sisimai/Lhost/Courier.pm

filter: Statementstmt 96.3% 78 / 81 Branchbran 81.2% 39 / 48 Conditioncond 60.6% 20 / 33 MC/DCmcdc 47.0% 8 / 17 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 81.8% 153 / 187 CC 43 SCAR 38.4
CC
43
Cov
85%
inquire
51.7
BEGIN
1.0
BEGIN
1.0
CRAP 46.4
« Sisimai/Lhost/Verizon.pm ↑ Summary Sisimai/DateTime.pm »
1 package Sisimai::Lhost::Courier;
2 37 ▶use parent 'Sisimai::Lhost';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 37 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 37 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 37 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶sub description { 'Courier MTA' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
8 893 ▶sub inquire {
Subroutine inquire: called CC=43 SCAR=39.5
Pod documented
9 # Detect an error from Courier MTA
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 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 891 ▶ my $match = 0; $match ||= 1 if index($mhead->{'from'}, 'Courier mail server at ') > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($mhead->{"from"}, "Courier mail server at ") != -1 0 891 891
Condition0%0/2
$match ||= 1
l!l
00
MC/DC0%0/1
$match ||= 1
$match
Truth table0%0/2
A
A= $match
Aresult
11
00
19 891 ▶ $match ||= 1 if index($mhead->{'subject'}, 'NOTICE: mail delivery status.') > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($mhead->{"subject"}, "NOTICE: mail delivery status.") != -1 21 870 891
Condition50%1/2
$match ||= 1
l!l
021
MC/DC0%0/1
$match ||= 1
$match
Truth table50%1/2
A
A= $match
Aresult
11
00
20 891 ▶ $match ||= 1 if index($mhead->{'subject'}, 'WARNING: delayed mail.') > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($mhead->{"subject"}, "WARNING: delayed mail.") != -1 0 891 891
Condition0%0/2
$match ||= 1
l!l
00
MC/DC0%0/1
$match ||= 1
$match
Truth table0%0/2
A
A= $match
Aresult
11
00
21 891 ▶ if( defined $mhead->{'message-id'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mhead->{"message-id"}) 829 62 891
22 # Message-ID: <courier.4D025E3A.00001792@5jo.example.org>
23 829 ▶ $match ||= 1 if index($mhead->{'message-id'}, '<courier.') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($mhead->{"message-id"}, "<courier.") == 0 21 808 829
Condition50%1/2
$match ||= 1
l!l
210
MC/DC0%0/1
$match ||= 1
$match
Truth table50%1/2
A
A= $match
Aresult
11
00
24 }
25 891 ▶ return undef unless $match;
Branch: 1 branch
BranchTrueFalseTotal
unless $match 870 21 891
26  
27 21 require Sisimai::Eb;
28 21 require Sisimai::RFC1123;
29 21 require Sisimai::SMTP::Command;
30 21 state $indicators = __PACKAGE__->INDICATORS;
31 21 state $boundaries = ['Content-Type: :message/rfc822', 'Content-Type: text/rfc822-headers'];
32 21 state $startingof = {
33 # https://www.courier-mta.org/courierdsn.html
34 # courier/module.dsn/dsn*.txt
35 'message' => ['DELAYS IN DELIVERING YOUR MESSAGE', 'UNDELIVERABLE MAIL'],
36 };
37 21 state $messagesof = {
38 # courier/module.esmtp/esmtpclient.c:526| hard_error(del, ctf, "No such domain.");
39 $Sisimai::Eb::ReHOST => ['No such domain.'],
40 # courier/module.esmtp/esmtpclient.c:531| hard_error(del, ctf,
41 # courier/module.esmtp/esmtpclient.c:532| "This domain's DNS violates RFC 1035.");
42 $Sisimai::Eb::RePROC => ["This domain's DNS violates RFC 1035."],
43 # courier/module.esmtp/esmtpclient.c:535| soft_error(del, ctf, "DNS lookup failed.");
44 $Sisimai::Eb::ReINET => ['DNS lookup failed.'],
45 };
46  
47 21 ▶ my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries) // return undef; return undef unless $emailparts->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $emailparts->[0] 0 21 21
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
210
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
48 21 my $fieldtable = Sisimai::RFC1894->FIELDTABLE;
49 21 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef;
50 21 my $permessage = {}; # (Hash) Store values of each Per-Message field
51 21 my $readcursor = 0; # (Integer) Points the current cursor position
52 21 my $recipients = 0; # (Integer) The number of 'Final-Recipient' header
53 21 my $thecommand = ''; # (String) SMTP Command name begin with the string '>>>'
54 21 my $p = '';
55  
56 21 for my $e ( split("\n", $emailparts->[0]) ) {
57 # Read error messages and delivery status lines from the head of the email to the previous
58 # line of the beginning of the original message.
59 1060 ▶ unless( $readcursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readcursor) 252 808 1060
60 # Beginning of the bounce message or message/delivery-status part
61 252 ▶ if( rindex($e, $startingof->{'message'}->[0]) > -1 || rindex($e, $startingof->{'message'}->[1]) > -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (rindex($e, $startingof->{"message"}[0]) != -1 or rindex($e, $startingof->{"message"}[1]) != -1) 21 231 252
Condition66%2/3
rindex($e, $startingof->{"message"}[0]) != -1 or rindex($e, $startingof->{"message"}[1]) != -1
l!l&&r!l&&!r
021231
MC/DC50%1/2
rindex($e, $startingof->{"message"}[0]) != -1 or rindex($e, $startingof->{"message"}[1]) != -1
rindex($e, $startingof->{"message"}[0]) != -1 rindex($e, $startingof->{"message"}[1]) != -1
Truth table66%2/3
A or B
A= rindex($e, $startingof->{"message"}[0]) != -1B= rindex($e, $startingof->{"message"}[1]) != -1
ABresult
1X1
011
000
62 21 $readcursor |= $indicators->{'deliverystatus'};
63 21 next;
64 }
65 }
66 1039 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq "" 430 609 1039
Condition100%3/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
l!l&&r!l&&!r
231199609
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
67  
68 609 ▶ if( my $f = Sisimai::RFC1894->match($e) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = 'Sisimai::RFC1894'->match($e)) { } 163 446 609
69 # $e matched with any field defined in RFC3464
70 163 ▶ next unless my $o = Sisimai::RFC1894->field($e);
Branch: 1 branch
BranchTrueFalseTotal
unless my $o = "Sisimai::RFC1894"->field($e) 0 163 163
71 163 $v = $dscontents->[-1];
72  
73 163 ▶ if( $o->[3] eq 'addr' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($o->[3] eq 'addr') { } 21 142 163
elsif ($o->[3] eq 'code') { } 21 121 142
74 # Final-Recipient: rfc822; kijitora@example.jp
75 # X-Actual-Recipient: rfc822; kijitora@example.co.jp
76 21 ▶ if( $o->[0] eq 'final-recipient' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->[0] eq 'final-recipient') { } 21 0 21
77 # Final-Recipient: rfc822; kijitora@example.jp
78 21 ▶ if( $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 0 21 21
79 # There are multiple recipient addresses in the message body.
80 0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
81 0 $v = $dscontents->[-1];
82 }
83 21 $v->{'recipient'} = $o->[2];
84 21 $recipients++;
85  
86 } else {
87 # X-Actual-Recipient: rfc822; kijitora@example.co.jp
88 0 $v->{'alias'} = $o->[2];
89 }
90 } elsif( $o->[3] eq 'code' ) {
91 # Diagnostic-Code: SMTP; 550 5.1.1 <userunknown@example.jp>... User Unknown
92 21 $v->{'spec'} = $o->[1];
93 21 $v->{'diagnosis'} = $o->[2];
94  
95 } else {
96 # Other DSN fields defined in RFC3464
97 121 ▶ next unless exists $fieldtable->{ $o->[0] };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$fieldtable{$o->[0]} 0 121 121
98 121 ▶ 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 22 99 121
Condition100%3/3
$o->[3] eq "host" and "Sisimai::RFC1123"->is_internethost($o->[2]) == 0
!ll&&!rl&&r
633622
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
99 99 $v->{ $fieldtable->{ $o->[0] } } = $o->[2];
100  
101 99 ▶ next unless $f == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $f == 1 42 57 99
102 57 $permessage->{ $fieldtable->{ $o->[0] } } = $o->[2];
103 }
104 } else {
105 # The line does not begin with a DSN field defined in RFC3464
106 #
107 # This is a delivery status notification from marutamachi.example.org,
108 # running the Courier mail server, version 0.65.2.
109 #
110 # The original message was received on Sat, 11 Dec 2010 12:19:57 +0900
111 # from [127.0.0.1] (c10920.example.com [192.0.2.20])
112 #
113 # ---------------------------------------------------------------------------
114 #
115 # UNDELIVERABLE MAIL
116 #
117 # Your message to the following recipients cannot be delivered:
118 #
119 # <kijitora@example.co.jp>:
120 # mx.example.co.jp [74.207.247.95]:
121 # >>> RCPT TO:<kijitora@example.co.jp>
122 # <<< 550 5.1.1 <kijitora@example.co.jp>... User Unknown
123 #
124 # ---------------------------------------------------------------------------
125 446 ▶ if( index($e, '>>> ') == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($e, '>>> ') == 0) { } 16 430 446
126 # >>> DATA
127 16 $thecommand = Sisimai::SMTP::Command->find($e);
128  
129 } else {
130 # Continued line of the value of Diagnostic-Code field
131 430 ▶ next unless index($p, 'Diagnostic-Code:') == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless index($p, "Diagnostic-Code:") == 0 425 5 430
132 5 ▶ next unless index($e, ' ') == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless index($e, " ") == 0 0 5 5
133 5 $v->{'diagnosis'} .= ' '.$e;
134 }
135 }
136 } continue {
137 # Save the current line for the next loop
138 1060 $p = $e;
139 }
140 21 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 0 21 21
141  
142 21 for my $e ( @$dscontents ) {
143 # Set default values if each value is empty.
144 21 ▶ $e->{ $_ } ||= $permessage->{ $_ } || '' for keys %$permessage;
Condition20%1/5
$e->{$_} ||= $permessage->{$_} || ""
l!l&&r!l&&!r
4200
$permessage->{$_} || ''
l!l
00
MC/DC0%0/2
$e->{$_} ||= $permessage->{$_} || ""
$e->{$_} $permessage->{$_}
Truth table33%1/3
A ||= B
A= $e->{$_}B= $permessage->{$_}
ABresult
1X1
011
000
145 21 $e->{'diagnosis'} = Sisimai::String->sweep($e->{'diagnosis'});
146  
147 21 for my $r ( keys %$messagesof ) {
148 # Verify each regular expression of session errors
149 54 ▶ next unless grep { index($e->{'diagnosis'}, $_) > -1 } $messagesof->{ $r }->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {index($e->{"diagnosis"}, $_) != -1;} @{$$messagesof{$r}} 49 5 54
150 5 $e->{'reason'} = $r;
151 5 last;
152 }
153 21 ▶ $e->{'command'} ||= $thecommand || '';
Condition80%4/5
$e->{"command"} ||= $thecommand || ""
l!l&&r!l&&!r
0165
$thecommand || ''
l!l
165
MC/DC50%1/2
$e->{"command"} ||= $thecommand || ""
$e->{"command"} $thecommand
Truth table66%2/3
A ||= B
A= $e->{"command"}B= $thecommand
ABresult
1X1
011
000
154 }
155 21 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
156 }
157  
158 37 1;
159 __END__
« Sisimai/Lhost/Verizon.pm ↑ Summary Sisimai/DateTime.pm »