Sisimai/Lhost/EZweb.pm

filter: Statementstmt 97.3% 72 / 74 Branchbran 80.7% 42 / 52 Conditioncond 88.4% 23 / 26 MC/DCmcdc 78.5% 11 / 14 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 89.6% 156 / 174 CC 39 SCAR 35.9
CC
39
Cov
90%
inquire
40.9
BEGIN
1.0
BEGIN
1.0
CRAP 36.4
« Sisimai/Lhost/mFILTER.pm ↑ Summary Sisimai/ARF.pm »
1 package Sisimai::Lhost::EZweb;
2 36 ▶use parent 'Sisimai::Lhost';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 36 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶sub description { 'au EZweb: https://www.au.com/mobile/' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
8 908 ▶sub inquire {
Subroutine inquire: called CC=39 SCAR=37.1
Pod documented
9 # Detect an error from EZweb
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 908 my $class = shift;
16 908 ▶ my $mhead = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
9071
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
17 907 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
9061
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18  
19 # Pre-process email headers of NON-STANDARD bounce message au by EZweb, as known as ezweb.ne.jp.
20 # Subject: Mail System Error - Returned Mail
21 # From: <Postmaster@ezweb.ne.jp>
22 # Received: from ezweb.ne.jp (wmflb12na02.ezweb.ne.jp [222.15.69.197])
23 # Received: from nmomta.auone-net.jp ([aaa.bbb.ccc.ddd]) by ...
24 906 ▶ my $match = 0; $match++ if rindex($mhead->{'from'}, 'Postmaster@ezweb.ne.jp') > -1;
Branch: 1 branch
BranchTrueFalseTotal
if rindex($mhead->{"from"}, "Postmaster\@ezweb.ne.jp") != -1 41 865 906
25 906 ▶ $match++ if rindex($mhead->{'from'}, 'Postmaster@au.com') > -1;
Branch: 1 branch
BranchTrueFalseTotal
if rindex($mhead->{"from"}, "Postmaster\@au.com") != -1 0 906 906
26 906 ▶ $match++ if $mhead->{'subject'} eq 'Mail System Error - Returned Mail';
Branch: 1 branch
BranchTrueFalseTotal
if $mhead->{"subject"} eq "Mail System Error - Returned Mail" 41 865 906
27 906 ▶ $match++ if grep { rindex($_, 'ezweb.ne.jp (EZweb Mail) with') > -1 } $mhead->{'received'}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if grep {rindex($_, "ezweb.ne.jp (EZweb Mail) with") != -1;} @{$$mhead{"received"}} 16 890 906
28 906 ▶ $match++ if grep { rindex($_, '.au.com (') > -1 } $mhead->{'received'}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if grep {rindex($_, ".au.com (") != -1;} @{$$mhead{"received"}} 0 906 906
29 906 ▶ if( defined $mhead->{'message-id'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mhead->{"message-id"}) 844 62 906
30 844 ▶ $match++ if substr($mhead->{'message-id'}, -13, 13) eq '.ezweb.ne.jp>';
Branch: 1 branch
BranchTrueFalseTotal
if substr($mhead->{"message-id"}, -13, 13) eq ".ezweb.ne.jp>" 41 803 844
31 844 ▶ $match++ if substr($mhead->{'message-id'}, -8, 8) eq '.au.com>';
Branch: 1 branch
BranchTrueFalseTotal
if substr($mhead->{"message-id"}, -8, 8) eq ".au.com>" 0 844 844
32 }
33 906 ▶ return undef if $match < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $match < 2 865 41 906
34  
35 41 require Sisimai::Eb;
36 41 require Sisimai::SMTP::Command;
37 41 state $indicators = __PACKAGE__->INDICATORS;
38 41 state $boundaries = ["--------------------------------------------------", "Content-Type: message/rfc822"];
39 41 state $startingof = {"message" => ['The user(s) ', 'Your message ', 'Each of the following', '<']};
40 41 state $unpaiduser = [
41 # http://www.naruhodo-au.kddi.com/qa3429203.html
42 # The recipient may be unpaid user...?
43 "The user(s) account is disabled.",
44 "The user(s) account is temporarily limited.",
45 ];
46  
47 41 ▶ my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries) // return undef; return undef unless $emailparts->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $emailparts->[0] 0 41 41
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
410
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 41 my $fieldtable = Sisimai::RFC1894->FIELDTABLE;
49 41 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef;
50 41 my $readcursor = 0; # Points the current cursor position
51 41 my $recipients = 0; # The number of 'Final-Recipient' header
52  
53 41 for my $e ( split("\n", $emailparts->[0]) ) {
54 # Read error messages and delivery status lines from the head of the email to the previous
55 # line of the beginning of the original message.
56 533 ▶ unless( $readcursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readcursor) 301 232 533
57 # Beginning of the bounce message or message/delivery-status part
58 301 ▶ $readcursor |= $indicators->{'deliverystatus'} if grep { index($e, $_) > -1 } $startingof->{'message'}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($e, $_) != -1;} @{$$startingof{"message"}} 41 260 301
59 }
60 533 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq "" 336 197 533
Condition100%3/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
l!l&&r!l&&!r
26076197
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
61  
62 # The user(s) account is disabled.
63 #
64 # <***@ezweb.ne.jp>: 550 user unknown (in reply to RCPT TO command)
65 #
66 # -- OR --
67 # Each of the following recipients was rejected by a remote
68 # mail server.
69 #
70 # Recipient: <******@ezweb.ne.jp>
71 # >>> RCPT TO:<******@ezweb.ne.jp>
72 # <<< 550 <******@ezweb.ne.jp>: User unknown
73 197 $v = $dscontents->[-1];
74  
75 197 ▶ if( Sisimai::String->aligned(\$e, ['<', '@', '>']) && (index($e, 'Recipient: <') > 1 || index($e, '<') == 0) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ('Sisimai::String'->aligned(\$e, ['<', '@', '>']) and index($e, 'Recipient: <') > 1 || index($e, '<') == 0) { } 41 156 197
elsif (my $f = 'Sisimai::RFC1894'->match($e)) { } 50 106 156
Condition100%6/6
"Sisimai::String"->aligned(\$e, ["<", "\@", ">"]) and index($e, "Recipient: <") > 1 || index($e, "<") == 0
!ll&&!rl&&r
1312541
index($e, "Recipient: <") > 1 or index($e, "<") == 0
l!l&&r!l&&!r
152625
MC/DC100%3/3
"Sisimai::String"->aligned(\$e, ["<", "\@", ">"]) and index($e, "Recipient: <") > 1 || index($e, "<") == 0
"Sisimai::String"->aligned(\$e, ["<", "\@", ">"]) index($e, "Recipient: <") > 1 index($e, "<") == 0
Truth table100%4/4
A and B or C
A= "Sisimai::String"->aligned(\$e, ["<", "\@", ">"])B= index($e, "Recipient: <") > 1C= index($e, "<") == 0
ABCresult
0XX0
1000
11X1
1011
76 # Recipient: <******@ezweb.ne.jp> OR <***@ezweb.ne.jp>: 550 user unknown ...
77 41 my $p1 = index($e, '<');
78 41 my $p2 = index($e, '>');
79  
80 41 ▶ if( $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 0 41 41
81 # There are multiple recipient addresses in the message body.
82 0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
83 0 $v = $dscontents->[-1];
84 }
85 41 $v->{'recipient'} = Sisimai::Address->s3s4(substr($e, $p1, $p2 - $p1));
86 41 $v->{"diagnosis"} .= " ".$e;
87 41 $recipients++;
88  
89 } elsif( my $f = Sisimai::RFC1894->match($e) ) {
90 # $e matched with any field defined in RFC3464
91 50 ▶ next unless my $o = Sisimai::RFC1894->field($e);
Branch: 1 branch
BranchTrueFalseTotal
unless my $o = "Sisimai::RFC1894"->field($e) 0 50 50
92 50 ▶ next unless exists $fieldtable->{ $o->[0] };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$fieldtable{$o->[0]} 0 50 50
93 50 $v->{ $fieldtable->{ $o->[0] } } = $o->[2];
94  
95 } else {
96 # The line does not begin with a DSN field defined in RFC3464
97 # >>> RCPT TO:<******@ezweb.ne.jp>
98 # <<< 550 ...
99 106 ▶ next if Sisimai::String->is_8bit(\$e);
Branch: 1 branch
BranchTrueFalseTotal
if "Sisimai::String"->is_8bit(\$e) 0 106 106
100 106 ▶ $v->{"command"} = Sisimai::SMTP::Command->find($e) if index($e, " >>> ") > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, " >>> ") != -1 15 91 106
101 106 $v->{"diagnosis"} .= " ".$e;
102 } # End of error message part
103 }
104 41 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 0 41 41
105  
106 41 for my $e ( @$dscontents ) {
107 # Check each value of DeliveryMatter{}, try to detect the bounce reason.
108 41 $e->{'diagnosis'} = Sisimai::String->sweep($e->{'diagnosis'});
109 41 ▶ $e->{"command"} ||= Sisimai::SMTP::Command->find($e->{"diagnosis"}) || "";
Condition100%5/5
$e->{"command"} ||= "Sisimai::SMTP::Command"->find($e->{"diagnosis"}) || ""
l!l&&r!l&&!r
15521
'Sisimai::SMTP::Command'->find($e->{'diagnosis'}) || ''
l!l
521
MC/DC100%2/2
$e->{"command"} ||= "Sisimai::SMTP::Command"->find($e->{"diagnosis"}) || ""
$e->{"command"} 'Sisimai::SMTP::Command'->find($e->{'diagnosis'})
Truth table100%3/3
A ||= B
A= $e->{"command"}B= 'Sisimai::SMTP::Command'->find($e->{'diagnosis'})
ABresult
1X1
011
000
110  
111 41 ▶ if( defined $mhead->{'x-spasign'} && $mhead->{'x-spasign'} eq 'NG' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mhead->{'x-spasign'} and $mhead->{'x-spasign'} eq 'NG') { } 6 35 41
Condition66%2/3
defined $mhead->{"x-spasign"} and $mhead->{"x-spasign"} eq "NG"
!ll&&!rl&&r
3506
MC/DC50%1/2
defined $mhead->{"x-spasign"} and $mhead->{"x-spasign"} eq "NG"
defined $mhead->{"x-spasign"} $mhead->{"x-spasign"} eq "NG"
Truth table66%2/3
A and B
A= defined $mhead->{"x-spasign"}B= $mhead->{"x-spasign"} eq "NG"
ABresult
0X0
100
111
112 # Content-Type: text/plain; ..., X-SPASIGN: NG (spamghetti, au by EZweb)
113 # Filtered recipient returns message that include 'X-SPASIGN' header
114 6 $e->{'reason'} = $Sisimai::Eb::ReFILT;
115  
116 } else {
117 # There is no X-SPASIGN header or the value of the header is not "NG"
118 35 ▶ $e->{'reason'} = $Sisimai::Eb::ReQUIT if grep { index($e->{'diagnosis'}, $_) > -1 } $unpaiduser->@*;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($e->{"diagnosis"}, $_) != -1;} @$unpaiduser 15 20 35
119 }
120 41 ▶ next if $e->{'reason'};
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"reason"} 21 20 41
121 20 ▶ next if index($e->{'recipient'}, '@ezweb.ne.jp') > 1 || index($e->{'recipient'}, '@au.com') > 1;
Branch: 1 branch
BranchTrueFalseTotal
if index($e->{"recipient"}, "\@ezweb.ne.jp") > 1 or index($e->{"recipient"}, "\@au.com") > 1 15 5 20
Condition66%2/3
index($e->{"recipient"}, "\@ezweb.ne.jp") > 1 or index($e->{"recipient"}, "\@au.com") > 1
l!l&&r!l&&!r
1505
MC/DC50%1/2
index($e->{"recipient"}, "\@ezweb.ne.jp") > 1 or index($e->{"recipient"}, "\@au.com") > 1
index($e->{"recipient"}, "\@ezweb.ne.jp") > 1 index($e->{"recipient"}, "\@au.com") > 1
Truth table66%2/3
A or B
A= index($e->{"recipient"}, "\@ezweb.ne.jp") > 1B= index($e->{"recipient"}, "\@au.com") > 1
ABresult
1X1
011
000
122 5 ▶ $e->{"reason"} = $Sisimai::Eb::ReUSER if index($e->{"diagnosis"}, "<") == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e->{"diagnosis"}, "<") == 0 0 5 5
123 }
124 41 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
125 }
126  
127 36 1;
128 __END__
« Sisimai/Lhost/mFILTER.pm ↑ Summary Sisimai/ARF.pm »