Sisimai/Lhost/OpenSMTPD.pm

filter: Statementstmt 100% 44 / 44 Branchbran 85.0% 17 / 20 Conditioncond 77.7% 7 / 9 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 91.8% 79 / 86 CC 16 SCAR 25.3
CC
16
Cov
93%
inquire
16.1
BEGIN
1.0
BEGIN
1.0
CRAP 12.5
« Sisimai/RFC1894.pm ↑ Summary Sisimai/Rhost/Microsoft.pm »
1 package Sisimai::Lhost::OpenSMTPD;
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 { 'OpenSMTPD: https://www.opensmtpd.org/' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
8 1121 ▶sub inquire {
Subroutine inquire: called CC=16 SCAR=27.8
Pod documented
9 # Detect an error from OpenSMTPD
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 1121 my $class = shift;
16 1121 ▶ my $mhead = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
11201
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
17 1120 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
11191
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18  
19 1119 ▶ return undef unless index($mhead->{'subject'}, 'Delivery status notification') > -1;
Branch: 1 branch
BranchTrueFalseTotal
unless index($mhead->{"subject"}, "Delivery status notification") != -1 1022 97 1119
20 97 ▶ return undef unless index($mhead->{'from'}, 'Mailer Daemon <') > -1;
Branch: 1 branch
BranchTrueFalseTotal
unless index($mhead->{"from"}, "Mailer Daemon <") != -1 26 71 97
21 71 ▶ return undef unless grep { rindex($_, ' (OpenSMTPD) with ') > -1 } $mhead->{'received'}->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {rindex($_, " (OpenSMTPD) with ") != -1;} @{$$mhead{"received"}} 0 71 71
22  
23 71 state $indicators = __PACKAGE__->INDICATORS;
24 71 state $boundaries = [' Below is a copy of the original message:'];
25 71 state $startingof = {
26 # http://www.openbsd.org/cgi-bin/man.cgi?query=smtpd&sektion=8
27 # opensmtpd-5.4.2p1/smtpd/
28 # bounce.c/317:#define NOTICE_INTRO \
29 # bounce.c/318: " Hi!\n\n" \
30 # bounce.c/319: " This is the MAILER-DAEMON, please DO NOT REPLY to this e-mail.\n"
31 # bounce.c/320:
32 # bounce.c/321:const char *notice_error =
33 # bounce.c/322: " An error has occurred while attempting to deliver a message for\n"
34 # bounce.c/323: " the following list of recipients:\n\n";
35 # bounce.c/324:
36 # bounce.c/325:const char *notice_warning =
37 # bounce.c/326: " A message is delayed for more than %s for the following\n"
38 # bounce.c/327: " list of recipients:\n\n";
39 # bounce.c/328:
40 # bounce.c/329:const char *notice_warning2 =
41 # bounce.c/330: " Please note that this is only a temporary failure report.\n"
42 # bounce.c/331: " The message is kept in the queue for up to %s.\n"
43 # bounce.c/332: " You DO NOT NEED to re-send the message to these recipients.\n\n";
44 # bounce.c/333:
45 # bounce.c/334:const char *notice_success =
46 # bounce.c/335: " Your message was successfully delivered to these recipients.\n\n";
47 # bounce.c/336:
48 # bounce.c/337:const char *notice_relay =
49 # bounce.c/338: " Your message was relayed to these recipients.\n\n";
50 # bounce.c/339:
51 'message' => [' This is the MAILER-DAEMON, please DO NOT REPLY to this'],
52 };
53  
54 71 ▶ my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries) // return undef; return undef unless $emailparts->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $emailparts->[0] 0 71 71
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
710
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
55 71 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef;
56 71 my $readcursor = 0; # (Integer) Points the current cursor position
57 71 my $recipients = 0; # (Integer) The number of 'Final-Recipient' header
58  
59 71 for my $e ( split("\n", $emailparts->[0]) ) {
60 # Read error messages and delivery status lines from the head of the email to the previous
61 # line of the beginning of the original message.
62 788 ▶ unless( $readcursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readcursor) 303 485 788
63 # Beginning of the bounce message or message/delivery-status part
64 303 ▶ $readcursor |= $indicators->{'deliverystatus'} if index($e, $startingof->{'message'}->[0]) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, $startingof->{"message"}[0]) == 0 71 232 303
65 303 next;
66 }
67 485 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq "" 172 313 485
Condition66%2/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
l!l&&r!l&&!r
0172313
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
68  
69 # Hi!
70 #
71 # This is the MAILER-DAEMON, please DO NOT REPLY to this e-mail.
72 #
73 # An error has occurred while attempting to deliver a message for
74 # the following list of recipients:
75 #
76 # kijitora@example.jp: 550 5.2.2 <kijitora@example>... Mailbox Full
77 #
78 # Below is a copy of the original message:
79 313 $v = $dscontents->[-1];
80  
81 313 ▶ if( Sisimai::String->aligned(\$e, ['@', ' ']) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Sisimai::String"->aligned(\$e, ["\@", " "])) 81 232 313
82 # kijitora@example.jp: 550 5.2.2 <kijitora@example.jp>... Mailbox Full
83 81 ▶ if( $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 10 71 81
84 # There are multiple recipient addresses in the message body.
85 10 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
86 10 $v = $dscontents->[-1];
87 }
88 81 $v->{'recipient'} = substr($e, 0, index($e, ':'));
89 81 $v->{'diagnosis'} = substr($e, index($e, ':') + 1, );
90 81 $recipients++;
91 }
92 }
93 71 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 0 71 71
94 71 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
95 }
96  
97 41 1;
98 __END__
« Sisimai/RFC1894.pm ↑ Summary Sisimai/Rhost/Microsoft.pm »