| 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)
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 17 | 1069 | ▶ | 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 | 1068 | ▶ | return undef unless index($mhead->{'subject'}, 'Mail delivery failed') > -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 198 | ▶ | return undef unless grep { rindex($_, ' (DragonFly Mail Agent') > -1 } $mhead->{'received'}->@*; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
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)
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 43 | 150 | next; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 755 | ▶ | 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 ""
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
index($e, " did not like our ") == -1 or length $v->{"rhost"} > 0
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
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 135 | my $p = [split(' ', $e, 3)]; | |||||||||||||||||||||||||||
| 77 | 135 | ▶ | $v->{'rhost'} = index($p->[0], '.') > 1 ? $p->[0] : $p->[1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 135 | ▶ | $v->{'command'} = Sisimai::SMTP::Command->find($e) || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
'Sisimai::SMTP::Command'->find($e) || ''
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)
| |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 150 | ▶ | return undef unless $recipients; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 150 | return {"ds" => $dscontents, "rfc822" => $emailparts->[1]}; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 41 | 1; | |||||||||||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||||||||||