Sisimai/Lhost/Mimecast.pm

filter: Statementstmt 96.6% 58 / 60 Branchbran 72.2% 26 / 36 Conditioncond 61.9% 13 / 21 MC/DCmcdc 36.3% 4 / 11 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 80.1% 109 / 136 CC 31 SCAR 34.9
CC
31
Cov
83%
inquire
37.8
BEGIN
1.0
BEGIN
1.0
CRAP 32.7
« Sisimai/Lhost/Exchange2007.pm ↑ Summary Sisimai/Lhost/AmazonSES.pm »
1 package Sisimai::Lhost::Mimecast;
2 3 ▶use parent 'Sisimai::Lhost';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶sub description { 'Mimecast' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
8 12 ▶sub inquire {
Subroutine inquire: called CC=31 SCAR=36.3
Pod documented
9 # Detect an error from Mimecast: https://www.mimecast.com/
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 v5.5.0
15 12 my $class = shift;
16 12 ▶ my $mhead = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
111
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
17 11 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
101
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18  
19 # Subject: [Postmaster] Email Delivery Failure
20 10 ▶ my $match = 0; $match ||= 1 if index($mhead->{'subject'}, 'Email Delivery Failure') > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($mhead->{"subject"}, "Email Delivery Failure") != -1 10 0 10
Condition50%1/2
$match ||= 1
l!l
010
MC/DC0%0/1
$match ||= 1
$match
Truth table50%1/2
A
A= $match
Aresult
11
00
21 10 ▶ if( defined $mhead->{'message-id'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mhead->{"message-id"}) 10 0 10
22 # Message-Id: <0123456789-1102117314000@us-mta-25.us.mimecast.lan>
23 10 ▶ $match ||= 1 if index($mhead->{'message-id'}, '.mimecast.lan>') > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($mhead->{"message-id"}, ".mimecast.lan>") != -1 10 0 10
Condition50%1/2
$match ||= 1
l!l
100
MC/DC0%0/1
$match ||= 1
$match
Truth table50%1/2
A
A= $match
Aresult
11
00
24 }
25 10 ▶ return undef unless $match;
Branch: 1 branch
BranchTrueFalseTotal
unless $match 0 10 10
26  
27 10 state $indicators = __PACKAGE__->INDICATORS;
28 10 state $boundaries = ['Content-Type: :message/rfc822']; # No such line in lhost-mimecast-*
29 10 state $startingof = {'message' => ['-- ']};
30  
31 10 ▶ my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries) // return undef; return undef unless $emailparts->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $emailparts->[0] 0 10 10
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
100
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
32 10 my $fieldtable = Sisimai::RFC1894->FIELDTABLE;
33 10 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef;
34 10 my $permessage = {}; # (Hash) Store values of each Per-Message field
35 10 my $readcursor = 0; # (Integer) Points the current cursor position
36 10 my $recipients = 0; # (Integer) The number of 'Final-Recipient' header
37  
38 10 for my $e ( split("\n", $emailparts->[0]) ) {
39 # Read error messages and delivery status lines from the head of the email to the previous
40 # line of the beginning of the original message.
41 240 ▶ unless( $readcursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readcursor) 35 205 240
42 # Beginning of the bounce message or message/delivery-status part
43 35 ▶ $readcursor |= $indicators->{'deliverystatus'} if index($e, $startingof->{'message'}->[0]) > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, $startingof->{"message"}[0]) != -1 10 25 35
44 }
45 240 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq "" 75 165 240
Condition100%3/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
l!l&&r!l&&!r
2550165
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
46  
47 165 $v = $dscontents->[-1];
48 165 ▶ if( index($e, '-- ') == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($e, '-- ') == 0) { } 30 135 165
49 # An email that you attempted to send to the following address could not be delivered:
50 # -- sabineko@neko.ef.example.org
51 30 ▶ my $cv = substr($e, 3,); if( index($cv, " ") < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($cv, ' ') == -1) { } 10 20 30
52 # -- sotoneko@cat.example.com
53 10 ▶ if( $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 0 10 10
54 # There are multiple recipient addresses in the message body.
55 0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
56 0 $v = $dscontents->[-1];
57 }
58 10 $v->{'recipient'} = Sisimai::Address->s3s4($cv);
59 10 $recipients++;
60  
61 } else {
62 # Deal each line begins with "-- " as an error message.
63 # The problem appears to be :
64 # -- Recipient email address is possibly incorrect
65 # Additional information follows :
66 # -- 5.4.1 Recipient address rejected: Access denied.
67 20 $v->{'diagnosis'} .= $cv.' ';
68 }
69 } else {
70 # Lines after Content-Type: message/delivery-status
71 135 ▶ if( my $f = Sisimai::RFC1894->match($e) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = "Sisimai::RFC1894"->match($e)) 40 95 135
72 # $e matched with any field defined in RFC3464
73 40 ▶ next unless my $o = Sisimai::RFC1894->field($e);
Branch: 1 branch
BranchTrueFalseTotal
unless my $o = "Sisimai::RFC1894"->field($e) 0 40 40
74  
75 40 ▶ if( $o->[3] eq 'code' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->[3] eq 'code') { } 5 35 40
76 # Diagnostic-Code: SMTP; 550 5.1.1 <userunknown@example.jp>... User Unknown
77 5 $v->{'spec'} = $o->[1];
78 5 $v->{'diagnosis'} = $o->[2];
79  
80 } else {
81 # Other DSN fields defined in RFC3464
82 35 ▶ next unless exists $fieldtable->{ $o->[0] };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$fieldtable{$o->[0]} 0 35 35
83 35 ▶ 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 0 35 35
Condition66%2/3
$o->[3] eq "host" and "Sisimai::RFC1123"->is_internethost($o->[2]) == 0
!ll&&!rl&&r
3050
MC/DC0%0/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 table66%2/3
A and B
A= $o->[3] eq "host"B= "Sisimai::RFC1123"->is_internethost($o->[2]) == 0
ABresult
0X0
100
111
84 35 $v->{ $fieldtable->{ $o->[0] } } = $o->[2];
85  
86 35 ▶ next unless $f == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $f == 1 25 10 35
87 10 $permessage->{ $fieldtable->{ $o->[0] } } = $o->[2];
88 }
89 }
90 }
91 }
92 10 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 0 10 10
93  
94 10 for my $e ( @$dscontents ) {
95 # Set default values if each value is empty.
96 10 ▶ $e->{ $_ } ||= $permessage->{ $_ } || '' for keys %$permessage;
Condition20%1/5
$e->{$_} ||= $permessage->{$_} || ""
l!l&&r!l&&!r
1000
$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
97 }
98 10 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
99 }
100  
101 3 1;
102 __END__
« Sisimai/Lhost/Exchange2007.pm ↑ Summary Sisimai/Lhost/AmazonSES.pm »