Sisimai/Lhost/DragonFly.pm

filter: Statementstmt 95.9% 47 / 49 Branchbran 77.2% 17 / 22 Conditioncond 71.4% 10 / 14 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 85.1% 86 / 101 CC 19 SCAR 27.9
CC
19
Cov
87%
inquire
20.3
BEGIN
1.0
BEGIN
1.0
CRAP 16.3
« Sisimai/Lhost/X1.pm ↑ Summary Sisimai/Lhost/Biglobe.pm »
1 package Sisimai::Lhost::DragonFly;
2 41 ▶use parent 'Sisimai::Lhost';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 41 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 41 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 41 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶sub description { 'DragonFly: https://www.dragonflybsd.org/handbook/mta/' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
8 1070 ▶sub inquire {
Subroutine inquire: called CC=19 SCAR=30.1
Pod documented
9 # Detect an error from DMA: DragonFly Mail Agent
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 v5.0.4
15 1070 my $class = shift;
16 1070 ▶ my $mhead = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
10691
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
17 1069 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
10681
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18  
19 1068 ▶ return undef unless index($mhead->{'subject'}, 'Mail delivery failed') > -1;
Branch: 1 branch
BranchTrueFalseTotal
unless index($mhead->{"subject"}, "Mail delivery failed") != -1 870 198 1068
20 198 ▶ return undef unless grep { rindex($_, ' (DragonFly Mail Agent') > -1 } $mhead->{'received'}->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {rindex($_, " (DragonFly Mail Agent") != -1;} @{$$mhead{"received"}} 48 150 198
21  
22 150 state $indicators = __PACKAGE__->INDICATORS;
23 150 state $boundaries = ['Original message follows.', 'Message headers follow'];
24 150 state $startingof = {
25 # https://github.com/corecode/dma/blob/ffad280aa40c242aa9a2cb9ca5b1b6e8efedd17e/mail.c#L84
26 'message' => ['This is the DragonFly Mail Agent '],
27 };
28  
29 150 ▶ my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries) // return undef; return undef unless $emailparts->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $emailparts->[0] 0 150 150
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
1500
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
30 150 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef;
31 150 my $readcursor = 0; # (Integer) Points the current cursor position
32 150 my $recipients = 0; # (Integer) The number of 'Final-Recipient' header
33  
34 150 require Sisimai::Address;
35 150 require Sisimai::SMTP::Command;
36  
37 150 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 905 ▶ unless( $readcursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readcursor) 150 755 905
41 # Beginning of the bounce message or message/delivery-status part
42 150 ▶ $readcursor |= $indicators->{'deliverystatus'} if index($e, $startingof->{'message'}->[0]) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, $startingof->{"message"}[0]) == 0 150 0 150
43 150 next;
44 }
45 755 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq "" 300 455 755
Condition66%2/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
l!l&&r!l&&!r
0300455
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
46  
47 # This is the DragonFly Mail Agent v0.13 at df.example.jp.
48 #
49 # There was an error delivering your mail to <kijitora@example.com>.
50 #
51 # email.example.jp [192.0.2.25] did not like our RCPT TO:
52 # 552 5.2.2 <kijitora@example.com>: Recipient address rejected: Mailbox full
53 #
54 # Original message follows.
55 455 $v = $dscontents->[-1];
56  
57 455 ▶ if( index($e, 'There was an error delivering your mail to <') == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($e, 'There was an error delivering your mail to <') == 0) { } 150 305 455
58 # email.example.jp [192.0.2.25] did not like our RCPT TO:
59 # 552 5.2.2 <kijitora@example.com>: Recipient address rejected: Mailbox full
60 150 ▶ if( $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 0 150 150
61 # There are multiple recipient addresses in the message body.
62 0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
63 0 $v = $dscontents->[-1];
64 }
65 150 $v->{'recipient'} = Sisimai::Address->s3s4(substr($e, index($e, '<'), -1));
66 150 $recipients++;
67  
68 } else {
69 # Pick the error message
70 305 $v->{'diagnosis'} .= $e;
71  
72 # Pick the remote hostname, and the SMTP command
73 # net.c:500| snprintf(errmsg, sizeof(errmsg), "%s [%s] did not like our %s:\n%s",
74 305 ▶ next if index($e, ' did not like our ') < 0 || length $v->{'rhost'} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, " did not like our ") == -1 or length $v->{"rhost"} > 0 170 135 305
Condition66%2/3
index($e, " did not like our ") == -1 or length $v->{"rhost"} > 0
l!l&&r!l&&!r
1700135
MC/DC50%1/2
index($e, " did not like our ") == -1 or length $v->{"rhost"} > 0
index($e, " did not like our ") == -1 length $v->{"rhost"} > 0
Truth table66%2/3
A or B
A= index($e, " did not like our ") == -1B= length $v->{"rhost"} > 0
ABresult
1X1
011
000
75  
76 135 my $p = [split(' ', $e, 3)];
77 135 ▶ $v->{'rhost'} = index($p->[0], '.') > 1 ? $p->[0] : $p->[1];
Branch: 1 branch
BranchTrueFalseTotal
index($p->[0], '.') > 1 ? : 135 0 135
78 135 ▶ $v->{'command'} = Sisimai::SMTP::Command->find($e) || '';
Condition50%1/2
'Sisimai::SMTP::Command'->find($e) || ''
l!l
1350
MC/DC0%0/1
'Sisimai::SMTP::Command'->find($e) || ''
'Sisimai::SMTP::Command'->find($e)
Truth table50%1/2
A
A= 'Sisimai::SMTP::Command'->find($e)
Aresult
11
00
79 }
80 }
81 150 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 0 150 150
82 150 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
83 }
84  
85 41 1;
86 __END__
« Sisimai/Lhost/X1.pm ↑ Summary Sisimai/Lhost/Biglobe.pm »