Sisimai/Lhost/TrendMicro.pm

filter: Statementstmt 89.0% 49 / 55 Branchbran 71.8% 23 / 32 Conditioncond 76.6% 23 / 30 MC/DCmcdc 53.3% 8 / 15 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 79.2% 111 / 140 CC 31 SCAR 35.5
CC
31
Cov
81%
inquire
40.1
BEGIN
1.0
BEGIN
1.0
CRAP 34.7
« Sisimai/ARF.pm ↑ Summary Sisimai/RFC5322.pm »
1 package Sisimai::Lhost::TrendMicro;
2 42 ▶use parent 'Sisimai::Lhost';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 42 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 42 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 42 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶sub description { 'TREND VISION ONE(Email and Collaboration Security)' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
8 930 ▶sub inquire {
Subroutine inquire: called CC=31 SCAR=36.9
Pod documented
9 # Detect an error from TREND VISION ONE: Email and Collaboration Security
10 # https://www.trendmicro.com/en_us/business/products/email-and-collaboration.html
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.2
16 930 my $class = shift;
17 930 ▶ my $mhead = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
9291
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18 929 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
9281
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
19 928 my $tryto = [
20 'Mail could not be delivered',
21 'メッセージを配信できません。',
22 'メール配信に失敗しました',
23 ];
24 928 ▶ my $match = 0; $match ||= 1 if index($mhead->{'from'}, '"InterScan MSS"') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($mhead->{"from"}, "\"InterScan MSS\"") == 0 6 922 928
Condition50%1/2
$match ||= 1
l!l
06
MC/DC0%0/1
$match ||= 1
$match
Truth table50%1/2
A
A= $match
Aresult
11
00
25 928 ▶ $match ||= 1 if index($mhead->{'from'}, '"InterScan Notification"') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($mhead->{"from"}, "\"InterScan Notification\"") == 0 0 928 928
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
26 928 ▶ $match ||= 1 if grep { $mhead->{'subject'} eq $_ } @$tryto;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$mhead->{"subject"} eq $_;} @$tryto 16 912 928
Condition100%2/2
$match ||= 1
l!l
610
MC/DC100%1/1
$match ||= 1
$match
Truth table100%2/2
A
A= $match
Aresult
11
00
27 928 ▶ return undef unless $match;
Branch: 1 branch
BranchTrueFalseTotal
unless $match 912 16 928
28  
29 16 require Sisimai::Eb;
30 16 require Sisimai::SMTP::Command;
31 16 state $boundaries = ['Content-type: message/rfc822'];
32  
33 16 ▶ my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries) // return undef; return undef unless $emailparts->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $emailparts->[0] 0 16 16
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
160
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
34 16 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef;
35 16 my $recipients = 0; # (Integer) The number of 'Final-Recipient' header
36  
37 16 for my $e ( split("\n", $emailparts->[0]) ) {
38 # Read error messages and delivery status lines from the head of the email to the previous
39 # line of the beginning of the original message.
40 544 ▶ next unless length $e;
Branch: 1 branch
BranchTrueFalseTotal
unless length $e 136 408 544
41  
42 408 $v = $dscontents->[-1];
43 408 my $p1 = index($e, ' <<< '); # Sent <<< ...
44 408 my $p2 = index($e, ' >>> '); # Received >>> ...
45 408 ▶ if( index($e, '@') > 1 && index($e, ' <') > 1 && ($p1 > 1 || $p2 > 1 || index($e, 'Unable to deliver ') > -1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($e, "\@") > 1 and index($e, " <") > 1 and $p1 > 1 || $p2 > 1 || index($e, "Unable to deliver ") != -1) 22 386 408
Condition100%12/12
index($e, "\@") > 1 and index($e, " <") > 1 and $p1 > 1 || $p2 > 1 || index($e, "Unable to deliver ") != -1
!ll&&!rl&&r
3493722
index($e, "\@") > 1 and index($e, " <") > 1
!ll&&!rl&&r
3183159
$p1 > 1 or $p2 > 1 or index($e, "Unable to deliver ") != -1
l!l&&r!l&&!r
121037
$p1 > 1 or $p2 > 1
l!l&&r!l&&!r
6647
MC/DC100%5/5
index($e, "\@") > 1 and index($e, " <") > 1 and $p1 > 1 || $p2 > 1 || index($e, "Unable to deliver ") != -1
index($e, "\@") > 1 index($e, " <") > 1 $p1 > 1 $p2 > 1 index($e, "Unable to deliver ") != -1
Truth table100%6/6
A and B and C or D or E
A= index($e, "\@") > 1B= index($e, " <") > 1C= $p1 > 1D= $p2 > 1E= index($e, "Unable to deliver ") != -1
ABCDEresult
0XXXX0
10XXX0
110000
111XX1
1101X1
110011
46 # Sent <<< RCPT TO:<kijitora@example.co.jp>
47 # Received >>> 550 5.1.1 <kijitora@example.co.jp>... user unknown
48 # Received >>> 550 5.1.1 unknown user.
49 # Unable to deliver message to <kijitora@neko.example.jp>
50 # Unable to deliver message to <neko@example.jp> (and other recipients in the same domain).
51 22 my $cr = substr($e, rindex($e, '<') + 1, rindex($e, '>') - rindex($e, '<') - 1);
52 22 ▶ if( $v->{'recipient'} && $cr ne $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"} and $cr ne $v->{"recipient"}) 0 22 22
Condition66%2/3
$v->{"recipient"} and $cr ne $v->{"recipient"}
!ll&&!rl&&r
1660
MC/DC0%0/2
$v->{"recipient"} and $cr ne $v->{"recipient"}
$v->{"recipient"} $cr ne $v->{"recipient"}
Truth table66%2/3
A and B
A= $v->{"recipient"}B= $cr ne $v->{"recipient"}
ABresult
0X0
100
111
53 # There are multiple recipient addresses in the message body.
54 0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
55 0 $v = $dscontents->[-1];
56 }
57 22 $v->{'recipient'} = $cr;
58 22 ▶ $v->{'diagnosis'} = $e if index($e, 'Unable to deliver ') > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, "Unable to deliver ") != -1 10 12 22
59 22 $recipients = scalar @$dscontents;
60 }
61  
62 408 ▶ if( index($e, 'Sent <<< ') == 0 ) {
Branch: 3 branches
BranchTrueFalseTotal
if (index($e, 'Sent <<< ') == 0) { } 6 402 408
elsif (index($e, 'Received >>> ') == 0) { } 6 396 402
elsif ($p1 > 0 or $p2 > 0) { } 0 396 396
63 # Sent <<< RCPT TO:<kijitora@example.co.jp>
64 6 $v->{'command'} = Sisimai::SMTP::Command->find($e);
65  
66 } elsif( index($e, 'Received >>> ') == 0 ) {
67 # Received >>> 550 5.1.1 <kijitora@example.co.jp>... user unknown
68 6 $v->{'diagnosis'} = substr($e, index($e, ' >>> ') + 4, );
69  
70 ▶ } elsif( $p1 > 0 || $p2 > 0 ) {
Condition33%1/3
$p1 > 0 or $p2 > 0
l!l&&r!l&&!r
00396
MC/DC0%0/2
$p1 > 0 or $p2 > 0
$p1 > 0 $p2 > 0
Truth table33%1/3
A or B
A= $p1 > 0B= $p2 > 0
ABresult
1X1
011
000
71 # Error message in non-English
72 0 ▶ $v->{'command'} = Sisimai::SMTP::Command->find($e) if index($e, ' >>> ') > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, " >>> ") != -1 0 0 0
73 0 ▶ my $p3 = index($e, ' <<< '); next if $p3 == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $p3 == -1 0 0 0
74 0 $v->{'diagnosis'} = substr($e, $p3 + 4,);
75 }
76 }
77 16 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 0 16 16
78  
79 16 for my $e ( @$dscontents ) {
80 # Set default values if each value is empty.
81 16 ▶ $e->{'reason'} = $Sisimai::Eb::ReUSER if index($e->{'diagnosis'}, 'Unable to deliver') > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($e->{"diagnosis"}, "Unable to deliver") != -1 10 6 16
82 }
83 16 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
84 }
85  
86 42 1;
87 __END__
« Sisimai/ARF.pm ↑ Summary Sisimai/RFC5322.pm »