| 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)
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 17 | 1120 | ▶ | my $mbody = shift // return undef; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift() // (return undef)
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1119 | ▶ | return undef unless index($mhead->{'subject'}, 'Delivery status notification') > -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 97 | ▶ | return undef unless index($mhead->{'from'}, 'Mailer Daemon <') > -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 71 | ▶ | return undef unless grep { rindex($_, ' (OpenSMTPD) with ') > -1 } $mhead->{'received'}->@*; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
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)
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 65 | 303 | next; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 485 | ▶ | next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
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 ""
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 82 | # kijitora@example.jp: 550 5.2.2 <kijitora@example.jp>... Mailbox Full | ||||||||||||||||||||||||||||
| 83 | 81 | ▶ | if( $v->{'recipient'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 94 | 71 | return {"ds" => $dscontents, "rfc822" => $emailparts->[1]}; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 41 | 1; | |||||||||||||||||||||||||||
| 98 | __END__ | ||||||||||||||||||||||||||||