Sisimai/Lhost/Verizon.pm

filter: Statementstmt 95.3% 82 / 86 Branchbran 79.6% 43 / 54 Conditioncond 53.8% 14 / 26 MC/DCmcdc 25.0% 4 / 16 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 79.4% 151 / 190 CC 42 SCAR 38.4
CC
42
Cov
84%
inquire
51.7
BEGIN
1.0
BEGIN
1.0
CRAP 46.3
« Sisimai/Lhost/Exchange2003.pm ↑ Summary Sisimai/Lhost/Courier.pm »
1 package Sisimai::Lhost::Verizon;
2 39 ▶use parent 'Sisimai::Lhost';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 39 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 39 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 39 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶sub description { 'Verizon: https://www.verizon.com/' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
8 899 ▶sub inquire {
Subroutine inquire: called CC=42 SCAR=39.5
Pod documented
9 # Detect an error from Verizon
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 899 my $class = shift;
16 899 ▶ my $mhead = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
8981
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
17 898 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
8971
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18  
19 897 ▶ return undef unless grep { rindex($_, '.vtext.com (') > -1 } $mhead->{'received'}->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {rindex($_, ".vtext.com (") != -1;} @{$$mhead{"received"}} 886 11 897
20 11 ▶ my $match = -1; $match = 1 if $mhead->{'from'} eq 'post_master@vtext.com';
Branch: 1 branch
BranchTrueFalseTotal
if $mhead->{"from"} eq "post_master\@vtext.com" 5 6 11
21 11 ▶ $match = 0 if Sisimai::String->aligned(\$mhead->{'from'}, ['sysadmin@', '.vzwpix.com']);
Branch: 1 branch
BranchTrueFalseTotal
if "Sisimai::String"->aligned(\$mhead->{"from"}, ["sysadmin\@", ".vzwpix.com"]) 6 5 11
22 11 ▶ return undef if $match < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $match < 0 0 11 11
23  
24 11 require Sisimai::Eb;
25 11 state $indicators = __PACKAGE__->INDICATORS;
26 11 my $boundaries = [];
27 11 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef;
28 11 my $emailparts = [];
29 11 my $readcursor = 0; # (Integer) Points the current cursor position
30 11 my $recipients = 0; # (Integer) The number of 'Final-Recipient' header
31 11 my $senderaddr = ''; # (String) Sender address in the message body
32 11 my $subjecttxt = ''; # (String) Subject of the original message
33 11 my $messagesof = {}; # (Ref->Hash) Error message patterns
34  
35 11 ▶ if( $match == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match == 1) { } 5 6 11
36 # vtext.com
37 5 my $markingsof = {'message' => ['Error: ']};
38 5 $messagesof = {
39 # The attempted recipient address does not exist.
40 $Sisimai::Eb::ReUSER => ['550 - Requested action not taken: no such user here'],
41 };
42 5 $boundaries = [Sisimai::RFC2045->boundary($mhead->{'content-type'}, 1)];
43 5 ▶ $emailparts = Sisimai::RFC5322->part($mbody, $boundaries) // return undef; return undef unless $emailparts->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $emailparts->[0] 0 5 5
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
50
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
44  
45 5 for my $e ( split("\n", $emailparts->[0]) ) {
46 # Read error messages and delivery status lines from the head of the email to the previous
47 # line of the beginning of the original message.
48 70 ▶ unless( $readcursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readcursor) 5 65 70
49 # Beginning of the bounce message or delivery status part
50 5 ▶ $readcursor |= $indicators->{'deliverystatus'} if index($e, $markingsof->{'message'}->[0]) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, $markingsof->{"message"}[0]) == 0 5 0 5
51 5 next;
52 }
53 65 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq "" 10 55 65
Condition66%2/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
l!l&&r!l&&!r
01055
MC/DC50%1/2
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
($readcursor & $indicators->{"deliverystatus"}) == 0 $e eq ""
Truth table66%2/3
A or B
A= ($readcursor & $indicators->{"deliverystatus"}) == 0B= $e eq ""
ABresult
1X1
011
000
54  
55 # Message details:
56 # Subject: Test message
57 # Sent date: Wed Jun 12 02:21:53 GMT 2013
58 # MAIL FROM: *******@hg.example.com
59 # RCPT TO: *****@vtext.com
60 55 $v = $dscontents->[-1];
61  
62 55 ▶ if( index($e, ' RCPT TO: ') == 0 ) {
Branch: 3 branches
BranchTrueFalseTotal
if (index($e, ' RCPT TO: ') == 0) { } 5 50 55
elsif (index($e, ' MAIL FROM: ') == 0) { } 5 45 50
elsif (index($e, ' Subject: ') == 0) { } 5 40 45
63 5 ▶ if( $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 0 5 5
64 # There are multiple recipient addresses in the message body.
65 0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
66 0 $v = $dscontents->[-1];
67 }
68 5 $v->{'recipient'} = substr($e, 11,);
69 5 $recipients++;
70 5 next;
71  
72 } elsif( index($e, ' MAIL FROM: ') == 0 ) {
73 # MAIL FROM: *******@hg.example.com
74 5 ▶ $senderaddr ||= substr($e, 13,);
Condition33%1/3
$senderaddr ||= substr($e, 13)
l!l&&r!l&&!r
050
MC/DC0%0/2
$senderaddr ||= substr($e, 13)
$senderaddr substr($e, 13)
Truth table33%1/3
A ||= B
A= $senderaddrB= substr($e, 13)
ABresult
1X1
011
000
75  
76 } elsif( index($e, ' Subject: ') == 0 ) {
77 # Subject:
78 5 ▶ $subjecttxt ||= substr($e, 11,);
Condition33%1/3
$subjecttxt ||= substr($e, 11)
l!l&&r!l&&!r
050
MC/DC0%0/2
$subjecttxt ||= substr($e, 11)
$subjecttxt substr($e, 11)
Truth table33%1/3
A ||= B
A= $subjecttxtB= substr($e, 11)
ABresult
1X1
011
000
79  
80 } else {
81 # 550 - Requested action not taken: no such user here
82 40 ▶ $v->{'diagnosis'} = $e if index($e, ' - ') > 2;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, " - ") > 2 5 35 40
83 }
84 }
85 } else {
86 # vzwpix.com
87 6 my $startingof = {'message' => ['Message could not be delivered to mobile']};
88 6 $messagesof = {$Sisimai::Eb::ReUSER => ['No valid recipients for this MM']};
89 6 $boundaries = [Sisimai::RFC2045->boundary($mhead->{'content-type'})];
90 6 ▶ $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
91 6 for my $e ( split("\n", $emailparts->[0]) ) {
92 # Read error messages and delivery status lines from the head of the email to the previous
93 # line of the beginning of the original message.
94 54 ▶ unless( $readcursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readcursor) 6 48 54
95 # Beginning of the bounce message or delivery status part
96 6 ▶ $readcursor |= $indicators->{'deliverystatus'} if index($e, $startingof->{'message'}->[0]) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, $startingof->{"message"}[0]) == 0 6 0 6
97 6 next;
98 }
99 48 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq "" 12 36 48
Condition66%2/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
l!l&&r!l&&!r
01236
MC/DC50%1/2
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
($readcursor & $indicators->{"deliverystatus"}) == 0 $e eq ""
Truth table66%2/3
A or B
A= ($readcursor & $indicators->{"deliverystatus"}) == 0B= $e eq ""
ABresult
1X1
011
000
100  
101 # Original Message:
102 # From: kijitora <kijitora@example.jp>
103 # To: 0000000000@vzwpix.com
104 # Subject: test for bounce
105 # Date: Wed, 20 Jun 2013 10:29:52 +0000
106 36 $v = $dscontents->[-1];
107  
108 36 ▶ if( index($e, 'To: ') == 0 ) {
Branch: 3 branches
BranchTrueFalseTotal
if (index($e, 'To: ') == 0) { } 6 30 36
elsif (index($e, 'From: ') == 0) { } 6 24 30
elsif (index($e, 'Subject: ') == 0) { } 6 18 24
109 6 ▶ if( $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 0 6 6
110 # There are multiple recipient addresses in the message body.
111 0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
112 0 $v = $dscontents->[-1];
113 }
114 6 $v->{'recipient'} = Sisimai::Address->s3s4(substr($e, 4,));
115 6 $recipients++;
116 6 next;
117  
118 } elsif( index($e, 'From: ') == 0 ) {
119 # From: kijitora <kijitora@example.jp>
120 6 ▶ $senderaddr ||= Sisimai::Address->s3s4(substr($e, 6,));
Condition33%1/3
$senderaddr ||= "Sisimai::Address"->s3s4(substr($e, 6))
l!l&&r!l&&!r
060
MC/DC0%0/2
$senderaddr ||= "Sisimai::Address"->s3s4(substr($e, 6))
$senderaddr "Sisimai::Address"->s3s4(substr($e, 6))
Truth table33%1/3
A ||= B
A= $senderaddrB= "Sisimai::Address"->s3s4(substr($e, 6))
ABresult
1X1
011
000
121  
122 } elsif( index($e, 'Subject: ') == 0 ) {
123 # Subject:
124 6 ▶ $subjecttxt ||= substr($e, 9,);
Condition33%1/3
$subjecttxt ||= substr($e, 9)
l!l&&r!l&&!r
060
MC/DC0%0/2
$subjecttxt ||= substr($e, 9)
$subjecttxt substr($e, 9)
Truth table33%1/3
A ||= B
A= $subjecttxtB= substr($e, 9)
ABresult
1X1
011
000
125  
126 } else {
127 # Message could not be delivered to mobile.
128 # Error: No valid recipients for this MM
129 18 ▶ $v->{'diagnosis'} = substr($e, 7,) if index($e, 'Error: ') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, "Error: ") == 0 6 12 18
130 }
131 }
132 }
133 11 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 0 11 11
134  
135 # Set the value of "MAIL FROM:" and "From:"
136 11 ▶ $emailparts->[1] .= sprintf("From: %s\n", $senderaddr) if index($emailparts->[1], "\nFrom: ") < 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($emailparts->[1], "\nFrom: ") == -1 11 0 11
137 11 ▶ $emailparts->[1] .= sprintf("Subject: %s\n", $subjecttxt) if index($emailparts->[1], "\nSubject: ") < 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($emailparts->[1], "\nSubject: ") == -1 11 0 11
138  
139 11 for my $e ( @$dscontents ) {
140 11 SESSION: for my $r ( keys %$messagesof ) {
141 # Verify each regular expression of session errors
142 11 ▶ next unless grep { index($e->{'diagnosis'}, $_) > -1 } $messagesof->{ $r }->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {index($e->{"diagnosis"}, $_) != -1;} @{$$messagesof{$r}} 0 11 11
143 11 $e->{'reason'} = $r;
144 11 last;
145 }
146 }
147 11 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
148 }
149  
150 39 1;
151 __END__
« Sisimai/Lhost/Exchange2003.pm ↑ Summary Sisimai/Lhost/Courier.pm »