| 1 | package Sisimai::Lhost::MailMarshal; | ||||||||||||||||||||||||||||
| 2 | 37 | ▶ | use parent 'Sisimai::Lhost'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 37 | ▶ | use v5.26; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 37 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 37 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | sub description { 'Trustwave Secure Email Gateway: https://www.trustwave.com/en-us/services/email-security/' } | ||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 8 | 899 | ▶ | sub inquire { | ||||||||||||||||||||||||||
|
Subroutine
inquire: called CC=27 SCAR=33.2
Pod
documented
| |||||||||||||||||||||||||||||
| 9 | # Detect an error from Trustwave Secure Email Gateway (Formerly MailMarshal) | ||||||||||||||||||||||||||||
| 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.9 | ||||||||||||||||||||||||||||
| 15 | 899 | my $class = shift; | |||||||||||||||||||||||||||
| 16 | 899 | ▶ | 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 | 898 | ▶ | 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 | 897 | ▶ | return undef unless $mhead->{'subject'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 879 | ▶ | return undef unless index($mhead->{'subject'}, 'Undeliverable Mail: "') == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 6 | state $indicators = __PACKAGE__->INDICATORS; | |||||||||||||||||||||||||||
| 23 | 6 | state $startingof = { | |||||||||||||||||||||||||||
| 24 | 'message' => ['Your message:'], | ||||||||||||||||||||||||||||
| 25 | 'error' => ['Could not be delivered because of'], | ||||||||||||||||||||||||||||
| 26 | 'rcpts' => ['The following recipients were affected:'], | ||||||||||||||||||||||||||||
| 27 | }; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 6 | my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef; | |||||||||||||||||||||||||||
| 30 | 6 | my $readcursor = 0; # (Integer) Points the current cursor position | |||||||||||||||||||||||||||
| 31 | 6 | my $recipients = 0; # (Integer) The number of 'Final-Recipient' header | |||||||||||||||||||||||||||
| 32 | 6 | my $endoferror = 0; # (Integer) Flag for the end of error message | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 6 | my $boundaries = ['+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++']; | |||||||||||||||||||||||||||
| 35 | 6 | ▶ | my $q = Sisimai::RFC2045->boundary($mhead->{'content-type'}, 1); push @$boundaries, $q if $q; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 6 | ▶ | 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)
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 6 | 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 | 132 | ▶ | unless( $readcursor ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | # Beginning of the bounce message or message/delivery-status part | ||||||||||||||||||||||||||||
| 43 | 6 | ▶ | $readcursor |= $indicators->{'deliverystatus'} if index($e, $startingof->{'message'}->[0]) == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 132 | ▶ | next if ($readcursor & $indicators->{'deliverystatus'}) == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # Your message: | ||||||||||||||||||||||||||||
| 48 | # From: originalsender@example.com | ||||||||||||||||||||||||||||
| 49 | # Subject: ... | ||||||||||||||||||||||||||||
| 50 | # | ||||||||||||||||||||||||||||
| 51 | # Could not be delivered because of | ||||||||||||||||||||||||||||
| 52 | # | ||||||||||||||||||||||||||||
| 53 | # 550 5.1.1 User unknown | ||||||||||||||||||||||||||||
| 54 | # | ||||||||||||||||||||||||||||
| 55 | # The following recipients were affected: | ||||||||||||||||||||||||||||
| 56 | # dummyuser@blabla.xxxxxxxxxxxx.com | ||||||||||||||||||||||||||||
| 57 | 132 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 132 | ▶ | if( index($e, ' ') == 0 && index($e, '@') > 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
index($e, " ") == 0 and index($e, "\@") > 1
MC/DC50%1/2
index($e, " ") == 0 and index($e, "\@") > 1
index($e, " ") == 0
index($e, "\@") > 1
Truth table66%2/3
A and B
A= index($e, " ") == 0B= index($e, "\@") > 1
| |||||||||||||||||||||||||||||
| 60 | # The following recipients were affected: | ||||||||||||||||||||||||||||
| 61 | # dummyuser@blabla.xxxxxxxxxxxx.com | ||||||||||||||||||||||||||||
| 62 | 6 | ▶ | if( $v->{'recipient'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | # There are multiple recipient addresses in the message body. | ||||||||||||||||||||||||||||
| 64 | 0 | push @$dscontents, __PACKAGE__->DELIVERYSTATUS; | |||||||||||||||||||||||||||
| 65 | 0 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 6 | $v->{'recipient'} = substr($e, 4,); | |||||||||||||||||||||||||||
| 68 | 6 | $recipients++; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | } else { | ||||||||||||||||||||||||||||
| 71 | # Get error message lines | ||||||||||||||||||||||||||||
| 72 | 126 | ▶ | if( $e eq $startingof->{'error'}->[0] ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 73 | # Could not be delivered because of | ||||||||||||||||||||||||||||
| 74 | # | ||||||||||||||||||||||||||||
| 75 | # 550 5.1.1 User unknown | ||||||||||||||||||||||||||||
| 76 | 6 | $v->{'diagnosis'} = $e; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | ▶ | } elsif( $v->{'diagnosis'} && ! $endoferror ) { | |||||||||||||||||||||||||||
|
Condition100%3/3
$v->{"diagnosis"} and not $endoferror
MC/DC100%2/2
$v->{"diagnosis"} and not $endoferror
$v->{"diagnosis"}
not $endoferror
Truth table100%3/3
A and not(B)
A= $v->{"diagnosis"}B= not $endoferror
| |||||||||||||||||||||||||||||
| 79 | # Append error messages | ||||||||||||||||||||||||||||
| 80 | 24 | ▶ | $endoferror = 1 if index($e, $startingof->{'rcpts'}->[0]) == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 24 | ▶ | next if $endoferror; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 18 | $v->{'diagnosis'} .= ' '.$e; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | } else { | ||||||||||||||||||||||||||||
| 86 | # Additional Information | ||||||||||||||||||||||||||||
| 87 | # ====================== | ||||||||||||||||||||||||||||
| 88 | # Original Sender: <originalsender@example.com> | ||||||||||||||||||||||||||||
| 89 | # Sender-MTA: <10.11.12.13> | ||||||||||||||||||||||||||||
| 90 | # Remote-MTA: <10.0.0.1> | ||||||||||||||||||||||||||||
| 91 | # Reporting-MTA: <relay.xxxxxxxxxxxx.com> | ||||||||||||||||||||||||||||
| 92 | # MessageName: <B549996730000.000000000001.0003.mml> | ||||||||||||||||||||||||||||
| 93 | # Last-Attempt-Date: <16:21:07 seg, 22 Dezembro 2014> | ||||||||||||||||||||||||||||
| 94 | 96 | my $p1 = index($e, '<'); | |||||||||||||||||||||||||||
| 95 | 96 | my $p2 = index($e, '>'); | |||||||||||||||||||||||||||
| 96 | 96 | ▶ | if( index($e, 'Original Sender: ') == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 97 | # Original Sender: <originalsender@example.com> | ||||||||||||||||||||||||||||
| 98 | # Use this line instead of "From" header of the original message. | ||||||||||||||||||||||||||||
| 99 | 6 | $emailparts->[1] .= sprintf("From: %s\n", substr($e, $p1 + 1, $p2 - $p1 - 1)); | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | } elsif( index($e, 'Sender-MTA: ') == 0 ) {; | ||||||||||||||||||||||||||||
| 102 | # Sender-MTA: <10.11.12.13> | ||||||||||||||||||||||||||||
| 103 | 6 | $v->{'lhost'} = substr($e, $p1 + 1, $p2 - $p1 - 1); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | } elsif( index($e , 'Reporting-MTA: ') == 0 ) { | ||||||||||||||||||||||||||||
| 106 | # Reporting-MTA: <relay.xxxxxxxxxxxx.com> | ||||||||||||||||||||||||||||
| 107 | 6 | $v->{'rhost'} = substr($e, $p1 + 1, $p2 - $p1 - 1); | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | ▶ | } elsif( index($e, ' From:') > 0 || index($e, ' Subject:') > 0 ) { | |||||||||||||||||||||||||||
|
Condition100%3/3
index($e, " From:") > 0 or index($e, " Subject:") > 0
MC/DC100%2/2
index($e, " From:") > 0 or index($e, " Subject:") > 0
index($e, " From:") > 0
index($e, " Subject:") > 0
Truth table100%3/3
A or B
A= index($e, " From:") > 0B= index($e, " Subject:") > 0
| |||||||||||||||||||||||||||||
| 110 | # From: originalsender@example.com | ||||||||||||||||||||||||||||
| 111 | # Subject: ... | ||||||||||||||||||||||||||||
| 112 | 12 | ▶ | $p1 = index($e, ' From:'); $p1 = index($e, ' Subject:') if $p1 < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 12 | $p2 = index($e, ':'); | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 12 | my $cf = substr($e, $p1 + 1, $p2 - $p1 - 1); | |||||||||||||||||||||||||||
| 116 | 12 | my $cv = substr($e, $p2 + 1,); | |||||||||||||||||||||||||||
| 117 | 12 | $emailparts->[1] .= sprintf("%s: %s\n", $cf, $cv); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | 6 | ▶ | return undef unless $recipients; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 6 | return {"ds" => $dscontents, "rfc822" => $emailparts->[1]}; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 37 | 1; | |||||||||||||||||||||||||||
| 127 | __END__ | ||||||||||||||||||||||||||||