Sisimai/Lhost/ApacheJames.pm

filter: Statementstmt 96.6% 58 / 60 Branchbran 71.7% 33 / 46 Conditioncond 55.5% 10 / 18 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 79.5% 113 / 142 CC 33 SCAR 36.2
CC
33
Cov
81%
inquire
42.7
BEGIN
1.0
BEGIN
1.0
CRAP 37.2
« Sisimai/Lhost/KDDI.pm ↑ Summary Sisimai/Lhost/mFILTER.pm »
1 package Sisimai::Lhost::ApacheJames;
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 { 'James: https://james.apache.org/' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
8 888 ▶sub inquire {
Subroutine inquire: called CC=33 SCAR=37.5
Pod documented
9 # Detect an error from Apache James
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.26
15 888 my $class = shift;
16 888 ▶ my $mhead = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
8871
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
17 887 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
8861
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18 886 ▶ my $match = 0; $match ||= 1 if $mhead->{'subject'} eq '[BOUNCE]';
Branch: 1 branch
BranchTrueFalseTotal
if $mhead->{"subject"} eq "[BOUNCE]" 0 886 886
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
19 886 ▶ $match ||= 1 if defined $mhead->{'message-id'} && rindex($mhead->{'message-id'}, '.JavaMail.') > -1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $mhead->{"message-id"} and rindex($mhead->{"message-id"}, ".JavaMail.") != -1 6 880 886
Condition80%4/5
defined $mhead->{"message-id"} and rindex($mhead->{"message-id"}, ".JavaMail.") != -1
!ll&&!rl&&r
628186
$match ||= 1
l!l
06
MC/DC100%2/2
defined $mhead->{"message-id"} and rindex($mhead->{"message-id"}, ".JavaMail.") != -1
defined $mhead->{"message-id"} rindex($mhead->{"message-id"}, ".JavaMail.") != -1
MC/DC0%0/1
$match ||= 1
$match
Truth table100%3/3
A and B
A= defined $mhead->{"message-id"}B= rindex($mhead->{"message-id"}, ".JavaMail.") != -1
ABresult
0X0
100
111
Truth table50%1/2
A
A= $match
Aresult
11
00
20 886 ▶ $match ||= 1 if grep { rindex($_, 'JAMES SMTP Server') > -1 } $mhead->{'received'}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if grep {rindex($_, "JAMES SMTP Server") != -1;} @{$$mhead{"received"}} 0 886 886
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
21 886 ▶ return undef unless $match;
Branch: 1 branch
BranchTrueFalseTotal
unless $match 880 6 886
22  
23 6 state $indicators = __PACKAGE__->INDICATORS;
24 6 state $boundaries = ["Content-Type: message/rfc822"];
25 6 state $startingof = {
26 # apache-james-2.3.2/src/java/org/apache/james/transport/mailets/
27 # AbstractNotify.java|124: out.println("Error message below:");
28 # AbstractNotify.java|128: out.println("Message details:");
29 "message" => ["Message details:"],
30 };
31  
32 6 ▶ my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries) // return undef; return undef unless $emailparts->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $emailparts->[0] 0 6 6
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
60
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
33 6 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = $dscontents->[-1];
34 6 my $readcursor = 0; # Points the current cursor position
35 6 my $recipients = 0; # The number of 'Final-Recipient' header
36 6 my $alternates = ["", "", "", ""]; # [Envelope-From, Header-From, Date, Subject]
37  
38 6 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 84 ▶ unless( $readcursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readcursor) 36 48 84
42 # Beginning of the bounce message or message/delivery-status part
43 36 ▶ if( index($e, $startingof->{"message"}->[0]) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($e, $startingof->{"message"}[0]) == 0) 6 30 36
44 # Message details:
45 # Subject: Nyaaan
46 6 $readcursor |= $indicators->{"deliverystatus"}; next;
47 }
48 30 ▶ $v->{"diagnosis"} .= $e." " if $e ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $e ne "" 18 12 30
49 30 next;
50 }
51 48 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq "" 0 48 48
Condition33%1/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
l!l&&r!l&&!r
0048
MC/DC0%0/2
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
($readcursor & $indicators->{"deliverystatus"}) == 0 $e eq ""
Truth table33%1/3
A or B
A= ($readcursor & $indicators->{"deliverystatus"}) == 0B= $e eq ""
ABresult
1X1
011
000
52  
53 # Message details:
54 # Subject: Nyaaan
55 # Sent date: Thu Apr 29 01:20:50 JST 2015
56 # MAIL FROM: shironeko@example.jp
57 # RCPT TO: kijitora@example.org
58 # From: Neko <shironeko@example.jp>
59 # To: kijitora@example.org
60 # Size (in bytes): 1024
61 # Number of lines: 64
62 48 ▶ if( index($e, " RCPT TO: ") == 0 ) {
Branch: 5 branches
BranchTrueFalseTotal
if (index($e, ' RCPT TO: ') == 0) { } 6 42 48
elsif (index($e, ' Sent date: ') == 0) { } 6 36 42
elsif (index($e, ' Subject: ') == 0) { } 6 30 36
elsif (index($e, ' MAIL FROM: ') == 0) { } 6 24 30
elsif (index($e, ' From: ') == 0) { } 6 18 24
63 # RCPT TO: kijitora@example.org
64 6 ▶ if( $v->{"recipient"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 0 6 6
65 # There are multiple recipient addresses in the message body.
66 0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
67 0 $v = $dscontents->[-1];
68 }
69 6 $v->{"recipient"} = substr($e, 12,);
70 6 $recipients++;
71  
72 } elsif( index($e, " Sent date: ") == 0 ) {
73 # Sent date: Thu Apr 29 01:20:50 JST 2015
74 6 $v->{"date"} = substr($e, 13,);
75 6 $alternates->[2] = $v->{"date"};
76  
77 } elsif( index($e, " Subject: ") == 0 ) {
78 # Subject: Nyaaan
79 6 $alternates->[3] = substr($e, 11,);
80  
81 } elsif( index($e, " MAIL FROM: ") == 0 ) {
82 # MAIL FROM: shironeko@example.jp
83 6 $alternates->[0] = substr($e, 13,);
84  
85 } elsif( index($e, " From: ") == 0 ) {
86 # From: Neko <shironeko@example.jp>
87 6 $alternates->[1] = substr($e, 8,);
88 }
89 }
90 6 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 0 6 6
91  
92 6 ▶ if( $emailparts->[1] eq "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($emailparts->[1] eq "") 6 0 6
93 # The original message is empty
94 6 ▶ $emailparts->[1] .= sprintf("From: %s\n", $alternates->[1]) if $alternates->[1] ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $alternates->[1] ne "" 6 0 6
95 6 ▶ $emailparts->[1] .= sprintf("Date: %s\n", $alternates->[2]) if $alternates->[2] ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $alternates->[2] ne "" 6 0 6
96 }
97 6 ▶ if( index($emailparts->[1], "Return-Path: ") < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($emailparts->[1], "Return-Path: ") == -1) 6 0 6
98 # Set the envelope from address as a Return-Path: header
99 6 ▶ $emailparts->[1] .= sprintf("Return-Path: <%s>\n", $alternates->[0]) if $alternates->[0] ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $alternates->[0] ne "" 6 0 6
100 }
101 6 ▶ if( index($emailparts->[1], "\nSubject: ") < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($emailparts->[1], "\nSubject: ") == -1) 6 0 6
102 # Set the envelope from address as a Return-Path: header
103 6 ▶ $emailparts->[1] .= sprintf("Subject: %s\n", $alternates->[3]) if $alternates->[3] ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $alternates->[3] ne "" 6 0 6
104 }
105 6 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
106 }
107  
108 38 1;
109 __END__
« Sisimai/Lhost/KDDI.pm ↑ Summary Sisimai/Lhost/mFILTER.pm »