Sisimai/Lhost/Exchange2003.pm

filter: Statementstmt 100% 107 / 107 Branchbran 82.3% 56 / 68 Conditioncond 67.5% 25 / 37 MC/DCmcdc 50.0% 11 / 22 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 85.6% 208 / 243 CC 54 SCAR 39.8
CC
54
Cov
89%
inquire
59.4
BEGIN
1.0
BEGIN
1.0
CRAP 53.5
« Sisimai/Lhost/Domino.pm ↑ Summary Sisimai/Lhost/Verizon.pm »
1 package Sisimai::Lhost::Exchange2003;
2 43 ▶use parent 'Sisimai::Lhost';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 43 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 43 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 43 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 43 ▶use Sisimai::Eb;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶sub description { 'Microsoft Exchange Server 2003: https://www.microsoft.com/microsoft-365/exchange/email' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
9 952 ▶sub inquire {
Subroutine inquire: called CC=54 SCAR=40.8
Pod documented
10 # Detect an error from Microsoft Exchange Server 2003
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 952 my $class = shift;
17 952 ▶ my $mhead = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
9511
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18 951 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
9501
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
19  
20 # X-MS-TNEF-Correlator: <00000000000000000000000000000000000000@example.com>
21 # X-Mailer: Internet Mail Service (5.5.1960.3)
22 # X-MS-Embedded-Report:
23 950 ▶ my $match = 0; $match ||= 1 if defined $mhead->{'x-ms-embedded-report'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $mhead->{"x-ms-embedded-report"} 22 928 950
Condition50%1/2
$match ||= 1
l!l
022
MC/DC0%0/1
$match ||= 1
$match
Truth table50%1/2
A
A= $match
Aresult
11
00
24 950 EXCHANGE_OR_NOT: while(1) {
25 # Check the value of X-Mailer header
26 950 ▶ last if $match;
Branch: 1 branch
BranchTrueFalseTotal
if $match 22 928 950
27  
28 928 ▶ if( defined $mhead->{'x-mailer'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mhead->{"x-mailer"}) 82 846 928
29 # X-Mailer: Microsoft Exchange Server Internet Mail Connector Version 4.0.994.63
30 # X-Mailer: Internet Mail Service (5.5.2232.9)
31 82 my $tryto = ['Internet Mail Service (', 'Microsoft Exchange Server Internet Mail Connector'];
32 82 ▶ my $value = $mhead->{'x-mailer'} || '';
Condition50%1/2
$mhead->{'x-mailer'} || ''
l!l
820
MC/DC0%0/1
$mhead->{'x-mailer'} || ''
$mhead->{'x-mailer'}
Truth table50%1/2
A
A= $mhead->{'x-mailer'}
Aresult
11
00
33 82 ▶ $match ||= 1 if index($value, $tryto->[0]) == 0 || index($value, $tryto->[1]) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($value, $tryto->[0]) == 0 or index($value, $tryto->[1]) == 0 5 77 82
Condition60%3/5
index($value, $tryto->[0]) == 0 or index($value, $tryto->[1]) == 0
l!l&&r!l&&!r
0577
$match ||= 1
l!l
05
MC/DC50%1/2
index($value, $tryto->[0]) == 0 or index($value, $tryto->[1]) == 0
index($value, $tryto->[0]) == 0 index($value, $tryto->[1]) == 0
MC/DC0%0/1
$match ||= 1
$match
Truth table66%2/3
A or B
A= index($value, $tryto->[0]) == 0B= index($value, $tryto->[1]) == 0
ABresult
1X1
011
000
Truth table50%1/2
A
A= $match
Aresult
11
00
34 82 ▶ last if $match;
Branch: 1 branch
BranchTrueFalseTotal
if $match 5 77 82
35 }
36  
37 923 ▶ if( defined $mhead->{'x-mimeole'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mhead->{"x-mimeole"}) 5 918 923
38 # X-MimeOLE: Produced By Microsoft Exchange V6.5
39 5 ▶ $match ||= 1 if index($mhead->{'x-mimeole'}, 'Produced By Microsoft Exchange') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($mhead->{"x-mimeole"}, "Produced By Microsoft Exchange") == 0 0 5 5
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
40 5 ▶ last if $match;
Branch: 1 branch
BranchTrueFalseTotal
if $match 0 5 5
41 }
42  
43 923 ▶ last unless scalar $mhead->{'received'}->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$mhead->{"received"}} 78 845 923
44 845 for my $e ( $mhead->{'received'}->@* ) {
45 # Received: by ***.**.** with Internet Mail Service (5.5.2657.72)
46 1786 ▶ next unless rindex($e, ' with Internet Mail Service (') > -1;
Branch: 1 branch
BranchTrueFalseTotal
unless rindex($e, " with Internet Mail Service (") != -1 1781 5 1786
47 5 $match = 1;
48 5 last(EXCHANGE_OR_NOT);
49 }
50 840 last;
51 }
52 950 ▶ return undef unless $match;
Branch: 1 branch
BranchTrueFalseTotal
unless $match 918 32 950
53  
54 32 state $indicators = __PACKAGE__->INDICATORS;
55 32 state $boundaries = ['Content-Type: message/rfc822'];
56 32 state $startingof = {
57 'message' => ['Your message'],
58 'error' => ['did not reach the following recipient(s):'],
59 };
60 32 state $errorcodes = {
61 $Sisimai::Eb::ReUSER => ['000C05A6'], # Unknown Recipient,
62 $Sisimai::Eb::ReFILT => ['000C0595'], # Ambiguous Recipient
63 $Sisimai::Eb::ReINET => ['00120270'], # Too Many Hops
64 $Sisimai::Eb::ReSAFE => ['000B0981'], # 502 Server does not support AUTH
65 $Sisimai::Eb::Re___1 => [ # OnHold
66 '000B099C', # Host Unknown, Message exceeds size limit, ...
67 '000B09AA', # Unable to relay for, Message exceeds size limit,...
68 '000B09B6', # Error messages by remote MTA
69 ],
70 $Sisimai::Eb::RePROC => [ # SystemError
71 '00010256', # Too many recipients.
72 '000D06B5', # No proxy for recipient (non-smtp mail?)
73 ],
74 $Sisimai::Eb::ReBODY => [ # ContentError
75 '00050311', # Conversion to Internet format failed
76 '000502CC', # Conversion to Internet format failed
77 ],
78 };
79  
80 32 ▶ my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries) // return undef; return undef unless $emailparts->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $emailparts->[0] 0 32 32
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
320
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
81 32 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef;
82 32 my $readcursor = 0; # (Integer) Points the current cursor position
83 32 my $recipients = 0; # (Integer) The number of 'Final-Recipient' header
84 32 my $statuspart = 0; # (Integer) Flag, 1 = have got delivery status part.
85 32 my $connvalues = 0; # (Integer) Flag, 1 if all the value of $connheader have been set
86 32 my $connheader = {
87 'to' => '', # The value of "To"
88 'date' => '', # The value of "Date"
89 'subject' => '', # The value of "Subject"
90 };
91  
92 32 for my $e ( split("\n", $emailparts->[0]) ) {
93 # Read error messages and delivery status lines from the head of the email to the previous
94 # line of the beginning of the original message.
95 474 ▶ unless( $readcursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readcursor) 82 392 474
96 # Beginning of the bounce message or message/delivery-status part
97 82 ▶ $readcursor |= $indicators->{'deliverystatus'} if index($e, $startingof->{'message'}->[0]) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, $startingof->{"message"}[0]) == 0 32 50 82
98 82 next;
99 }
100 392 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $statuspart == 1;
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 or $statuspart == 1 0 392 392
Condition33%1/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $statuspart == 1
l!l&&r!l&&!r
00392
MC/DC0%0/2
($readcursor & $indicators->{"deliverystatus"}) == 0 or $statuspart == 1
($readcursor & $indicators->{"deliverystatus"}) == 0 $statuspart == 1
Truth table33%1/3
A or B
A= ($readcursor & $indicators->{"deliverystatus"}) == 0B= $statuspart == 1
ABresult
1X1
011
000
101  
102 392 ▶ if( $connvalues == scalar(keys %$connheader) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($connvalues == scalar keys %$connheader) { } 264 128 392
103 # did not reach the following recipient(s):
104 #
105 # kijitora@example.co.jp on Thu, 29 Apr 2007 16:51:51 -0500
106 # The recipient name is not recognized
107 # The MTS-ID of the original message is: c=jp;a= ;p=neko
108 # ;l=EXCHANGE000000000000000000
109 # MSEXCH:IMS:KIJITORA CAT:EXAMPLE:EXCHANGE 0 (000C05A6) Unknown Recipient
110 # mikeneko@example.co.jp on Thu, 29 Apr 2007 16:51:51 -0500
111 # The recipient name is not recognized
112 # The MTS-ID of the original message is: c=jp;a= ;p=neko
113 # ;l=EXCHANGE000000000000000000
114 # MSEXCH:IMS:KIJITORA CAT:EXAMPLE:EXCHANGE 0 (000C05A6) Unknown Recipient
115 264 $v = $dscontents->[-1];
116  
117 264 ▶ if( Sisimai::String->aligned(\$e, ['@', ' on ']) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ('Sisimai::String'->aligned(\$e, ['@', ' on '])) { } 37 227 264
elsif (index($e, ' ') == 0 and index($e, 'MSEXCH:') > 0) { } 37 190 227
118 # kijitora@example.co.jp on Thu, 29 Apr 2007 16:51:51 -0500
119 # kijitora@example.com on 4/29/99 9:19:59 AM
120 37 ▶ if( $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 5 32 37
121 # There are multiple recipient addresses in the message body.
122 5 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
123 5 $v = $dscontents->[-1];
124 }
125  
126 37 ▶ my $p1 = index(lc $e, 'smtp='); $p1 = $p1 == -1 ? 0 : $p1 + 5;
Branch: 1 branch
BranchTrueFalseTotal
$p1 == -1 ? : 37 0 37
127 37 my $p2 = index($e, ' on ') + 1;
128 37 $v->{'recipient'} = Sisimai::Address->s3s4(substr($e, $p1, $p2));
129 37 $v->{'msexch'} = 0;
130 37 $recipients++;
131  
132 ▶ } elsif( index($e, ' ') == 0 && index($e, 'MSEXCH:') > 0 ) {
Condition100%3/3
index($e, " ") == 0 and index($e, "MSEXCH:") > 0
!ll&&!rl&&r
1335737
MC/DC100%2/2
index($e, " ") == 0 and index($e, "MSEXCH:") > 0
index($e, " ") == 0 index($e, "MSEXCH:") > 0
Truth table100%3/3
A and B
A= index($e, " ") == 0B= index($e, "MSEXCH:") > 0
ABresult
0X0
100
111
133 # MSEXCH:IMS:KIJITORA CAT:EXAMPLE:EXCHANGE 0 (000C05A6) Unknown Recipient
134 37 $v->{'diagnosis'} .= substr($e, index($e, 'MSEXCH:'),);
135  
136 } else {
137 190 ▶ next if $v->{'msexch'};
Branch: 1 branch
BranchTrueFalseTotal
if $v->{"msexch"} 0 190 190
138 190 ▶ if( index($v->{'diagnosis'}, 'MSEXCH:') == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($v->{'diagnosis'}, 'MSEXCH:') == 0) { } 17 173 190
139 # Continued from MEEXCH in the previous line
140 17 $v->{'msexch'} = 1;
141 17 $v->{'diagnosis'} .= ' '.$e;
142 17 $statuspart = 1;
143  
144 } else {
145 # Error message in the body part
146 173 $v->{'alterrors'} .= ' '.$e;
147 }
148 }
149 } else {
150 # Your message
151 #
152 # To: shironeko@example.jp
153 # Subject: ...
154 # Sent: Thu, 29 Apr 2010 18:14:35 +0000
155 #
156 128 ▶ if( index($e, ' To: ') == 0 || index($e, ' To: ') == 0 ) {
Branch: 3 branches
BranchTrueFalseTotal
if (index($e, ' To: ') == 0 or index($e, ' To: ') == 0) { } 32 96 128
elsif (index($e, ' Subject: ') == 0 or index($e, ' Subject: ') == 0) { } 32 64 96
elsif (index($e, ' Sent: ') == 0 or index($e, ' Sent: ') == 0) { } 32 32 64
Condition100%3/3
index($e, " To: ") == 0 or index($e, " To: ") == 0
l!l&&r!l&&!r
27596
MC/DC100%2/2
index($e, " To: ") == 0 or index($e, " To: ") == 0
index($e, " To: ") == 0 index($e, " To: ") == 0
Truth table100%3/3
A or B
A= index($e, " To: ") == 0B= index($e, " To: ") == 0
ABresult
1X1
011
000
157 # To: shironeko@example.jp
158 32 ▶ next if $connheader->{'to'};
Branch: 1 branch
BranchTrueFalseTotal
if $connheader->{"to"} 0 32 32
159 32 $connheader->{'to'} = substr($e, rindex($e, ' ') + 1,);
160 32 $connvalues++;
161  
162 ▶ } elsif( index($e, ' Subject: ') == 0 || index($e, ' Subject: ') == 0 ) {
Condition100%3/3
index($e, " Subject: ") == 0 or index($e, " Subject: ") == 0
l!l&&r!l&&!r
52764
MC/DC100%2/2
index($e, " Subject: ") == 0 or index($e, " Subject: ") == 0
index($e, " Subject: ") == 0 index($e, " Subject: ") == 0
Truth table100%3/3
A or B
A= index($e, " Subject: ") == 0B= index($e, " Subject: ") == 0
ABresult
1X1
011
000
163 # Subject: ...
164 32 ▶ next if length $connheader->{'subject'};
Branch: 1 branch
BranchTrueFalseTotal
if length $connheader->{"subject"} 0 32 32
165 32 $connheader->{'subject'} = substr($e, rindex($e, ' ') + 1,);
166 32 $connvalues++;
167  
168 ▶ } elsif( index($e, ' Sent: ') == 0 || index($e, ' Sent: ') == 0 ) {
Condition100%3/3
index($e, " Sent: ") == 0 or index($e, " Sent: ") == 0
l!l&&r!l&&!r
27532
MC/DC100%2/2
index($e, " Sent: ") == 0 or index($e, " Sent: ") == 0
index($e, " Sent: ") == 0 index($e, " Sent: ") == 0
Truth table100%3/3
A or B
A= index($e, " Sent: ") == 0B= index($e, " Sent: ") == 0
ABresult
1X1
011
000
169 # Sent: Thu, 29 Apr 2010 18:14:35 +0000
170 # Sent: 4/29/99 9:19:59 AM
171 32 ▶ next if $connheader->{'date'};
Branch: 1 branch
BranchTrueFalseTotal
if $connheader->{"date"} 0 32 32
172 32 $connheader->{'date'} = substr($e, index($e, ':') + 2,);
173 32 $connvalues++;
174 }
175 } # End of error message part
176 }
177 32 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 0 32 32
178  
179 32 for my $e ( @$dscontents ) {
180 37 delete $e->{'msexch'};
181  
182 37 ▶ if( index($e->{'diagnosis'}, 'MSEXCH:') == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($e->{"diagnosis"}, "MSEXCH:") == 0) 37 0 37
183 # MSEXCH:IMS:KIJITORA CAT:EXAMPLE:EXCHANGE 0 (000C05A6) Unknown Recipient
184 37 my $capturedcode = substr($e->{'diagnosis'}, index($e->{'diagnosis'}, '(') + 1, 8);
185 37 my $errormessage = substr($e->{'diagnosis'}, index($e->{'diagnosis'}, ')') + 1, );
186  
187 37 for my $r ( keys %$errorcodes ) {
188 # Find captured code from the error code table
189 183 ▶ next unless grep { $capturedcode eq $_ } $errorcodes->{ $r }->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$capturedcode eq $_;} @{$$errorcodes{$r}} 151 32 183
190 32 $e->{'reason'} = $r;
191 32 ▶ $e->{'status'} = Sisimai::SMTP::Status->code($r) || '';
Condition50%1/2
'Sisimai::SMTP::Status'->code($r) || ''
l!l
320
MC/DC0%0/1
'Sisimai::SMTP::Status'->code($r) || ''
'Sisimai::SMTP::Status'->code($r)
Truth table50%1/2
A
A= 'Sisimai::SMTP::Status'->code($r)
Aresult
11
00
192 32 last;
193 }
194 37 $e->{'diagnosis'} = $errormessage;
195 }
196  
197 # Could not detect the reason from the value of "diagnosis", copy alternative error message
198 37 ▶ next if $e->{'reason'};
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"reason"} 32 5 37
199 5 ▶ next unless exists $e->{'alterrors'} && length $e->{'alterrors'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $e->{"alterrors"} and length $e->{"alterrors"} 0 5 5
Condition33%1/3
exists $e->{"alterrors"} and length $e->{"alterrors"}
!ll&&!rl&&r
005
MC/DC0%0/2
exists $e->{"alterrors"} and length $e->{"alterrors"}
exists $e->{"alterrors"} length $e->{"alterrors"}
Truth table33%1/3
A and B
A= exists $e->{"alterrors"}B= length $e->{"alterrors"}
ABresult
0X0
100
111
200  
201 5 $e->{'diagnosis'} = $e->{'alterrors'}.' '.$e->{'diagnosis'};
202 5 delete $e->{'alterrors'};
203 }
204  
205 32 ▶ unless( length $emailparts->[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $emailparts->[1]) 12 20 32
206 # When original message does not included in the bounce message
207 12 $emailparts->[1] .= sprintf("From: %s\n", $connheader->{'to'});
208 12 $emailparts->[1] .= sprintf("Date: %s\n", $connheader->{'date'});
209 12 $emailparts->[1] .= sprintf("Subject: %s\n", $connheader->{'subject'});
210 }
211 32 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
212 }
213  
214 43 1;
215 __END__
« Sisimai/Lhost/Domino.pm ↑ Summary Sisimai/Lhost/Verizon.pm »