Sisimai/Lhost/GoogleWorkspace.pm

filter: Statementstmt 96.3% 52 / 54 Branchbran 87.5% 21 / 24 Conditioncond 91.6% 11 / 12 MC/DCmcdc 85.7% 6 / 7 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 93.3% 98 / 105 CC 21 SCAR 28.5
CC
21
Cov
93%
inquire
21.2
BEGIN
1.0
BEGIN
1.0
CRAP 17.3
« Sisimai/Lhost/DeutscheTelekom.pm ↑ Summary Sisimai/Lhost/Activehunter.pm »
1 package Sisimai::Lhost::GoogleWorkspace;
2 40 ▶use parent 'Sisimai::Lhost';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 40 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶sub description { "Google Workspace: https://workspace.google.com/" }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
8 1050 ▶sub inquire {
Subroutine inquire: called CC=21 SCAR=30.5
Pod documented
9 # Detect an error from Google Workspace (Transfer from the Google Workspace to the destination host)
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.21.0
15 1050 my $class = shift;
16 1050 ▶ my $mhead = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
10491
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
17 1049 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
10481
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18  
19 1048 ▶ return undef if index($$mbody, "\nDiagnostic-Code:") > -1 || index($$mbody, "\nFinal-Recipient:") > -1;
Branch: 1 branch
BranchTrueFalseTotal
if index($$mbody, "\nDiagnostic-Code:") != -1 or index($$mbody, "\nFinal-Recipient:") != -1 749 299 1048
Condition100%3/3
index($$mbody, "\nDiagnostic-Code:") != -1 or index($$mbody, "\nFinal-Recipient:") != -1
l!l&&r!l&&!r
67970299
MC/DC100%2/2
index($$mbody, "\nDiagnostic-Code:") != -1 or index($$mbody, "\nFinal-Recipient:") != -1
index($$mbody, "\nDiagnostic-Code:") != -1 index($$mbody, "\nFinal-Recipient:") != -1
Truth table100%3/3
A or B
A= index($$mbody, "\nDiagnostic-Code:") != -1B= index($$mbody, "\nFinal-Recipient:") != -1
ABresult
1X1
011
000
20 299 ▶ return undef unless rindex($mhead->{'from'}, '<mailer-daemon@googlemail.com>') > -1;
Branch: 1 branch
BranchTrueFalseTotal
unless rindex($mhead->{"from"}, "<mailer-daemon\@googlemail.com>") != -1 147 152 299
21 152 ▶ return undef unless index($mhead->{'subject'}, "Delivery Status Notification") > -1;
Branch: 1 branch
BranchTrueFalseTotal
unless index($mhead->{"subject"}, "Delivery Status Notification") != -1 0 152 152
22  
23 152 require Sisimai::Eb;
24 152 state $indicators = __PACKAGE__->INDICATORS;
25 152 state $boundaries = ["Content-Type: message/rfc822", "Content-Type: text/rfc822-headers"];
26 152 state $startingof = {
27 'message' => ["** "],
28 'error' => ["The response was:", "The response from the remote server was:"],
29 };
30 152 state $messagesof = {
31 $Sisimai::Eb::ReUSER => ["because the address couldn't be found. Check for typos or unnecessary spaces and try again."],
32 };
33  
34 152 ▶ my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries) // return undef; return undef unless $emailparts->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $emailparts->[0] 0 152 152
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
1520
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 152 my $dscontents = [__PACKAGE__->DELIVERYSTATUS];
36 152 my $entiremesg = "";
37 152 my $readcursor = 0; # (Integer) Points the current cursor position
38 152 my $recipients = 0;
39  
40 152 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 7584 ▶ unless( $readcursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readcursor) 7524 60 7584
44 # Beginning of the bounce message or message/delivery-status part
45 7524 ▶ if( index($e, $startingof->{'message'}->[0]) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($e, $startingof->{"message"}[0]) == 0) 5 7519 7524
46 # ** Message not delivered **
47 5 $readcursor |= $indicators->{'deliverystatus'};
48 5 $entiremesg .= $e." ";
49 }
50 }
51 7584 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq "" 7549 35 7584
Condition100%3/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
l!l&&r!l&&!r
75193035
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
52  
53 # ** Message not delivered **
54 # You're sending this from a different address or alias using the 'Send mail as' feature.
55 # The settings for your 'Send mail as' account are misconfigured or out of date. Check those settings and try resending.
56 # Learn more here: https://support.google.com/mail/?p=CustomFromDenied
57 # The response was:
58 # Unspecified Error (SENT_SECOND_EHLO): Smtp server does not advertise AUTH capability
59 35 ▶ next if index($e, "Content-Type: ") == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, "Content-Type: ") == 0 5 30 35
60 30 $entiremesg .= $e." ";
61 }
62  
63 152 ▶ while( $recipients == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recipients == 0) 152 5 157
64 # Pick the recipient address from the value of To: header of the original message after
65 # Content-Type: message/rfc822 field
66 152 ▶ my $p0 = index($emailparts->[1], "\nTo:"); last if $p0 < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $p0 < 0 147 5 152
67 5 my $p1 = index($emailparts->[1], "\n", $p0 + 2);
68 5 my $cv = Sisimai::Address->s3s4(substr($emailparts->[1], $p0 + 4, $p1 - $p0));
69 5 $dscontents->[0]->{'recipient'} = $cv;
70 5 $recipients++;
71 }
72 152 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 147 5 152
73  
74 5 $dscontents->[0]->{'diagnosis'} = $entiremesg;
75 5 for my $e ( @$dscontents ) {
76 5 for my $r ( keys %$messagesof ) {
77 # Guess an reason of the bounce
78 5 ▶ next unless grep { index($e->{'diagnosis'}, $_) > -1 } $messagesof->{ $r }->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {index($e->{"diagnosis"}, $_) != -1;} @{$$messagesof{$r}} 5 0 5
79 0 $e->{'reason'} = $r; last;
80 }
81 }
82 5 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
83 }
84  
85 40 1;
86 __END__
« Sisimai/Lhost/DeutscheTelekom.pm ↑ Summary Sisimai/Lhost/Activehunter.pm »