| 1 | package Sisimai::Lhost::MailFoundry; | ||||||||||||||||||||||||||||
| 2 | 36 | ▶ | use parent 'Sisimai::Lhost'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 36 | ▶ | use v5.26; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 36 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 36 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | sub description { 'MailFoundry: https://www.barracuda.com/' } | ||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 8 | 878 | ▶ | sub inquire { | ||||||||||||||||||||||||||
|
Subroutine
inquire: called CC=19 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 9 | # Detect an error from MailFoundry | ||||||||||||||||||||||||||||
| 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.1.1 | ||||||||||||||||||||||||||||
| 15 | 878 | my $class = shift; | |||||||||||||||||||||||||||
| 16 | 878 | ▶ | 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 | 877 | ▶ | 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 | 876 | ▶ | return undef unless $mhead->{'subject'} eq 'Message delivery has failed'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 11 | ▶ | return undef unless grep { rindex($_, '(MAILFOUNDRY) id') > -1 } $mhead->{'received'}->@*; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 11 | state $indicators = __PACKAGE__->INDICATORS; | |||||||||||||||||||||||||||
| 23 | 11 | state $boundaries = ['Content-Type: message/rfc822']; | |||||||||||||||||||||||||||
| 24 | 11 | state $startingof = { | |||||||||||||||||||||||||||
| 25 | 'message' => ['Unable to deliver message to:'], | ||||||||||||||||||||||||||||
| 26 | 'error' => ['Delivery failed for the following reason:'], | ||||||||||||||||||||||||||||
| 27 | }; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 11 | ▶ | 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 | 11 | my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef; | |||||||||||||||||||||||||||
| 31 | 11 | my $readcursor = 0; # (Integer) Points the current cursor position | |||||||||||||||||||||||||||
| 32 | 11 | my $recipients = 0; # (Integer) The number of 'Final-Recipient' header | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 11 | for my $e ( split("\n", $emailparts->[0]) ) { | |||||||||||||||||||||||||||
| 35 | # Read error messages and delivery status lines from the head of the email to the previous | ||||||||||||||||||||||||||||
| 36 | # line of the beginning of the original message. | ||||||||||||||||||||||||||||
| 37 | 77 | ▶ | unless( $readcursor ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | # Beginning of the bounce message or message/delivery-status part | ||||||||||||||||||||||||||||
| 39 | 33 | ▶ | $readcursor |= $indicators->{'deliverystatus'} if index($e, $startingof->{'message'}->[0]) == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 77 | ▶ | next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
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 ""
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # Unable to deliver message to: <kijitora@example.org> | ||||||||||||||||||||||||||||
| 44 | # Delivery failed for the following reason: | ||||||||||||||||||||||||||||
| 45 | # Server mx22.example.org[192.0.2.222] failed with: 550 <kijitora@example.org> No such user here | ||||||||||||||||||||||||||||
| 46 | # | ||||||||||||||||||||||||||||
| 47 | # This has been a permanent failure. No further delivery attempts will be made. | ||||||||||||||||||||||||||||
| 48 | 44 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 44 | ▶ | if( index($e, 'Unable to deliver message to: <') == 0 && index($e, '@') > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
index($e, "Unable to deliver message to: <") == 0 and index($e, "\@") > 1
MC/DC50%1/2
index($e, "Unable to deliver message to: <") == 0 and index($e, "\@") > 1
index($e, "Unable to deliver message to: <") == 0
index($e, "\@") > 1
Truth table66%2/3
A and B
A= index($e, "Unable to deliver message to: <") == 0B= index($e, "\@") > 1
| |||||||||||||||||||||||||||||
| 51 | # Unable to deliver message to: <kijitora@example.org> | ||||||||||||||||||||||||||||
| 52 | 11 | ▶ | if( $v->{'recipient'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | # There are multiple recipient addresses in the message body. | ||||||||||||||||||||||||||||
| 54 | 0 | push @$dscontents, __PACKAGE__->DELIVERYSTATUS; | |||||||||||||||||||||||||||
| 55 | 0 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 11 | $v->{'recipient'} = Sisimai::Address->s3s4(substr($e, index($e, '<'), )); | |||||||||||||||||||||||||||
| 58 | 11 | $recipients++; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||||||||||
| 61 | # Delivery failed for the following reason: | ||||||||||||||||||||||||||||
| 62 | 33 | ▶ | if( $e eq $startingof->{'error'}->[0] ) { $v->{'diagnosis'} = $e; next } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 22 | ▶ | next unless $v->{'diagnosis'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 22 | ▶ | next if index($e, '-') == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 22 | $v->{'diagnosis'} .= ' '.$e; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 11 | ▶ | return undef unless $recipients; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 11 | return {"ds" => $dscontents, "rfc822" => $emailparts->[1]}; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 36 | 1; | |||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||