Sisimai/Fact.pm

filter: Statementstmt 98.9% 295 / 298 Branchbran 85.7% 132 / 154 Conditioncond 74.8% 107 / 143 MC/DCmcdc 49.3% 39 / 79 Subroutinesub 100% 24 / 24 Podpod 50.0% 2 / 4 totaltotal 85.3% 599 / 702 CC 152 SCAR 50.1
CC
152
Cov
90%
rise
180.9
maketoken
5.0
damn
3.0
CRAP 149.2
↑ Summary Sisimai/Lhost/Exim.pm »
1 package Sisimai::Fact;
2 86 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 86 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 86 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 86 ▶use Digest::SHA;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 86 ▶use Sisimai::Eb;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 86 ▶use Sisimai::Message;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 86 ▶use Sisimai::RFC791;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 86 ▶use Sisimai::RFC1123;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 86 ▶use Sisimai::RFC1894;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 86 ▶use Sisimai::RFC5322;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 86 ▶use Sisimai::Reason;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 86 ▶use Sisimai::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 86 ▶use Sisimai::DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 86 ▶use Sisimai::Time;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 86 ▶use Sisimai::SMTP::Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 86 ▶use Sisimai::SMTP::Failure;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 86 ▶use Sisimai::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 86 ▶use Sisimai::Rhost;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 86 ▶use Sisimai::LDA;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 86 ▶use Class::Accessor::Lite ('new' => 0, 'rw' => [
Subroutine BEGIN: called CC=1 SCAR=0.0
22 'action', # [String] The value of Action: header
23 'addresser', # [Sisimai::Address] From address
24 'alias', # [String] Alias of the recipient address
25 'bogus', # [Integer] EXPERIMENTAL
26 'catch', # [?] Results generated by hook method
27 'command', # [String] The last SMTP command
28 'decodedby', # [String] MTA Module name since v5.2.0
29 'deliverystatus', # [String] Delivery Status(DSN)
30 'destination', # [String] The domain part of the "recipient"
31 'diagnosticcode', # [String] Diagnostic-Code: Header
32 'diagnostictype', # [String] The 1st part of Diagnostic-Code: Header
33 'feedbackid', # [String] The value of Feedback-ID: header of the original message
34 'feedbacktype', # [String] Feedback Type
35 'hardbounce', # [Integer] 1 = Hard bounce, 0 = Is not a hard bounce
36 'lhost', # [String] local host name/Local MTA
37 'listid', # [String] List-Id header of each ML
38 'messageid', # [String] Message-Id: header
39 'origin', # [String] Email path as a data source
40 'reason', # [String] Bounce reason
41 'recipient', # [Sisimai::Address] Recipient address which bounced
42 'replycode', # [String] SMTP Reply Code
43 'rhost', # [String] Remote host name/Remote MTA
44 'senderdomain', # [String] The domain part of the "addresser"
45 'subject', # [String] UTF-8 Subject text
46 'timestamp', # [Sisimai::Time] Date: header in the original message
47 'timezoneoffset', # [Integer] Time zone offset(seconds)
48 'token', # [String] Message token/MD5 Hex digest value
49 'toxic', # [Integer] EXPERIMENTAL
50 86 ]);
51  
52 3522 ▶sub rise {
Subroutine rise: called CC=144 SCAR=52.0
Pod documented
53 # Constructor of Sisimai::Fact
54 # @param [Hash] argvs
55 # @options argvs [String] data Entire email message
56 # @options argvs [Integer] delivered 1 if the result which has "delivered" reason is included
57 # @options argvs [Integer] vacation 1 if the result which has "vacation" reason is included
58 # @options argvs [Code] hook Code reference to callback method
59 # @options argvs [String] origin Path to the original email file
60 # @return [Array] Array of Sisimai::Fact objects
61 3522 my $class = shift;
62 3522 ▶ my $argvs = shift || return undef;
Condition100%2/2
shift() || (return undef)
l!l
35211
MC/DC100%1/1
shift() || (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
63 3521 ▶ die ' ***error: Sisimai::Fact->rise receives only a HASH reference as an argument' unless ref $argvs eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $argvs eq "HASH" 0 3521 3521
64  
65 3521 ▶ my $email = $argvs->{'data'} || return undef;
Condition100%2/2
$argvs->{'data'} || (return undef)
l!l
35201
MC/DC100%1/1
$argvs->{'data'} || (return undef)
$argvs->{'data'}
Truth table100%2/2
A
A= $argvs->{'data'}
Aresult
11
00
66 3520 my $args1 = {'data' => $email, 'hook' => $argvs->{'hook'}};
67 3520 ▶ my $mesg1 = Sisimai::Message->rise($args1) || return undef;
Condition100%2/2
'Sisimai::Message'->rise($args1) || (return undef)
l!l
347842
MC/DC100%1/1
'Sisimai::Message'->rise($args1) || (return undef)
'Sisimai::Message'->rise($args1)
Truth table100%2/2
A
A= 'Sisimai::Message'->rise($args1)
Aresult
11
00
68  
69 3478 ▶ return undef unless $mesg1->{'ds'};
Branch: 1 branch
BranchTrueFalseTotal
unless $mesg1->{"ds"} 0 3478 3478
70 3478 ▶ return undef unless $mesg1->{'rfc822'};
Branch: 1 branch
BranchTrueFalseTotal
unless $mesg1->{"rfc822"} 0 3478 3478
71  
72 3478 state $retryindex = Sisimai::Reason->retry;
73 3478 state $rfc822head = Sisimai::RFC5322::HEADERTABLE;
74 3478 state $actionlist = {
75 $Sisimai::Eb::AeSTAY => 1, $Sisimai::Eb::AeSENT => 1, $Sisimai::Eb::AeEXPN => 1,
76 $Sisimai::Eb::AeFAIL => 1, $Sisimai::Eb::AePASS => 1,
77 };
78 3478 my $rfc822data = $mesg1->{'rfc822'};
79 3478 my $listoffact = [];
80  
81 3478 RISEOF: for my $e ( $mesg1->{'ds'}->@* ) {
82 # Create parameters
83 3665 ▶ next if length $e->{'recipient'} < 5;
Branch: 1 branch
BranchTrueFalseTotal
if length $e->{"recipient"} < 5 0 3665 3665
84 3665 ▶ next if ! $argvs->{'delivered'} && index($e->{'status'}, '2.') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if not $argvs->{"delivered"} and index($e->{"status"}, "2.") == 0 12 3653 3665
Condition100%3/3
not $argvs->{"delivered"} and index($e->{"status"}, "2.") == 0
!ll&&!rl&&r
704294912
MC/DC100%2/2
not $argvs->{"delivered"} and index($e->{"status"}, "2.") == 0
not $argvs->{"delivered"} index($e->{"status"}, "2.") == 0
Truth table100%3/3
not(A) and B
A= not $argvs->{"delivered"}B= index($e->{"status"}, "2.") == 0
ABresult
0X0
100
111
85 3653 ▶ next if ! $argvs->{'vacation'} && $e->{'reason'} eq $Sisimai::Eb::ReAWAY;
Branch: 1 branch
BranchTrueFalseTotal
if not $argvs->{"vacation"} and $e->{"reason"} eq $Sisimai::Eb::ReAWAY 21 3632 3653
Condition100%3/3
not $argvs->{"vacation"} and $e->{"reason"} eq $Sisimai::Eb::ReAWAY
!ll&&!rl&&r
664296821
MC/DC100%2/2
not $argvs->{"vacation"} and $e->{"reason"} eq $Sisimai::Eb::ReAWAY
not $argvs->{"vacation"} $e->{"reason"} eq $Sisimai::Eb::ReAWAY
Truth table100%3/3
not(A) and B
A= not $argvs->{"vacation"}B= $e->{"reason"} eq $Sisimai::Eb::ReAWAY
ABresult
0X0
100
111
86  
87 3632 my $thing = {}; # To be blessed and pushed into the array above at the end of the loop
88 my $piece = {
89 'action' => $e->{'action'} // '',
90 'alias' => $e->{'alias'} // '',
91 'catch' => $mesg1->{'catch'} // undef,
92 'decodedby' => $e->{'agent'} // '',
93 'deliverystatus' => $e->{'status'} // '',
94 'diagnosticcode' => $e->{'diagnosis'} // '',
95 'diagnostictype' => $e->{'spec'} // '',
96 'feedbacktype' => $e->{'feedbacktype'} // '',
97 'hardbounce' => 0,
98 'lhost' => $e->{'lhost'} // '',
99 'origin' => $argvs->{'origin'} // '',
100 'reason' => $e->{'reason'} // '',
101 'recipient' => $e->{'recipient'} // '',
102 'replycode' => $e->{'replycode'} // '',
103 'rhost' => $e->{'rhost'} // '',
104 3632 ▶ 'command' => $e->{'command'} // '',
Condition60%18/30
$e->{"action"} // ""
l!l
36320
$e->{"alias"} // ""
l!l
36320
$mesg1->{"catch"} // undef
l!l
7352897
$e->{"agent"} // ""
l!l
36320
$e->{"status"} // ""
l!l
36320
$e->{"diagnosis"} // ""
l!l
36320
$e->{"spec"} // ""
l!l
36320
$e->{"feedbacktype"} // ""
l!l
36320
$e->{"lhost"} // ""
l!l
36266
$argvs->{"origin"} // ""
l!l
36302
$e->{"reason"} // ""
l!l
36320
$e->{"recipient"} // ""
l!l
36320
$e->{"replycode"} // ""
l!l
36320
$e->{"rhost"} // ""
l!l
36320
$e->{"command"} // ""
l!l
36320
MC/DC0%0/1
$e->{"action"} // ""
$e->{"action"}
MC/DC0%0/1
$e->{"alias"} // ""
$e->{"alias"}
MC/DC100%1/1
$mesg1->{"catch"} // undef
$mesg1->{"catch"}
MC/DC0%0/1
$e->{"agent"} // ""
$e->{"agent"}
MC/DC0%0/1
$e->{"status"} // ""
$e->{"status"}
MC/DC0%0/1
$e->{"diagnosis"} // ""
$e->{"diagnosis"}
MC/DC0%0/1
$e->{"spec"} // ""
$e->{"spec"}
MC/DC0%0/1
$e->{"feedbacktype"} // ""
$e->{"feedbacktype"}
MC/DC100%1/1
$e->{"lhost"} // ""
$e->{"lhost"}
MC/DC100%1/1
$argvs->{"origin"} // ""
$argvs->{"origin"}
MC/DC0%0/1
$e->{"reason"} // ""
$e->{"reason"}
MC/DC0%0/1
$e->{"recipient"} // ""
$e->{"recipient"}
MC/DC0%0/1
$e->{"replycode"} // ""
$e->{"replycode"}
MC/DC0%0/1
$e->{"rhost"} // ""
$e->{"rhost"}
MC/DC0%0/1
$e->{"command"} // ""
$e->{"command"}
Truth table50%1/2
A
A= $e->{"action"}
Aresult
11
00
Truth table50%1/2
A
A= $e->{"alias"}
Aresult
11
00
Truth table100%2/2
A
A= $mesg1->{"catch"}
Aresult
11
00
Truth table50%1/2
A
A= $e->{"agent"}
Aresult
11
00
Truth table50%1/2
A
A= $e->{"status"}
Aresult
11
00
Truth table50%1/2
A
A= $e->{"diagnosis"}
Aresult
11
00
Truth table50%1/2
A
A= $e->{"spec"}
Aresult
11
00
Truth table50%1/2
A
A= $e->{"feedbacktype"}
Aresult
11
00
Truth table100%2/2
A
A= $e->{"lhost"}
Aresult
11
00
Truth table100%2/2
A
A= $argvs->{"origin"}
Aresult
11
00
Truth table50%1/2
A
A= $e->{"reason"}
Aresult
11
00
Truth table50%1/2
A
A= $e->{"recipient"}
Aresult
11
00
Truth table50%1/2
A
A= $e->{"replycode"}
Aresult
11
00
Truth table50%1/2
A
A= $e->{"rhost"}
Aresult
11
00
Truth table50%1/2
A
A= $e->{"command"}
Aresult
11
00
105 };
106  
107 ADDRESSER: {
108 # Detect an email address from message/rfc822 part
109 3632 my $j = [];
110 3632 for my $f ( $rfc822head->{'addresser'}->@* ) {
111 # Check each header in message/rfc822 part
112 5479 ▶ next unless exists $rfc822data->{ $f };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rfc822data->{$f} 2093 3386 5479
113 3386 ▶ next unless $rfc822data->{ $f };
Branch: 1 branch
BranchTrueFalseTotal
unless $rfc822data->{$f} 0 3386 3386
114  
115 3386 ▶ $j = Sisimai::Address->find($rfc822data->{ $f }) || next;
Condition50%1/2
'Sisimai::Address'->find($rfc822data->{$f}) || (next)
l!l
33860
MC/DC0%0/1
'Sisimai::Address'->find($rfc822data->{$f}) || (next)
'Sisimai::Address'->find($rfc822data->{$f})
Truth table50%1/2
A
A= 'Sisimai::Address'->find($rfc822data->{$f})
Aresult
11
00
116 3386 $piece->{'addresser'} = shift @$j;
117 3386 last ADDRESSER;
118 }
119  
120 # Fallback: Get the sender address from the header of the bounced email if the address
121 # is not set at the loop above.
122 246 ▶ $j = Sisimai::Address->find($mesg1->{'header'}->{'to'}) || [];
Condition50%1/2
'Sisimai::Address'->find($mesg1->{'header'}{'to'}) || []
l!l
2460
MC/DC0%0/1
'Sisimai::Address'->find($mesg1->{'header'}{'to'}) || []
'Sisimai::Address'->find($mesg1->{'header'}{'to'})
Truth table50%1/2
A
A= 'Sisimai::Address'->find($mesg1->{'header'}{'to'})
Aresult
11
00
123 246 $piece->{'addresser'} = shift @$j;
124 }
125 3632 ▶ next RISEOF unless $piece->{'addresser'};
Branch: 1 branch
BranchTrueFalseTotal
unless $piece->{"addresser"} 0 3632 3632
126  
127 TIMESTAMP: {
128 # Convert from a time stamp or a date string to a machine time.
129 3632 my $datestring = undef;
130 3632 my $zoneoffset = 0;
131 3632 ▶ my @datevalues; push @datevalues, $e->{'date'} if $e->{'date'};
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"date"} 1900 1732 3632
132  
133 # Date information did not exist in message/delivery-status part,...
134 3632 for my $f ( $rfc822head->{'date'}->@* ) {
135 # Get the value of Date header or other date related header.
136 14528 ▶ next unless $rfc822data->{ $f };
Branch: 1 branch
BranchTrueFalseTotal
unless $rfc822data->{$f} 11336 3192 14528
137 3192 push @datevalues, $rfc822data->{ $f };
138 }
139  
140 # Set "date" getting from the value of "Date" in the bounce message
141 3632 ▶ push @datevalues, $mesg1->{'header'}->{'date'} if scalar(@datevalues) < 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @datevalues < 2 1846 1786 3632
142  
143 3632 ▶ while( my $v = shift @datevalues ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $v = shift @datevalues) 3632 0 3632
144 # Decode each date value in the array
145 3632 ▶ $datestring = Sisimai::DateTime->parse($v) || next;
Condition50%1/2
'Sisimai::DateTime'->parse($v) || (next)
l!l
36320
MC/DC0%0/1
'Sisimai::DateTime'->parse($v) || (next)
'Sisimai::DateTime'->parse($v)
Truth table50%1/2
A
A= 'Sisimai::DateTime'->parse($v)
Aresult
11
00
146  
147 3632 ▶ if( $datestring =~ /\A(.+)[ ]+([-+]\d{4})\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($datestring =~ /\A(.+)[ ]+([-+]\d{4})\z/u) 3632 0 3632
148 # Get the value of timezone offset from $datestring: Wed, 26 Feb 2014 06:05:48 -0500
149 3632 $datestring = $1;
150 3632 $zoneoffset = Sisimai::DateTime->tz2second($2);
151 3632 $piece->{'timezoneoffset'} = $2;
152 }
153 3632 ▶ last if $datestring;
Branch: 1 branch
BranchTrueFalseTotal
if $datestring 3632 0 3632
154 }
155  
156 3632 eval {
157 # Convert from the date string to an object then calculate time zone offset.
158 3632 my $t = Sisimai::Time->strptime($datestring, '%a, %d %b %Y %T');
159 3632 ▶ $piece->{'timestamp'} = ($t->epoch - $zoneoffset) // undef;
Condition50%1/2
$t->epoch - $zoneoffset // undef
l!l
36320
MC/DC0%0/1
$t->epoch - $zoneoffset // undef
$t->epoch - $zoneoffset
Truth table50%1/2
A
A= $t->epoch - $zoneoffset
Aresult
11
00
160 };
161 }
162 3632 ▶ next RISEOF unless defined $piece->{'timestamp'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $piece->{"timestamp"} 0 3632 3632
163  
164 RECEIVED: {
165 # Scan "Received:" header of the original message
166 3632 ▶ my $recv = $mesg1->{'header'}->{'received'} || [];
Condition50%1/2
$mesg1->{'header'}{'received'} || []
l!l
36320
MC/DC0%0/1
$mesg1->{'header'}{'received'} || []
$mesg1->{'header'}{'received'}
Truth table50%1/2
A
A= $mesg1->{'header'}{'received'}
Aresult
11
00
167 3632 ▶ unless( $piece->{'rhost'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($piece->{"rhost"}) 1680 1952 3632
168 # Try to pick a remote hostname from Received: headers of the bounce message
169 1680 my $ir = Sisimai::RFC1123->find($e->{'diagnosis'});
170 1680 ▶ $piece->{'rhost'} = $ir if Sisimai::RFC1123->is_internethost($ir);
Branch: 1 branch
BranchTrueFalseTotal
if "Sisimai::RFC1123"->is_internethost($ir) 421 1259 1680
171  
172 1680 ▶ unless( $piece->{'rhost'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($piece->{"rhost"}) 1259 421 1680
173 # The remote hostname in the error message did not exist or is not a valid
174 # internet hostname
175 1259 for my $re ( reverse @$recv ) {
176 # Check the Received: headers backwards and get a remote hostname
177 1973 ▶ last if $piece->{'rhost'};
Branch: 1 branch
BranchTrueFalseTotal
if $piece->{"rhost"} 444 1529 1973
178 1529 my $cv = Sisimai::RFC5322->received($re)->[0];
179 1529 ▶ next unless Sisimai::RFC1123->is_internethost($cv);
Branch: 1 branch
BranchTrueFalseTotal
unless "Sisimai::RFC1123"->is_internethost($cv) 418 1111 1529
180 1111 $piece->{'rhost'} = $cv;
181 }
182 }
183 }
184 3632 ▶ $piece->{'lhost'} = '' if $piece->{'lhost'} eq $piece->{'rhost'};
Branch: 1 branch
BranchTrueFalseTotal
if $piece->{"lhost"} eq $piece->{"rhost"} 286 3346 3632
185  
186 3632 ▶ unless( $piece->{'lhost'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($piece->{"lhost"}) 1593 2039 3632
187 # Try to pick a local hostname from Received: headers of the bounce message
188 1593 for my $le ( @$recv ) {
189 # Check the Received: headers forwards and get a local hostname
190 1786 my $cv = Sisimai::RFC5322->received($le)->[0];
191 1786 ▶ next unless Sisimai::RFC1123->is_internethost($cv);
Branch: 1 branch
BranchTrueFalseTotal
unless "Sisimai::RFC1123"->is_internethost($cv) 599 1187 1786
192 1187 $piece->{'lhost'} = $cv; last;
193 }
194 }
195  
196 3632 for my $v ('rhost', 'lhost') {
197 # Check and rewrite each host name
198 7264 ▶ next unless length $piece->{ $v };
Branch: 1 branch
BranchTrueFalseTotal
unless length $piece->{$v} 554 6710 7264
199 6710 ▶ if( index($piece->{ $v }, '@') > -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($piece->{$v}, "\@") != -1) 0 6710 6710
200 # Use the domain part as a remote/local host when the value is an email address
201 0 $piece->{ $v } = (split('@', $piece->{ $v }))[-1];
202 }
203 6710 y/[]()\r//d, s/\A.+=// for $piece->{ $v }; # Remove [], (), \r, and strings before "="
204  
205 6710 ▶ if( index($piece->{ $v }, ' ') > -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($piece->{$v}, " ") != -1) 77 6633 6710
206 # Check a space character in each value and get the first hostname
207 77 my @ee = split(' ', $piece->{ $v });
208 77 for my $w ( @ee ) {
209 # get a hostname from the string like "127.0.0.1 x109-20.example.com 192.0.2.20"
210 # or "mx.sp.example.jp 192.0.2.135"
211 77 ▶ next if Sisimai::RFC791->is_ipv4address($w);
Branch: 1 branch
BranchTrueFalseTotal
if "Sisimai::RFC791"->is_ipv4address($w) 0 77 77
212 77 $piece->{ $v } = $w; last;
213 }
214 77 ▶ $piece->{ $v } = $ee[0] if index($piece->{ $v }, ' ') > 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($piece->{$v}, " ") > 0 0 77 77
215 }
216 6710 ▶ chop $piece->{ $v } if substr($piece->{ $v }, -1, 1) eq '.'; # Remove "." at the end of the value
Branch: 1 branch
BranchTrueFalseTotal
if substr($piece->{$v}, -1, 1) eq "." 54 6656 6710
217 }
218 }
219  
220 ID_HEADERS: {
221 # Message-ID:, List-ID: headers of the original message
222 3632 my $p0 = 0;
223 3632 my $p1 = 0;
224 3632 ▶ if( Sisimai::String->aligned(\$rfc822data->{'message-id'}, ['<', '@', '>']) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('Sisimai::String'->aligned(\$rfc822data->{'message-id'}, ['<', '@', '>'])) { } 3100 532 3632
225 # https://www.rfc-editor.org/rfc/rfc5322#section-3.6.4
226 # Leave only string inside of angle brackets(<>)
227 3100 $p0 = index($rfc822data->{'message-id'}, '<') + 1;
228 3100 $p1 = index($rfc822data->{'message-id'}, '>');
229 3100 $piece->{'messageid'} = substr($rfc822data->{'message-id'}, $p0, $p1 - $p0);
230  
231 } else {
232 # Invalid value of the Message-Id: field
233 532 $piece->{'messageid'} = '';
234 }
235  
236 3632 ▶ if( Sisimai::String->aligned(\$rfc822data->{'list-id'}, ['<', '.', '>']) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ('Sisimai::String'->aligned(\$rfc822data->{'list-id'}, ['<', '.', '>'])) { } 27 3605 3632
237 # https://www.rfc-editor.org/rfc/rfc2919
238 # Get the value of List-Id header: "List name <list-id@example.org>"
239 27 $p0 = index($rfc822data->{'list-id'}, '<') + 1;
240 27 $p1 = index($rfc822data->{'list-id'}, '>');
241 27 $piece->{'listid'} = substr($rfc822data->{'list-id'}, $p0, $p1 - $p0);
242  
243 } else {
244 # Invalid value of the List-Id: field
245 3605 $piece->{'listid'} = '';
246 }
247 }
248  
249 DIAGNOSTICCODE: {
250 # Cleanup the value of "Diagnostic-Code:" header
251 3632 ▶ last unless length $piece->{'diagnosticcode'};
Branch: 1 branch
BranchTrueFalseTotal
unless length $piece->{"diagnosticcode"} 10 3622 3632
252  
253 # Get an SMTP Reply Code and an SMTP Enhanced Status Code
254 3622 ▶ chop $piece->{'diagnosticcode'} if substr($piece->{'diagnosticcode'}, -1, 1) eq "\r";
Branch: 1 branch
BranchTrueFalseTotal
if substr($piece->{"diagnosticcode"}, -1, 1) eq "\r" 0 3622 3622
255  
256 3622 ▶ my $cs = Sisimai::SMTP::Status->find($piece->{'diagnosticcode'}) || '';
Condition100%2/2
'Sisimai::SMTP::Status'->find($piece->{'diagnosticcode'}) || ''
l!l
18851737
MC/DC100%1/1
'Sisimai::SMTP::Status'->find($piece->{'diagnosticcode'}) || ''
'Sisimai::SMTP::Status'->find($piece->{'diagnosticcode'})
Truth table100%2/2
A
A= 'Sisimai::SMTP::Status'->find($piece->{'diagnosticcode'})
Aresult
11
00
257 3622 ▶ my $cr = Sisimai::SMTP::Reply->find( $piece->{'diagnosticcode'}, $cs) || '';
Condition100%2/2
'Sisimai::SMTP::Reply'->find($piece->{'diagnosticcode'}, $cs) || ''
l!l
26021020
MC/DC100%1/1
'Sisimai::SMTP::Reply'->find($piece->{'diagnosticcode'}, $cs) || ''
'Sisimai::SMTP::Reply'->find($piece->{'diagnosticcode'}, $cs)
Truth table100%2/2
A
A= 'Sisimai::SMTP::Reply'->find($piece->{'diagnosticcode'}, $cs)
Aresult
11
00
258 3622 $piece->{'deliverystatus'} = Sisimai::SMTP::Status->prefer($piece->{'deliverystatus'}, $cs, $cr);
259  
260 3622 ▶ if( length $cr == 3 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $cr == 3) 2602 1020 3622
261 # There is an SMTP reply code in the error message
262 2602 ▶ $piece->{'replycode'} ||= $cr;
Condition66%2/3
$piece->{"replycode"} ||= $cr
l!l&&r!l&&!r
142311790
MC/DC0%0/2
$piece->{"replycode"} ||= $cr
$piece->{"replycode"} $cr
Truth table66%2/3
A ||= B
A= $piece->{"replycode"}B= $cr
ABresult
1X1
011
000
263  
264 2602 ▶ if( index($piece->{'diagnosticcode'}, $cr.'-') > -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($piece->{"diagnosticcode"}, $cr . '-') != -1) 207 2395 2602
265 # 550-5.7.1 [192.0.2.222] Our system has detected that this message is
266 # 550-5.7.1 likely unsolicited mail. To reduce the amount of spam sent to Gmail,
267 # 550-5.7.1 this message has been blocked. Please visit
268 # 550 5.7.1 https://support.google.com/mail/answer/188131 for more information.
269 #
270 # kijitora@example.co.uk
271 # host c.eu.example.com [192.0.2.3]
272 # SMTP error from remote mail server after end of data:
273 # 553-SPF (Sender Policy Framework) domain authentication
274 # 553-fail. Refer to the Troubleshooting page at
275 # 553-http://www.symanteccloud.com/troubleshooting for more
276 # 553 information. (#5.7.1)
277 207 for my $q ('-', ' ') {
278 # Remove strings: "550-5.7.1", and "550 5.7.1" from the error message
279 414 my $cx = sprintf("%s%s%s", $cr, $q, $cs);
280 414 my $p0 = index($piece->{'diagnosticcode'}, $cx);
281 414 ▶ while( $p0 > -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p0 > -1) 801 414 1215
282 # Remove strings like "550-5.7.1"
283 801 substr($piece->{'diagnosticcode'}, $p0, length $cx, '');
284 801 $p0 = index($piece->{'diagnosticcode'}, $cx);
285 }
286  
287 # Remove "553-" and "553 " (SMTP reply code only) from the error message
288 414 $cx = sprintf("%s%s", $cr, $q);
289 414 $p0 = index($piece->{'diagnosticcode'}, $cx);
290 414 ▶ while( $p0 > -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p0 > -1) 42 414 456
291 # Remove strings like "553-"
292 42 substr($piece->{'diagnosticcode'}, $p0, length $cx, '');
293 42 $p0 = index($piece->{'diagnosticcode'}, $cx);
294 }
295 }
296  
297 207 ▶ if( index($piece->{'diagnosticcode'}, $cr) > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($piece->{"diagnosticcode"}, $cr) > 1) 0 207 207
298 # Add "550 5.1.1" into the head of the error message when the error
299 # message does not begin with "550"
300 0 $piece->{'diagnosticcode'} = sprintf("%s %s %s", $cr, $cs, $piece->{'diagnosticcode'});
301 }
302 }
303 }
304  
305 3622 my $dc = lc $piece->{'diagnosticcode'};
306 3622 my $p1 = index($dc, '<html>');
307 3622 my $p2 = index($dc, '</html>');
308 3622 ▶ substr($piece->{'diagnosticcode'}, $p1, $p2 + 7 - $p1, '') if $p1 > 0 && $p2 > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $p1 > 0 and $p2 > 0 22 3600 3622
Condition66%2/3
$p1 > 0 and $p2 > 0
!ll&&!rl&&r
3600022
MC/DC50%1/2
$p1 > 0 and $p2 > 0
$p1 > 0 $p2 > 0
Truth table66%2/3
A and B
A= $p1 > 0B= $p2 > 0
ABresult
0X0
100
111
309 3622 $piece->{'diagnosticcode'} = Sisimai::String->sweep($piece->{'diagnosticcode'});
310 }
311  
312 DIAGNOSTICTYPE: {
313 # Set the value of "diagnostictype" if it is empty
314 3632 my $cv = $piece->{'reason'};
315 3632 ▶ if( $cv eq $Sisimai::Eb::ReUNIX ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cv eq $Sisimai::Eb::ReUNIX) { } 0 3632 3632
elsif ($cv ne $Sisimai::Eb::ReFEED and $cv ne $Sisimai::Eb::ReAWAY) { } 3516 227 3743
316 # MailerError
317 0 ▶ $piece->{'diagnostictype'} ||= 'X-UNIX';
Condition0%0/2
$piece->{"diagnostictype"} ||= "X-UNIX"
l!l
00
MC/DC0%0/1
$piece->{"diagnostictype"} ||= "X-UNIX"
$piece->{"diagnostictype"}
Truth table0%0/2
A
A= $piece->{"diagnostictype"}
Aresult
11
00
318  
319 ▶ } elsif( $cv ne $Sisimai::Eb::ReFEED && $cv ne $Sisimai::Eb::ReAWAY ) {
Condition100%3/3
$cv ne $Sisimai::Eb::ReFEED and $cv ne $Sisimai::Eb::ReAWAY
!ll&&!rl&&r
11153516
MC/DC100%2/2
$cv ne $Sisimai::Eb::ReFEED and $cv ne $Sisimai::Eb::ReAWAY
$cv ne $Sisimai::Eb::ReFEED $cv ne $Sisimai::Eb::ReAWAY
Truth table100%3/3
A and B
A= $cv ne $Sisimai::Eb::ReFEEDB= $cv ne $Sisimai::Eb::ReAWAY
ABresult
0X0
100
111
320 # Feeback or Vacation
321 3516 ▶ $piece->{'diagnostictype'} ||= 'SMTP';
Condition100%2/2
$piece->{"diagnostictype"} ||= "SMTP"
l!l
18581658
MC/DC100%1/1
$piece->{"diagnostictype"} ||= "SMTP"
$piece->{"diagnostictype"}
Truth table100%2/2
A
A= $piece->{"diagnostictype"}
Aresult
11
00
322 }
323 }
324  
325 # Check the Subject field of the original message
326 3632 ▶ $piece->{'subject'} = $rfc822data->{'subject'} // '';
Condition50%1/2
$rfc822data->{"subject"} // ""
l!l
36320
MC/DC0%0/1
$rfc822data->{"subject"} // ""
$rfc822data->{"subject"}
Truth table50%1/2
A
A= $rfc822data->{"subject"}
Aresult
11
00
327 3632 ▶ chop $piece->{'subject'} if substr($piece->{'subject'}, -1, 1) eq "\r";
Branch: 1 branch
BranchTrueFalseTotal
if substr($piece->{"subject"}, -1, 1) eq "\r" 0 3632 3632
328  
329 # When "RCPT first" in the error message, set "RCPT" as the last command.
330 # - <<< 503 RCPT first (#5.5.1)
331 # - <<< 503-5.5.1 RCPT first. A mail transaction protocol command was issued ...
332 # - RCPT first (in reply to DATA command)
333 3632 ▶ $piece->{'command'} = '' unless Sisimai::SMTP::Command->test($piece->{'command'});
Branch: 1 branch
BranchTrueFalseTotal
unless "Sisimai::SMTP::Command"->test($piece->{"command"}) 1951 1681 3632
334 3632 ▶ $piece->{'command'} = $Sisimai::Eb::CeRCPT if index($piece->{'diagnosticcode'}, 'RCPT first') > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($piece->{"diagnosticcode"}, "RCPT first") != -1 13 3619 3632
335  
336 CONSTRUCTOR: {
337 # Create email address object
338 3632 ▶ my $as = Sisimai::Address->new($piece->{'addresser'}) || next RISEOF;
Condition50%1/2
'Sisimai::Address'->new($piece->{'addresser'}) || (next RISEOF)
l!l
36320
MC/DC0%0/1
'Sisimai::Address'->new($piece->{'addresser'}) || (next RISEOF)
'Sisimai::Address'->new($piece->{'addresser'})
Truth table50%1/2
A
A= 'Sisimai::Address'->new($piece->{'addresser'})
Aresult
11
00
339 3632 ▶ my $ar = Sisimai::Address->new({'address' => $piece->{'recipient'}}) || next RISEOF;
Condition50%1/2
'Sisimai::Address'->new({'address', $piece->{'recipient'}}) || (next RISEOF)
l!l
36320
MC/DC0%0/1
'Sisimai::Address'->new({'address', $piece->{'recipient'}}) || (next RISEOF)
'Sisimai::Address'->new({'address', $piece->{'recipient'}})
Truth table50%1/2
A
A= 'Sisimai::Address'->new({'address', $piece->{'recipient'}})
Aresult
11
00
340 3632 my @ea = (qw|
341 action command decodedby deliverystatus diagnosticcode diagnostictype feedbacktype
342 lhost listid messageid origin reason replycode rhost subject
343 |);
344  
345 $thing = {
346 'addresser' => $as,
347 'recipient' => $ar,
348 'senderdomain' => $as->host,
349 'destination' => $ar->host,
350 'alias' => $piece->{'alias'} || $ar->alias,
351 3632 ▶ 'token' => __PACKAGE__->maketoken($as->address, $ar->address, $piece->{'timestamp'}),
Condition66%2/3
$piece->{'alias'} || $ar->alias
l!l&&r!l&&!r
78602846
MC/DC50%1/2
$piece->{'alias'} || $ar->alias
$piece->{'alias'} $ar->alias
Truth table66%2/3
A || B
A= $piece->{'alias'}B= $ar->alias
ABresult
1X1
011
000
352 };
353 3632 ▶ $thing->{ $_ } ||= $piece->{ $_ } // '' for @ea;
Condition60%3/5
$thing->{$_} ||= $piece->{$_} // ""
l!l&&r!l&&!r
03724417236
$piece->{$_} // ""
l!l
544800
MC/DC0%0/2
$thing->{$_} ||= $piece->{$_} // ""
$thing->{$_} $piece->{$_}
Truth table33%1/3
A ||= B
A= $thing->{$_}B= $piece->{$_}
ABresult
1X1
011
000
354 3632 $thing->{'bogus'} = -1;
355 3632 ▶ $thing->{'catch'} = $piece->{'catch'} // undef;
Condition100%2/2
$piece->{"catch"} // undef
l!l
7352897
MC/DC100%1/1
$piece->{"catch"} // undef
$piece->{"catch"}
Truth table100%2/2
A
A= $piece->{"catch"}
Aresult
11
00
356 3632 $thing->{"feedbackid"} = "";
357 3632 $thing->{'hardbounce'} = int $piece->{'hardbounce'};
358 3632 ▶ $thing->{'replycode'} ||= Sisimai::SMTP::Reply->find($piece->{'diagnosticcode'}) || '';
Condition100%5/5
$thing->{"replycode"} ||= "Sisimai::SMTP::Reply"->find($piece->{"diagnosticcode"}) || ""
l!l&&r!l&&!r
260251025
'Sisimai::SMTP::Reply'->find($piece->{'diagnosticcode'}) || ''
l!l
51025
MC/DC100%2/2
$thing->{"replycode"} ||= "Sisimai::SMTP::Reply"->find($piece->{"diagnosticcode"}) || ""
$thing->{"replycode"} 'Sisimai::SMTP::Reply'->find($piece->{'diagnosticcode'})
Truth table100%3/3
A ||= B
A= $thing->{"replycode"}B= 'Sisimai::SMTP::Reply'->find($piece->{'diagnosticcode'})
ABresult
1X1
011
000
359 3632 $thing->{'timestamp'} = Sisimai::Time->new($piece->{'timestamp'});
360 3632 ▶ $thing->{'timezoneoffset'} = $piece->{'timezoneoffset'} // '+0000';
Condition50%1/2
$piece->{"timezoneoffset"} // "+0000"
l!l
36320
MC/DC0%0/1
$piece->{"timezoneoffset"} // "+0000"
$piece->{"timezoneoffset"}
Truth table50%1/2
A
A= $piece->{"timezoneoffset"}
Aresult
11
00
361 3632 $thing->{'toxic'} = -1;
362 }
363  
364 ALIAS: {
365 # Look up the Envelope-To address from the Received: header in the original message
366 # when the recipient address is same with the value of $o->{'alias'}.
367 3632 ▶ last if length $thing->{'alias'} == 0 || $thing->{'recipient'}->address ne $thing->{'alias'};
Branch: 1 branch
BranchTrueFalseTotal
if length $thing->{"alias"} == 0 or $thing->{"recipient"}->address ne $thing->{"alias"} 2956 676 3632
Condition100%3/3
length $thing->{"alias"} == 0 or $thing->{"recipient"}->address ne $thing->{"alias"}
l!l&&r!l&&!r
2846110676
MC/DC100%2/2
length $thing->{"alias"} == 0 or $thing->{"recipient"}->address ne $thing->{"alias"}
length $thing->{"alias"} == 0 $thing->{"recipient"}->address ne $thing->{"alias"}
Truth table100%3/3
A or B
A= length $thing->{"alias"} == 0B= $thing->{"recipient"}->address ne $thing->{"alias"}
ABresult
1X1
011
000
368 676 ▶ last unless exists $rfc822data->{'received'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rfc822data->{"received"} 0 676 676
369 676 ▶ last unless scalar $rfc822data->{'received'}->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$rfc822data->{"received"}} 73 603 676
370  
371 603 for my $er ( reverse $rfc822data->{'received'}->@* ) {
372 # Search for the string " for " from the Received: header
373 1093 ▶ next unless index($er, ' for ') > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless index($er, " for ") > 1 302 791 1093
374 791 my $or = Sisimai::RFC5322->received($er);
375  
376 791 ▶ next if scalar(@$or) == 0 || length($or->[5]) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @$or == 0 or length $or->[5] == 0 0 791 791
Condition33%1/3
scalar @$or == 0 or length $or->[5] == 0
l!l&&r!l&&!r
00791
MC/DC0%0/2
scalar @$or == 0 or length $or->[5] == 0
scalar @$or == 0 length $or->[5] == 0
Truth table33%1/3
A or B
A= scalar @$or == 0B= length $or->[5] == 0
ABresult
1X1
011
000
377 791 ▶ next if Sisimai::Address->is_emailaddress($or->[5]) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if "Sisimai::Address"->is_emailaddress($or->[5]) == 0 0 791 791
378 791 ▶ next if $thing->{'recipient'}->address eq $or->[5];
Branch: 1 branch
BranchTrueFalseTotal
if $thing->{"recipient"}->address eq $or->[5] 758 33 791
379  
380 33 $thing->{'alias'} = $or->[5];
381 33 last ALIAS;
382 }
383 }
384 3632 ▶ $thing->{'alias'} = '' if $thing->{'alias'} eq $thing->{'recipient'}->{'address'};
Branch: 1 branch
BranchTrueFalseTotal
if $thing->{"alias"} eq $thing->{"recipient"}{"address"} 643 2989 3632
385  
386 REASON: {
387 # Decide the reason of the email bounce
388 3632 ▶ if( $thing->{'reason'} eq '' || exists $retryindex->{ $thing->{'reason'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"reason"} eq "" or exists $$retryindex{$thing->{"reason"}}) 3367 265 3632
Condition100%3/3
$thing->{"reason"} eq "" or exists $$retryindex{$thing->{"reason"}}
l!l&&r!l&&!r
3117250265
MC/DC100%2/2
$thing->{"reason"} eq "" or exists $$retryindex{$thing->{"reason"}}
$thing->{"reason"} eq "" exists $$retryindex{$thing->{"reason"}}
Truth table100%3/3
A or B
A= $thing->{"reason"} eq ""B= exists $$retryindex{$thing->{"reason"}}
ABresult
1X1
011
000
389 # The value of "reason" is empty or is needed to check with other values again
390 3367 ▶ my $re = $thing->{'reason'} || $Sisimai::Eb::Re___0;
Condition66%2/3
$thing->{'reason'} || $Sisimai::Eb::Re___0
l!l&&r!l&&!r
25031170
MC/DC0%0/2
$thing->{'reason'} || $Sisimai::Eb::Re___0
$thing->{'reason'} $Sisimai::Eb::Re___0
Truth table66%2/3
A || B
A= $thing->{'reason'}B= $Sisimai::Eb::Re___0
ABresult
1X1
011
000
391 3367 my $cr = "Sisimai::Reason";
392 3367 ▶ my $or = Sisimai::LDA->find($thing); if( $cr->is_explicit($or) ){ $thing->{'reason'} = $or; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($cr->is_explicit($or)) 32 3335 3367
393 3335 ▶ $or = Sisimai::Rhost->find($thing); if( $cr->is_explicit($or) ){ $thing->{'reason'} = $or; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($cr->is_explicit($or)) 834 2501 3335
394 2501 ▶ $or = Sisimai::Reason->find($thing); if( $cr->is_explicit($or) ){ $thing->{'reason'} = $or; last }
Branch: 1 branch
BranchTrueFalseTotal
if ($cr->is_explicit($or)) 2459 42 2501
395 42 ▶ $thing->{'reason'} = $thing->{'diagnosticcode'} ? $Sisimai::Eb::Re___1 : $re;
Branch: 1 branch
BranchTrueFalseTotal
$thing->{'diagnosticcode'} ? : 32 10 42
396 }
397 }
398  
399 HARDBOUNCE: {
400 # Set the value of "hardbounce", default value of "bouncebounce" is 0
401 3632 ▶ last HARDBOUNCE if $thing->{'reason'} eq $Sisimai::Eb::ReSENT;
Branch: 1 branch
BranchTrueFalseTotal
if $thing->{"reason"} eq $Sisimai::Eb::ReSENT 4 3628 3632
402 3628 ▶ if( $thing->{'reason'} eq $Sisimai::Eb::ReFEED || $thing->{'reason'} eq $Sisimai::Eb::ReAWAY ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"reason"} eq $Sisimai::Eb::ReFEED or $thing->{"reason"} eq $Sisimai::Eb::ReAWAY) 116 3512 3628
Condition100%3/3
$thing->{"reason"} eq $Sisimai::Eb::ReFEED or $thing->{"reason"} eq $Sisimai::Eb::ReAWAY
l!l&&r!l&&!r
11153512
MC/DC100%2/2
$thing->{"reason"} eq $Sisimai::Eb::ReFEED or $thing->{"reason"} eq $Sisimai::Eb::ReAWAY
$thing->{"reason"} eq $Sisimai::Eb::ReFEED $thing->{"reason"} eq $Sisimai::Eb::ReAWAY
Truth table100%3/3
A or B
A= $thing->{"reason"} eq $Sisimai::Eb::ReFEEDB= $thing->{"reason"} eq $Sisimai::Eb::ReAWAY
ABresult
1X1
011
000
403 # Do not assign the value of ReplyCode when the reason is Feedback or Vacation
404 116 $thing->{'replycode'} = '';
405 116 last HARDBOUNCE;
406 }
407  
408 # The reason is not "delivered", or "feedback", or "vacation"
409 3512 my $smtperrors = $piece->{'deliverystatus'}.' '.$piece->{'diagnosticcode'};
410 3512 ▶ $smtperrors = '' if length $smtperrors < 4;
Branch: 1 branch
BranchTrueFalseTotal
if length $smtperrors < 4 10 3502 3512
411 3512 $thing->{'hardbounce'} = Sisimai::SMTP::Failure->is_hardbounce($thing->{'reason'}, $smtperrors);
412 }
413  
414 DELIVERYSTATUS: {
415 # Set pseudo status code
416 3632 ▶ last DELIVERYSTATUS if $thing->{'deliverystatus'};
Branch: 1 branch
BranchTrueFalseTotal
if $thing->{"deliverystatus"} 2831 801 3632
417  
418 801 my $smtperrors = $thing->{'replycode'}.' '.$piece->{'diagnosticcode'};
419 801 ▶ $smtperrors = '' if length $smtperrors < 4;
Branch: 1 branch
BranchTrueFalseTotal
if length $smtperrors < 4 10 791 801
420 801 my $permanent0 = Sisimai::SMTP::Failure->is_permanent($smtperrors);
421 801 my $temporary0 = Sisimai::SMTP::Failure->is_temporary($smtperrors);
422 801 ▶ my $temporary1 = $permanent0.$temporary0 eq "00" ? 0 : $temporary0;
Branch: 1 branch
BranchTrueFalseTotal
$permanent0 . $temporary0 eq '00' ? : 522 279 801
423 801 $thing->{'deliverystatus'} = Sisimai::SMTP::Status->code($thing->{'reason'}, $temporary1);
424 }
425  
426 REPLYCODE: {
427 # Check both of the first digit of "deliverystatus" and "replycode"
428 3632 my $cx = [substr($thing->{'deliverystatus'}, 0, 1), substr($thing->{'replycode'}, 0, 1)];
429 3632 ▶ if( $cx->[0] ne $cx->[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cx->[0] ne $cx->[1]) 945 2687 3632
430 # The class of the "Status:" is defer with the first digit of the reply code
431 945 ▶ $cx->[1] = Sisimai::SMTP::Reply->find($piece->{'diagnosticcode'}, $cx->[0]) || '';
Condition100%2/2
'Sisimai::SMTP::Reply'->find($piece->{'diagnosticcode'}, $cx->[0]) || ''
l!l
10935
MC/DC100%1/1
'Sisimai::SMTP::Reply'->find($piece->{'diagnosticcode'}, $cx->[0]) || ''
'Sisimai::SMTP::Reply'->find($piece->{'diagnosticcode'}, $cx->[0])
Truth table100%2/2
A
A= 'Sisimai::SMTP::Reply'->find($piece->{'diagnosticcode'}, $cx->[0])
Aresult
11
00
432 945 ▶ $thing->{'replycode'} = index($cx->[1], $cx->[0]) == 0 ? $cx->[1] : '';
Branch: 1 branch
BranchTrueFalseTotal
index($cx->[1], $cx->[0]) == 0 ? : 10 935 945
433 }
434  
435 3632 ▶ unless( exists $actionlist->{ $thing->{'action'} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $$actionlist{$thing->{"action"}}) 1690 1942 3632
436 # There is an action value which is not described at RFC1894
437 1690 ▶ if( my $ox = Sisimai::RFC1894->field('Action: '.$thing->{'action'}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ox = "Sisimai::RFC1894"->field('Action: ' . $thing->{"action"})) 1690 0 1690
438 # Rewrite the value of "Action:" field to the valid value
439 #
440 # The syntax for the action-field is:
441 # action-field = "Action" ":" action-value
442 # action-value = "failed" / "delayed" / "delivered" / "relayed" / "expanded"
443 1690 $thing->{'action'} = $ox->[2];
444 }
445 }
446 3632 ▶ $thing->{'action'} = $Sisimai::Eb::AeSENT if $thing->{'reason'} eq $Sisimai::Eb::ReSENT;
Branch: 1 branch
BranchTrueFalseTotal
if $thing->{"reason"} eq $Sisimai::Eb::ReSENT 4 3628 3632
447 3632 ▶ $thing->{'action'} ||= $Sisimai::Eb::AeSTAY if $thing->{'reason'} eq $Sisimai::Eb::ReTIME;
Branch: 1 branch
BranchTrueFalseTotal
if $thing->{"reason"} eq $Sisimai::Eb::ReTIME 249 3383 3632
Condition66%2/3
$thing->{"action"} ||= $Sisimai::Eb::AeSTAY
l!l&&r!l&&!r
1141350
MC/DC0%0/2
$thing->{"action"} ||= $Sisimai::Eb::AeSTAY
$thing->{"action"} $Sisimai::Eb::AeSTAY
Truth table66%2/3
A ||= B
A= $thing->{"action"}B= $Sisimai::Eb::AeSTAY
ABresult
1X1
011
000
448 3632 ▶ $thing->{'action'} ||= $Sisimai::Eb::AeFAIL if $cx->[0] eq '4' || $cx->[0] eq '5';
Branch: 1 branch
BranchTrueFalseTotal
if $cx->[0] eq 4 or $cx->[0] eq 5 3512 120 3632
Condition83%5/6
$cx->[0] eq 4 or $cx->[0] eq 5
l!l&&r!l&&!r
4413071120
$thing->{"action"} ||= $Sisimai::Eb::AeFAIL
l!l&&r!l&&!r
207314390
MC/DC100%2/2
$cx->[0] eq 4 or $cx->[0] eq 5
$cx->[0] eq 4 $cx->[0] eq 5
MC/DC0%0/2
$thing->{"action"} ||= $Sisimai::Eb::AeFAIL
$thing->{"action"} $Sisimai::Eb::AeFAIL
Truth table100%3/3
A or B
A= $cx->[0] eq 4B= $cx->[0] eq 5
ABresult
1X1
011
000
Truth table66%2/3
A ||= B
A= $thing->{"action"}B= $Sisimai::Eb::AeFAIL
ABresult
1X1
011
000
449 3632 ▶ $thing->{'action'} ||= "";
Condition100%2/2
$thing->{"action"} ||= ""
l!l
3516116
MC/DC100%1/1
$thing->{"action"} ||= ""
$thing->{"action"}
Truth table100%2/2
A
A= $thing->{"action"}
Aresult
11
00
450 }
451  
452 3632 ▶ if( $thing->{'replycode'} ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($thing->{"replycode"} ne "") 2581 1051 3632
453 # Fill empty values: ["SMTP Command", "DSN", "Reason"]
454 2581 my $cv = Sisimai::SMTP::Reply->associatedwith($thing->{'replycode'});
455 2581 ▶ if( scalar @$cv > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$cv > 0) 334 2247 2581
456 334 ▶ $thing->{'command'} = $cv->[0] if $cv->[0] ne "" && $thing->{'command'} eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $cv->[0] ne "" and $thing->{"command"} eq "" 5 329 334
Condition100%3/3
$cv->[0] ne "" and $thing->{"command"} eq ""
!ll&&!rl&&r
309205
MC/DC100%2/2
$cv->[0] ne "" and $thing->{"command"} eq ""
$cv->[0] ne "" $thing->{"command"} eq ""
Truth table100%3/3
A and B
A= $cv->[0] ne ""B= $thing->{"command"} eq ""
ABresult
0X0
100
111
457 334 ▶ $thing->{'deliverystatus'} = $cv->[1] if $cv->[1] ne "" && Sisimai::SMTP::Status->is_explicit($thing->{'deliverystatus'}) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $cv->[1] ne "" and "Sisimai::SMTP::Status"->is_explicit($thing->{"deliverystatus"}) == 0 0 334 334
Condition66%2/3
$cv->[1] ne "" and "Sisimai::SMTP::Status"->is_explicit($thing->{"deliverystatus"}) == 0
!ll&&!rl&&r
319150
MC/DC0%0/2
$cv->[1] ne "" and "Sisimai::SMTP::Status"->is_explicit($thing->{"deliverystatus"}) == 0
$cv->[1] ne "" "Sisimai::SMTP::Status"->is_explicit($thing->{"deliverystatus"}) == 0
Truth table66%2/3
A and B
A= $cv->[1] ne ""B= "Sisimai::SMTP::Status"->is_explicit($thing->{"deliverystatus"}) == 0
ABresult
0X0
100
111
458 334 ▶ $thing->{'reason'} = $cv->[2] if $cv->[2] ne "" && Sisimai::Reason->is_explicit($thing->{'reason'}) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $cv->[2] ne "" and "Sisimai::Reason"->is_explicit($thing->{"reason"}) == 0 10 324 334
Condition66%2/3
$cv->[2] ne "" and "Sisimai::Reason"->is_explicit($thing->{"reason"}) == 0
!ll&&!rl&&r
032410
MC/DC50%1/2
$cv->[2] ne "" and "Sisimai::Reason"->is_explicit($thing->{"reason"}) == 0
$cv->[2] ne "" "Sisimai::Reason"->is_explicit($thing->{"reason"}) == 0
Truth table66%2/3
A and B
A= $cv->[2] ne ""B= "Sisimai::Reason"->is_explicit($thing->{"reason"}) == 0
ABresult
0X0
100
111
459 }
460 }
461 # Feedback-ID: 1.us-west-2.QHuyeCQrGtIIMGKQfVdUhP9hCQR2LglVOrRamBc+Prk=:AmazonSES
462 3632 ▶ $thing->{'feedbackid'} = $rfc822data->{'feedback-id'} || "";
Condition100%2/2
$rfc822data->{'feedback-id'} || ''
l!l
1243508
MC/DC100%1/1
$rfc822data->{'feedback-id'} || ''
$rfc822data->{'feedback-id'}
Truth table100%2/2
A
A= $rfc822data->{'feedback-id'}
Aresult
11
00
463 3632 $thing->{'reason'} = lc $thing->{'reason'};
464  
465 3632 push @$listoffact, bless($thing, __PACKAGE__);
466 } # End of for(RISEOF)
467  
468 3478 return $listoffact;
469 }
470  
471 3638 ▶sub maketoken {
Subroutine maketoken: called CC=5 SCAR=16.1
Pod undocumented
472 # Create the message token from an addresser and a recipient
473 # @param [String] addr1 A sender's email address
474 # @param [String] addr2 A recipient's email address
475 # @param [Integer] epoch Machine time of the email bounce
476 # @return [String] Message token(MD5 hex digest) or empty string
477 # if the any argument is missing
478 # @see http://en.wikipedia.org/wiki/ASCII
479 # @see https://metacpan.org/pod/Digest::MD5
480 3638 ▶ my $class = shift || return '';
Condition50%1/2
shift() || (return '')
l!l
36380
MC/DC0%0/1
shift() || (return '')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
481 3638 ▶ my $addr1 = shift || return '';
Condition100%2/2
shift() || (return '')
l!l
36371
MC/DC100%1/1
shift() || (return '')
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
482 3637 ▶ my $addr2 = shift || return '';
Condition100%2/2
shift() || (return '')
l!l
36361
MC/DC100%1/1
shift() || (return '')
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
483 3636 ▶ my $epoch = shift // return '';
Condition100%2/2
shift() // (return "")
l!l
36351
MC/DC100%1/1
shift() // (return "")
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
484  
485 # Format: STX(0x02) Sender-Address RS(0x1e) Recipient-Address ETX(0x03)
486 3635 return Digest::SHA::sha1_hex(sprintf("\x02%s\x1e%s\x1e%d\x03", lc $addr1, lc $addr2, $epoch));
487 }
488  
489  
490 3663 ▶sub damn {
Subroutine damn: called CC=3 SCAR=11.0
Pod documented
491 # Convert from object to hash reference
492 # @return [Hash] Data in Hash reference
493 3663 my $self = shift;
494 3663 my $data = undef;
495 3663 state $stringdata = [qw|
496 action alias catch command decodedby deliverystatus destination diagnosticcode diagnostictype
497 feedbackid feedbacktype lhost listid messageid origin reason replycode rhost senderdomain
498 subject timezoneoffset token
499 |];
500 3663 eval {
501 3663 my $v = {};
502 3663 ▶ $v->{ $_ } = $self->$_ // '' for @$stringdata;
Condition100%2/2
$self->$_ // ""
l!l
770833503
MC/DC100%1/1
$self->$_ // ""
$self->$_
Truth table100%2/2
A
A= $self->$_
Aresult
11
00
503 3663 $v->{'hardbounce'} = int $self->hardbounce;
504 3663 $v->{'bogus'} = int $self->bogus;
505 3663 $v->{'toxic'} = int $self->toxic;
506 3663 $v->{'addresser'} = $self->addresser->address;
507 3663 $v->{'recipient'} = $self->recipient->address;
508 3663 $v->{'timestamp'} = $self->timestamp->epoch;
509 3663 $data = $v;
510 };
511 3663 return $data;
512 }
513  
514 2243 ▶sub dump {
Subroutine dump: called CC=3 SCAR=11.0
Pod undocumented
515 # Data dumper
516 # @param [String] type Data format: json, yaml
517 # @return [String] Dumped data or an empty string when the argument is neither "json" nor "yaml"
518 2243 my $self = shift;
519 2243 ▶ my $type = shift || 'json'; return "" unless $type =~ /\A(?:json|yaml)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $type =~ /\A(?:json|yaml)\z/u 40 2203 2243
Condition100%2/2
shift() || 'json'
l!l
220340
MC/DC100%1/1
shift() || 'json'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
520  
521 2203 my $referclass = 'Sisimai::Fact::'.uc($type);
522 2203 my $modulepath = 'Sisimai/Fact/'.uc($type).'.pm';
523  
524 2203 require $modulepath;
525 2203 return $referclass->dump($self);
526 }
527  
528 86 1;
529 __END__
↑ Summary Sisimai/Lhost/Exim.pm »