| 1 | package Sisimai::Lhost::Mimecast; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use parent 'Sisimai::Lhost'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use v5.26; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | sub description { 'Mimecast' } | ||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 8 | 12 | ▶ | sub inquire { | ||||||||||||||||||||||||||
|
Subroutine
inquire: called CC=31 SCAR=36.3
Pod
documented
| |||||||||||||||||||||||||||||
| 9 | # Detect an error from Mimecast: https://www.mimecast.com/ | ||||||||||||||||||||||||||||
| 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.5.0 | ||||||||||||||||||||||||||||
| 15 | 12 | my $class = shift; | |||||||||||||||||||||||||||
| 16 | 12 | ▶ | 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 | 11 | ▶ | 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 | # Subject: [Postmaster] Email Delivery Failure | ||||||||||||||||||||||||||||
| 20 | 10 | ▶ | my $match = 0; $match ||= 1 if index($mhead->{'subject'}, 'Email Delivery Failure') > -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$match ||= 1
MC/DC0%0/1
$match ||= 1
$match
Truth table50%1/2
A
A= $match
| |||||||||||||||||||||||||||||
| 21 | 10 | ▶ | if( defined $mhead->{'message-id'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | # Message-Id: <0123456789-1102117314000@us-mta-25.us.mimecast.lan> | ||||||||||||||||||||||||||||
| 23 | 10 | ▶ | $match ||= 1 if index($mhead->{'message-id'}, '.mimecast.lan>') > -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$match ||= 1
MC/DC0%0/1
$match ||= 1
$match
Truth table50%1/2
A
A= $match
| |||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | 10 | ▶ | return undef unless $match; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 10 | state $indicators = __PACKAGE__->INDICATORS; | |||||||||||||||||||||||||||
| 28 | 10 | state $boundaries = ['Content-Type: :message/rfc822']; # No such line in lhost-mimecast-* | |||||||||||||||||||||||||||
| 29 | 10 | state $startingof = {'message' => ['-- ']}; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 10 | ▶ | 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)
| |||||||||||||||||||||||||||||
| 32 | 10 | my $fieldtable = Sisimai::RFC1894->FIELDTABLE; | |||||||||||||||||||||||||||
| 33 | 10 | my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef; | |||||||||||||||||||||||||||
| 34 | 10 | my $permessage = {}; # (Hash) Store values of each Per-Message field | |||||||||||||||||||||||||||
| 35 | 10 | my $readcursor = 0; # (Integer) Points the current cursor position | |||||||||||||||||||||||||||
| 36 | 10 | my $recipients = 0; # (Integer) The number of 'Final-Recipient' header | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 10 | for my $e ( split("\n", $emailparts->[0]) ) { | |||||||||||||||||||||||||||
| 39 | # Read error messages and delivery status lines from the head of the email to the previous | ||||||||||||||||||||||||||||
| 40 | # line of the beginning of the original message. | ||||||||||||||||||||||||||||
| 41 | 240 | ▶ | unless( $readcursor ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | # Beginning of the bounce message or message/delivery-status part | ||||||||||||||||||||||||||||
| 43 | 35 | ▶ | $readcursor |= $indicators->{'deliverystatus'} if index($e, $startingof->{'message'}->[0]) > -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 240 | ▶ | 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 ""
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 165 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||
| 48 | 165 | ▶ | if( index($e, '-- ') == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | # An email that you attempted to send to the following address could not be delivered: | ||||||||||||||||||||||||||||
| 50 | # -- sabineko@neko.ef.example.org | ||||||||||||||||||||||||||||
| 51 | 30 | ▶ | my $cv = substr($e, 3,); if( index($cv, " ") < 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | # -- sotoneko@cat.example.com | ||||||||||||||||||||||||||||
| 53 | 10 | ▶ | if( $v->{'recipient'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | # There are multiple recipient addresses in the message body. | ||||||||||||||||||||||||||||
| 55 | 0 | push @$dscontents, __PACKAGE__->DELIVERYSTATUS; | |||||||||||||||||||||||||||
| 56 | 0 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 10 | $v->{'recipient'} = Sisimai::Address->s3s4($cv); | |||||||||||||||||||||||||||
| 59 | 10 | $recipients++; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | } else { | ||||||||||||||||||||||||||||
| 62 | # Deal each line begins with "-- " as an error message. | ||||||||||||||||||||||||||||
| 63 | # The problem appears to be : | ||||||||||||||||||||||||||||
| 64 | # -- Recipient email address is possibly incorrect | ||||||||||||||||||||||||||||
| 65 | # Additional information follows : | ||||||||||||||||||||||||||||
| 66 | # -- 5.4.1 Recipient address rejected: Access denied. | ||||||||||||||||||||||||||||
| 67 | 20 | $v->{'diagnosis'} .= $cv.' '; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } else { | ||||||||||||||||||||||||||||
| 70 | # Lines after Content-Type: message/delivery-status | ||||||||||||||||||||||||||||
| 71 | 135 | ▶ | if( my $f = Sisimai::RFC1894->match($e) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | # $e matched with any field defined in RFC3464 | ||||||||||||||||||||||||||||
| 73 | 40 | ▶ | next unless my $o = Sisimai::RFC1894->field($e); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 40 | ▶ | if( $o->[3] eq 'code' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | # Diagnostic-Code: SMTP; 550 5.1.1 <userunknown@example.jp>... User Unknown | ||||||||||||||||||||||||||||
| 77 | 5 | $v->{'spec'} = $o->[1]; | |||||||||||||||||||||||||||
| 78 | 5 | $v->{'diagnosis'} = $o->[2]; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | } else { | ||||||||||||||||||||||||||||
| 81 | # Other DSN fields defined in RFC3464 | ||||||||||||||||||||||||||||
| 82 | 35 | ▶ | next unless exists $fieldtable->{ $o->[0] }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 35 | ▶ | next if $o->[3] eq "host" && Sisimai::RFC1123->is_internethost($o->[2]) == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$o->[3] eq "host" and "Sisimai::RFC1123"->is_internethost($o->[2]) == 0
MC/DC0%0/2
$o->[3] eq "host" and "Sisimai::RFC1123"->is_internethost($o->[2]) == 0
$o->[3] eq "host"
"Sisimai::RFC1123"->is_internethost($o->[2]) == 0
Truth table66%2/3
A and B
A= $o->[3] eq "host"B= "Sisimai::RFC1123"->is_internethost($o->[2]) == 0
| |||||||||||||||||||||||||||||
| 84 | 35 | $v->{ $fieldtable->{ $o->[0] } } = $o->[2]; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 35 | ▶ | next unless $f == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 10 | $permessage->{ $fieldtable->{ $o->[0] } } = $o->[2]; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 10 | ▶ | return undef unless $recipients; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 10 | for my $e ( @$dscontents ) { | |||||||||||||||||||||||||||
| 95 | # Set default values if each value is empty. | ||||||||||||||||||||||||||||
| 96 | 10 | ▶ | $e->{ $_ } ||= $permessage->{ $_ } || '' for keys %$permessage; | ||||||||||||||||||||||||||
|
Condition20%1/5
$e->{$_} ||= $permessage->{$_} || ""
$permessage->{$_} || ''
MC/DC0%0/2
$e->{$_} ||= $permessage->{$_} || ""
$e->{$_}
$permessage->{$_}
Truth table33%1/3
A ||= B
A= $e->{$_}B= $permessage->{$_}
| |||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | 10 | return {"ds" => $dscontents, "rfc822" => $emailparts->[1]}; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 3 | 1; | |||||||||||||||||||||||||||
| 102 | __END__ | ||||||||||||||||||||||||||||