Sisimai/Lhost/mFILTER.pm

filter: Statementstmt 96.9% 63 / 65 Branchbran 80.9% 34 / 42 Conditioncond 78.7% 26 / 33 MC/DCmcdc 63.1% 12 / 19 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 85.6% 143 / 167 CC 38 SCAR 36.0
CC
38
Cov
88%
inquire
41.5
BEGIN
1.0
BEGIN
1.0
CRAP 36.8
« Sisimai/Lhost/ApacheJames.pm ↑ Summary Sisimai/Lhost/EZweb.pm »
1 package Sisimai::Lhost::mFILTER;
2 38 ▶use parent 'Sisimai::Lhost';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 38 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 38 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 38 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶sub description { 'Digital Arts m-FILTER: https://www.daj.jp/bs/mf/' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
8 905 ▶sub inquire {
Subroutine inquire: called CC=38 SCAR=37.2
Pod documented
9 # Detect an error from Digital Arts m-FILTER
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.1.1
15 905 my $class = shift;
16 905 ▶ my $mhead = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
9041
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
17 904 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
9031
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18  
19 903 state $indicators = __PACKAGE__->INDICATORS;
20 903 state $boundaries = ['-------original message', '-------original mail info'];
21 903 state $startingof = {
22 'command' => ['-------SMTP command'],
23 'error' => ['-------server message'],
24 };
25  
26 # X-Mailer: m-FILTER
27 903 my $proceedsto = 0;
28 903 ▶ $proceedsto = 1 if defined $mhead->{'x-mailer'} && $mhead->{'x-mailer'} eq 'm-FILTER';
Branch: 1 branch
BranchTrueFalseTotal
if defined $mhead->{"x-mailer"} and $mhead->{"x-mailer"} eq "m-FILTER" 22 881 903
Condition100%3/3
defined $mhead->{"x-mailer"} and $mhead->{"x-mailer"} eq "m-FILTER"
!ll&&!rl&&r
8047722
MC/DC100%2/2
defined $mhead->{"x-mailer"} and $mhead->{"x-mailer"} eq "m-FILTER"
defined $mhead->{"x-mailer"} $mhead->{"x-mailer"} eq "m-FILTER"
Truth table100%3/3
A and B
A= defined $mhead->{"x-mailer"}B= $mhead->{"x-mailer"} eq "m-FILTER"
ABresult
0X0
100
111
29 903 ▶ $proceedsto ||= 1 if grep { index($$mbody, $_) > 1 } @$boundaries;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($$mbody, $_) > 1;} @$boundaries 27 876 903
Condition100%2/2
$proceedsto ||= 1
l!l
225
MC/DC100%1/1
$proceedsto ||= 1
$proceedsto
Truth table100%2/2
A
A= $proceedsto
Aresult
11
00
30 903 ▶ $proceedsto ||= 1 if grep { index($$mbody, $_) > 1 } $startingof->{'command'}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($$mbody, $_) > 1;} @{$$startingof{"command"}} 27 876 903
Condition50%1/2
$proceedsto ||= 1
l!l
270
MC/DC0%0/1
$proceedsto ||= 1
$proceedsto
Truth table50%1/2
A
A= $proceedsto
Aresult
11
00
31 903 ▶ $proceedsto ||= 1 if grep { index($$mbody, $_) > 1 } $startingof->{'error'}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($$mbody, $_) > 1;} @{$$startingof{"error"}} 27 876 903
Condition50%1/2
$proceedsto ||= 1
l!l
270
MC/DC0%0/1
$proceedsto ||= 1
$proceedsto
Truth table50%1/2
A
A= $proceedsto
Aresult
11
00
32 903 ▶ return undef unless $proceedsto;
Branch: 1 branch
BranchTrueFalseTotal
unless $proceedsto 876 27 903
33  
34 27 ▶ my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries) // return undef; return undef unless $emailparts->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $emailparts->[0] 0 27 27
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
270
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
35 27 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef;
36 27 my $readcursor = 0; # (Integer) Points the current cursor position
37 27 my $recipients = 0; # (Integer) The number of 'Final-Recipient' header
38 27 my $markingset = {'diagnosis' => 0, 'command' => 0};
39  
40 27 for my $e ( split("\n", $emailparts->[0]) ) {
41 # Read error messages and delivery status lines from the head of the email to the previous
42 # line of the beginning of the original message.
43 351 ▶ unless( $readcursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readcursor) 162 189 351
44 # Beginning of the bounce message or message/delivery-status part
45 162 ▶ if( index($e, '@') > 1 && index($e, ' ') < 0 && Sisimai::Address->is_emailaddress($e) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($e, "\@") > 1 and index($e, " ") == -1 and "Sisimai::Address"->is_emailaddress($e)) 27 135 162
Condition83%5/6
index($e, "\@") > 1 and index($e, " ") == -1 and "Sisimai::Address"->is_emailaddress($e)
!ll&&!rl&&r
1201527
index($e, "\@") > 1 and index($e, " ") == -1
!ll&&!rl&&r
120042
MC/DC66%2/3
index($e, "\@") > 1 and index($e, " ") == -1 and "Sisimai::Address"->is_emailaddress($e)
index($e, "\@") > 1 index($e, " ") == -1 "Sisimai::Address"->is_emailaddress($e)
Truth table75%3/4
A and B and C
A= index($e, "\@") > 1B= index($e, " ") == -1C= "Sisimai::Address"->is_emailaddress($e)
ABCresult
0XX0
10X0
1100
1111
46 27 $readcursor |= $indicators->{'deliverystatus'};
47 }
48 }
49 351 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq "" 216 135 351
Condition100%3/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
l!l&&r!l&&!r
13581135
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
50  
51 # このメールは「m-FILTER」が自動的に生成して送信しています。
52 # メールサーバーとの通信中、下記の理由により
53 # このメールは送信できませんでした。
54 #
55 # 以下のメールアドレスへの送信に失敗しました。
56 # kijitora@example.jp
57 #
58 #
59 # -------server message
60 # 550 5.1.1 unknown user <kijitora@example.jp>
61 #
62 # -------SMTP command
63 # DATA
64 #
65 # -------original message
66 135 $v = $dscontents->[-1];
67  
68 135 ▶ if( index($e, '@') > 0 && index($e, ' ') < 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (index($e, '@') > 0 and index($e, ' ') == -1) { } 27 108 135
elsif (length $e == 4 and index($e, ' ') == -1) { } 27 81 108
Condition100%3/3
index($e, "\@") > 0 and index($e, " ") == -1
!ll&&!rl&&r
921627
MC/DC100%2/2
index($e, "\@") > 0 and index($e, " ") == -1
index($e, "\@") > 0 index($e, " ") == -1
Truth table100%3/3
A and B
A= index($e, "\@") > 0B= index($e, " ") == -1
ABresult
0X0
100
111
69 # 以下のメールアドレスへの送信に失敗しました。
70 # kijitora@example.jp
71 27 ▶ if( $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 0 27 27
72 # There are multiple recipient addresses in the message body.
73 0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
74 0 $v = $dscontents->[-1];
75 }
76 27 $v->{'recipient'} = $e;
77 27 $recipients++;
78  
79 ▶ } elsif( length $e == 4 && index($e, ' ') < 0 ) {
Condition66%2/3
length $e == 4 and index($e, " ") == -1
!ll&&!rl&&r
81027
MC/DC50%1/2
length $e == 4 and index($e, " ") == -1
length $e == 4 index($e, " ") == -1
Truth table66%2/3
A and B
A= length $e == 4B= index($e, " ") == -1
ABresult
0X0
100
111
80 # -------SMTP command
81 # DATA
82 27 ▶ next if $v->{'command'};
Branch: 1 branch
BranchTrueFalseTotal
if $v->{"command"} 0 27 27
83 27 ▶ $v->{'command'} = $e if $markingset->{'command'};
Branch: 1 branch
BranchTrueFalseTotal
if $markingset->{"command"} 27 0 27
84  
85 } else {
86 # Get error message and SMTP command
87 81 ▶ if( $e eq $startingof->{'error'}->[0] ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($e eq $startingof->{'error'}[0]) { } 27 54 81
elsif ($e eq $startingof->{'command'}[0]) { } 27 27 54
88 # -------server message
89 27 $markingset->{'diagnosis'} = 1;
90  
91 } elsif( $e eq $startingof->{'command'}->[0] ) {
92 # -------SMTP command
93 27 $markingset->{'command'} = 1;
94  
95 } else {
96 # 550 5.1.1 unknown user <kijitora@example.jp>
97 27 ▶ next if index($e, '-') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, "-") == 0 0 27 27
98 27 ▶ next if $v->{'diagnosis'};
Branch: 1 branch
BranchTrueFalseTotal
if $v->{"diagnosis"} 0 27 27
99 27 $v->{'diagnosis'} = $e;
100 }
101 } # End of error message part
102 }
103 27 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 0 27 27
104  
105 27 for my $e ( @$dscontents ) {
106 # Get localhost and remote host name from Received header.
107 27 ▶ next unless scalar $mhead->{'received'}->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$mhead->{"received"}} 0 27 27
108 27 my $rheads = $mhead->{'received'};
109 27 my $rhosts = Sisimai::RFC5322->received($rheads->[-1]);
110  
111 27 ▶ $e->{'lhost'} ||= shift Sisimai::RFC5322->received($rheads->[0])->@*;
Condition33%1/3
$e->{"lhost"} ||= shift @{"Sisimai::RFC5322"->received($rheads->[0])}
l!l&&r!l&&!r
0270
MC/DC0%0/2
$e->{"lhost"} ||= shift @{"Sisimai::RFC5322"->received($rheads->[0])}
$e->{"lhost"} shift @{"Sisimai::RFC5322"->received($rheads->[0])}
Truth table33%1/3
A ||= B
A= $e->{"lhost"}B= shift @{"Sisimai::RFC5322"->received($rheads->[0])}
ABresult
1X1
011
000
112 27 for my $ee ( $rhosts->[0], $rhosts->[1] ) {
113 # Avoid "... by m-FILTER"
114 54 ▶ next unless rindex($ee, '.') > -1;
Branch: 1 branch
BranchTrueFalseTotal
unless rindex($ee, ".") != -1 27 27 54
115 27 $e->{'rhost'} = $ee;
116 }
117 }
118 27 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
119 }
120  
121 38 1;
122 __END__
« Sisimai/Lhost/ApacheJames.pm ↑ Summary Sisimai/Lhost/EZweb.pm »