Sisimai/Lhost/Exchange2007.pm

filter: Statementstmt 97.7% 88 / 90 Branchbran 83.3% 40 / 48 Conditioncond 86.3% 19 / 22 MC/DCmcdc 75.0% 9 / 12 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 91.1% 165 / 181 CC 38 SCAR 35.2
CC
38
Cov
92%
inquire
39.1
BEGIN
1.0
BEGIN
1.0
CRAP 33.9
« Sisimai/Lhost/MessagingServer.pm ↑ Summary Sisimai/Lhost/Mimecast.pm »
1 package Sisimai::Lhost::Exchange2007;
2 46 ▶use parent 'Sisimai::Lhost';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 46 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 46 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 46 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 46 ▶use Sisimai::Eb;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶sub description { 'Microsoft Exchange Server 2007: https://www.microsoft.com/microsoft-365/exchange/email' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
9 1062 ▶sub inquire {
Subroutine inquire: called CC=38 SCAR=36.7
Pod documented
10 # Detect an error from Microsoft Exchange Server 2007
11 # @param [Hash] mhead Message headers of a bounce email
12 # @param [String] mbody Message body of a bounce email
13 # @return [Hash] Bounce data list and message/rfc822 part
14 # @return [undef] failed to decode or the arguments are missing
15 # @since v4.1.1
16 1062 my $class = shift;
17 1062 ▶ my $mhead = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
10602
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18 1060 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
10582
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
19  
20 1058 my $mailsender = ['postmaster@outlook.com', ".onmicrosoft.com"];
21 1058 my $emailtitle = [
22 # "Subject:" "Content-Language:"
23 "Undeliverable", # en-US
24 "Non_remis_", # fr-FR
25 "Non remis ", # fr-FR
26 "Non recapitabile", # it-CH
27 "Olevererbart", # sv-SE
28 ];
29 1058 state $boundaries = [
30 "Original Message Headers",
31 "Original message headers:", # en-US
32 "tes de message d'origine :", # fr-FR/En-têtes de message d'origine
33 "Intestazioni originali del messaggio:", # it-CH
34 "Ursprungshuvuden:", # sv-SE
35 ];
36 1058 state $startingof = {
37 "error" => [" RESOLVER.", " QUEUE."],
38 "message" => [
39 "Error Details",
40 "Diagnostic information for administrators:", # en-US
41 "Informations de diagnostic pour les administrateurs", # fr-FR
42 "Informazioni di diagnostica per gli amministratori", # it-CH
43 "Diagnostisk information f", # sv-SE
44 ],
45 "rhost" => [
46 "DSN generated by:",
47 "Generating server", # en-US
48 "Serveur de g", # fr-FR/Serveur de gènèration
49 "Server di generazione", # it-CH
50 "Genererande server", # sv-SE
51 ],
52 };
53 1058 state $ndrsubject = {
54 "SMTPSEND.DNS.NonExistentDomain" => $Sisimai::Eb::ReHOST, # 554 5.4.4 SMTPSEND.DNS.NonExistentDomain
55 "SMTPSEND.DNS.MxLoopback" => $Sisimai::Eb::ReINET, # 554 5.4.4 SMTPSEND.DNS.MxLoopback
56 "RESOLVER.ADR.BadPrimary" => $Sisimai::Eb::RePROC, # 550 5.2.0 RESOLVER.ADR.BadPrimary
57 "RESOLVER.ADR.RecipNotFound" => $Sisimai::Eb::ReUSER, # 550 5.1.1 RESOLVER.ADR.RecipNotFound
58 "RESOLVER.ADR.RecipientNotFound" => $Sisimai::Eb::ReUSER, # 550 5.1.1 RESOLVER.ADR.RecipientNotFound
59 "RESOLVER.ADR.ExRecipNotFound" => $Sisimai::Eb::ReUSER, # 550 5.1.1 RESOLVER.ADR.ExRecipNotFound
60 "RESOLVER.ADR.RecipLimit" => $Sisimai::Eb::ReRATE, # 550 5.5.3 RESOLVER.ADR.RecipLimit
61 "RESOLVER.ADR.InvalidInSmtp" => $Sisimai::Eb::RePROC, # 550 5.1.0 RESOLVER.ADR.InvalidInSmtp
62 "RESOLVER.ADR.Ambiguous" => $Sisimai::Eb::RePROC, # 550 5.1.4 RESOLVER.ADR.Ambiguous, 420 4.2.0 RESOLVER.ADR.Ambiguous
63 "RESOLVER.RST.AuthRequired" => $Sisimai::Eb::ReSAFE, # 550 5.7.1 RESOLVER.RST.AuthRequired
64 "RESOLVER.RST.NotAuthorized" => $Sisimai::Eb::ReFROM, # 550 5.7.1 RESOLVER.RST.NotAuthorized
65 "RESOLVER.RST.RecipSizeLimit" => $Sisimai::Eb::ReSIZE, # 550 5.2.3 RESOLVER.RST.RecipSizeLimit
66 "QUEUE.Expired" => $Sisimai::Eb::ReTIME, # 550 4.4.7 QUEUE.Expired
67 };
68 1058 ▶ my $proceedsto = 0; $proceedsto++ if grep { index($mhead->{"subject"}, $_) > -1 } @$emailtitle;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($mhead->{"subject"}, $_) != -1;} @$emailtitle 175 883 1058
69 1058 ▶ $proceedsto++ if grep { index($mhead->{"from"}, $_) > 1 } @$mailsender;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($mhead->{"from"}, $_) > 1;} @$mailsender 55 1003 1058
70 1058 ▶ $proceedsto++ if grep { index($$mbody, $_) > 1 } $startingof->{"error"}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($$mbody, $_) > 1;} @{$$startingof{"error"}} 53 1005 1058
71 1058 ▶ $proceedsto++ if grep { index($$mbody, $_) > 1 } $startingof->{"message"}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($$mbody, $_) > 1;} @{$$startingof{"message"}} 108 950 1058
72 1058 ▶ $proceedsto++ if defined $mhead->{"content-language"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $mhead->{"content-language"} 103 955 1058
73 1058 ▶ return undef if $proceedsto < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $proceedsto < 2 950 108 1058
74  
75 108 require Sisimai::RFC1123;
76 108 state $indicators = __PACKAGE__->INDICATORS;
77  
78 108 ▶ my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries) // return undef; return undef unless $emailparts->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $emailparts->[0] 0 108 108
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
1080
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
79 108 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef;
80 108 my $readcursor = 0; # (Integer) Points the current cursor position
81 108 my $recipients = 0; # (Integer) The number of 'Final-Recipient' header
82  
83 108 for my $e ( split("\n", $emailparts->[0]) ) {
84 # Read error messages and delivery status lines from the head of the email to the previous
85 # line of the beginning of the original message.
86 3131 ▶ unless( $readcursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readcursor) 2436 695 3131
87 # Beginning of the bounce message or message/delivery-status part
88 2436 ▶ $readcursor |= $indicators->{"deliverystatus"} if grep { index($e, $_) == 0 } $startingof->{"message"}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($e, $_) == 0;} @{$$startingof{"message"}} 108 2328 2436
89 2436 next;
90 }
91 695 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq "" 221 474 695
Condition66%2/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
l!l&&r!l&&!r
0221474
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
92  
93 # Diagnostic information for administrators:
94 #
95 # Generating server: mta2.neko.example.jp
96 #
97 # kijitora@example.jp
98 # #550 5.1.1 RESOLVER.ADR.RecipNotFound; not found ##
99 #
100 # Original message headers:
101 474 $v = $dscontents->[-1];
102  
103 474 ▶ if( index($e, " ") < 0 && index($e, '@') > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($e, ' ') == -1 and index($e, '@') > 1) { } 97 377 474
Condition100%3/3
index($e, " ") == -1 and index($e, "\@") > 1
!ll&&!rl&&r
3324597
MC/DC100%2/2
index($e, " ") == -1 and index($e, "\@") > 1
index($e, " ") == -1 index($e, "\@") > 1
Truth table100%3/3
A and B
A= index($e, " ") == -1B= index($e, "\@") > 1
ABresult
0X0
100
111
104 # kijitora@example.jp
105 97 ▶ if( $v->{"recipient"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 0 97 97
106 # There are multiple recipient addresses in the message body.
107 0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
108 0 $v = $dscontents->[-1];
109 }
110 97 $v->{"recipient"} = Sisimai::Address->s3s4($e);
111 97 $recipients++;
112  
113 } else {
114 # Try to pick the remote hostname and status code, reply code from the error message
115 377 ▶ if( grep { index($e, $_) == 0 } $startingof->{"rhost"}->@* ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {index($e, $_) == 0;} @{$$startingof{'rhost'}}) { } 108 269 377
116 # Generating server: SG2APC01HT234.mail.protection.outlook.com
117 # DSN generated by: NEKONYAAN0022.apcprd01.prod.exchangelabs.com
118 108 my $cv = Sisimai::RFC1123->find($e);
119 108 ▶ $v->{"rhost"} = $cv if Sisimai::RFC1123->is_internethost($cv);
Branch: 1 branch
BranchTrueFalseTotal
if "Sisimai::RFC1123"->is_internethost($cv) 108 0 108
120  
121 } else {
122 # #550 5.1.1 RESOLVER.ADR.RecipNotFound; not found ##
123 # #550 5.2.3 RESOLVER.RST.RecipSizeLimit; message too large for this recipient ##
124 269 ▶ my $cr = Sisimai::SMTP::Reply->find($e) || "";
Condition100%2/2
'Sisimai::SMTP::Reply'->find($e) || ''
l!l
118151
MC/DC100%1/1
'Sisimai::SMTP::Reply'->find($e) || ''
'Sisimai::SMTP::Reply'->find($e)
Truth table100%2/2
A
A= 'Sisimai::SMTP::Reply'->find($e)
Aresult
11
00
125 269 ▶ my $cs = Sisimai::SMTP::Status->find($e) || "";
Condition100%2/2
'Sisimai::SMTP::Status'->find($e) || ''
l!l
123146
MC/DC100%1/1
'Sisimai::SMTP::Status'->find($e) || ''
'Sisimai::SMTP::Status'->find($e)
Truth table100%2/2
A
A= 'Sisimai::SMTP::Status'->find($e)
Aresult
11
00
126 269 ▶ if( $cr ne "" || $cs ne "" || index($e, "Remote Server ") > -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cr ne "" or $cs ne "" or index($e, "Remote Server ") != -1) 123 146 269
Condition83%5/6
$cr ne "" or $cs ne "" or index($e, "Remote Server ") != -1
l!l&&r!l&&!r
1230146
$cr ne "" or $cs ne ""
l!l&&r!l&&!r
1185146
MC/DC66%2/3
$cr ne "" or $cs ne "" or index($e, "Remote Server ") != -1
$cr ne "" $cs ne "" index($e, "Remote Server ") != -1
Truth table75%3/4
A or B or C
A= $cr ne ""B= $cs ne ""C= index($e, "Remote Server ") != -1
ABCresult
1XX1
01X1
0011
0000
127 # Remote Server returned '550 5.1.1 RESOLVER.ADR.RecipNotFound; not found'
128 # 3/09/2016 8:05:56 PM - Remote Server at mydomain.com (10.1.1.3) returned '550 4.4.7 QUEUE.Expired; message expired'
129 123 $v->{"replycode"} = $cr;
130 123 $v->{"status"} = $cs;
131 123 $v->{"diagnosis"} .= $e." ";
132 }
133 }
134 }
135 }
136  
137 108 ▶ while( $recipients == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recipients == 0) 11 108 119
138 # Try to pick the recipient address from the following formatted bounce message:
139 #
140 # Original Message Details
141 # Created Date: 4/29/2017 11:23:34 PM
142 # Sender Address: neko@example.com
143 # Recipient Address: kijitora-nyaan@neko.kyoto.example.jp
144 # Subject: Nyaan?
145 11 ▶ my $p1 = index($emailparts->[0], "Original Message Details"); last if $p1 < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $p1 < 0 0 11 11
146 11 ▶ my $p2 = index($emailparts->[0], "\nRecipient Address: "); last if $p2 < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $p2 < 0 0 11 11
147 11 ▶ my $p3 = index($emailparts->[0], "\n", $p2 + 20); last if $p3 < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $p3 < 0 0 11 11
148 11 my $cv = Sisimai::Address->s3s4(substr($emailparts->[0], $p2 + 20, $p3 - $p2 - 20));
149  
150 11 ▶ last unless Sisimai::Address->is_emailaddress($cv);
Branch: 1 branch
BranchTrueFalseTotal
unless "Sisimai::Address"->is_emailaddress($cv) 0 11 11
151 11 $dscontents->[0]->{"recipient"} = $cv;
152 11 $recipients++;
153 }
154 108 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 0 108 108
155  
156 108 for my $e ( @$dscontents ) {
157 108 my $p0 = -1; for my $r ( $startingof->{"error"}->@* ) {
158 # Try to find the NDR subject string such as "RESOLVER.ADR.RecipientNotFound" from the
159 # error message
160 168 ▶ $p0 = index($e->{"diagnosis"}, $r); last if $p0 > -1;
Branch: 1 branch
BranchTrueFalseTotal
if $p0 > -1 53 115 168
161 }
162 108 ▶ next if $p0 < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $p0 < 0 55 53 108
163  
164 53 my $cv = substr($e->{"diagnosis"}, $p0 + 1, index($e->{"diagnosis"}, ";") - $p0 - 1);
165 53 for my $r ( keys %$ndrsubject ) {
166 # Try to match with error subject strings such as "RESOLVER.ADR.RecipNotFound"
167 476 ▶ next unless $cv eq $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $cv eq $r 423 53 476
168 53 $e->{"reason"} = $ndrsubject->{ $r };
169 53 last;
170 }
171 }
172 108 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
173 }
174  
175 46 1;
176 __END__
« Sisimai/Lhost/MessagingServer.pm ↑ Summary Sisimai/Lhost/Mimecast.pm »