| 1 | package Sisimai::RFC3464; | ||||||||||||||||||||||||||||||||||
| 2 | 33 | ▶ | use v5.26; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | 33 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 33 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 33 | ▶ | use Sisimai::Lhost; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 33 | ▶ | use Sisimai::RFC1123; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 33 | ▶ | use Sisimai::RFC3464::ThirdParty; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | # http://tools.ietf.org/html/rfc3464 | ||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | sub description { 'RFC3464' }; | ||||||||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 11 | 893 | ▶ | sub inquire { | ||||||||||||||||||||||||||||||||
|
Subroutine
inquire: called CC=83 SCAR=44.7
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 12 | # Decode a bounce mail which have fields defined in RFC3464 | ||||||||||||||||||||||||||||||||||
| 13 | # @param [Hash] mhead Message headers of a bounce email | ||||||||||||||||||||||||||||||||||
| 14 | # @param [String] mbody Message body of a bounce email | ||||||||||||||||||||||||||||||||||
| 15 | # @return [Hash] Bounce data list and message/rfc822 part | ||||||||||||||||||||||||||||||||||
| 16 | # @return [undef] failed to decode or the arguments are missing | ||||||||||||||||||||||||||||||||||
| 17 | 893 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 18 | 893 | ▶ | my $mhead = shift // return undef; return undef unless keys %$mhead; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
shift() // (return undef)
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||
| 19 | 856 | ▶ | my $mbody = shift // return undef; return undef unless ref $mbody eq 'SCALAR'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
shift() // (return undef)
MC/DC0%0/1
shift() // (return undef)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | 855 | require Sisimai::RFC1894; | |||||||||||||||||||||||||||||||||
| 22 | 855 | require Sisimai::RFC2045; | |||||||||||||||||||||||||||||||||
| 23 | 855 | require Sisimai::RFC5322; | |||||||||||||||||||||||||||||||||
| 24 | 855 | require Sisimai::Address; | |||||||||||||||||||||||||||||||||
| 25 | 855 | require Sisimai::String; | |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | 855 | state $indicators = Sisimai::Lhost->INDICATORS; | |||||||||||||||||||||||||||||||||
| 28 | 855 | state $boundaries = [ | |||||||||||||||||||||||||||||||||
| 29 | # When the new value added, the part of the value should be listed in $delimiters variable | ||||||||||||||||||||||||||||||||||
| 30 | # defined at Sisimai::RFC2045->makeFlat() method | ||||||||||||||||||||||||||||||||||
| 31 | "Content-Type: message/rfc822", | ||||||||||||||||||||||||||||||||||
| 32 | "Content-Type: text/rfc822-headers", | ||||||||||||||||||||||||||||||||||
| 33 | "Content-Type: message/partial", | ||||||||||||||||||||||||||||||||||
| 34 | "Content-Disposition: inline", # See lhost-amavis-*.eml, lhost-facebook-*.eml | ||||||||||||||||||||||||||||||||||
| 35 | ]; | ||||||||||||||||||||||||||||||||||
| 36 | 855 | state $startingof = {"message" => ["Content-Type: message/delivery-status"]}; | |||||||||||||||||||||||||||||||||
| 37 | 855 | state $fieldtable = Sisimai::RFC1894->FIELDTABLE; | |||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | 855 | ▶ | unless( grep { index($$mbody, $_) > 0 } @$boundaries ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 40 | # There is no "Content-Type: message/rfc822" line in the message body | ||||||||||||||||||||||||||||||||||
| 41 | # Insert "Content-Type: message/rfc822" before "Return-Path:" of the original message | ||||||||||||||||||||||||||||||||||
| 42 | 123 | my $p0 = index($$mbody, "\n\nReturn-Path:"); | |||||||||||||||||||||||||||||||||
| 43 | 123 | ▶ | $$mbody = sprintf("%s%s%s", substr($$mbody, 0, $p0), $boundaries->[0], substr($$mbody, $p0 + 1,)) if $p0 > 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | 855 | ▶ | 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)
| |||||||||||||||||||||||||||||||||||
| 47 | 855 | my $dscontents = [Sisimai::Lhost->DELIVERYSTATUS]; my $v = undef; | |||||||||||||||||||||||||||||||||
| 48 | 855 | my $alternates = Sisimai::Lhost->DELIVERYSTATUS; | |||||||||||||||||||||||||||||||||
| 49 | 855 | my $permessage = {}; | |||||||||||||||||||||||||||||||||
| 50 | 855 | my $readcursor = 0; # (Integer) Points the current cursor position | |||||||||||||||||||||||||||||||||
| 51 | 855 | my $recipients = 0; # (Integer) The number of 'Final-Recipient' header | |||||||||||||||||||||||||||||||||
| 52 | 855 | my $beforemesg = ""; # (String) String before $startingof->{"message"} | |||||||||||||||||||||||||||||||||
| 53 | 855 | my $goestonext = 0; # (Bool) Flag: do not append the line into $beforemesg | |||||||||||||||||||||||||||||||||
| 54 | 855 | ▶ | my $isboundary = [Sisimai::RFC2045->boundary($mhead->{"content-type"}, 0)]; $isboundary->[0] ||= ""; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$isboundary->[0] ||= ""
MC/DC100%1/1
$isboundary->[0] ||= ""
$isboundary->[0]
Truth table100%2/2
A
A= $isboundary->[0]
| |||||||||||||||||||||||||||||||||||
| 55 | 855 | my $p = ""; | |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | 855 | ▶ | while( index($emailparts->[0], '@') < 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 58 | # There is no email address in the first element of emailparts | ||||||||||||||||||||||||||||||||||
| 59 | # There is a bounce message inside of message/rfc822 part at lhost-x5-* | ||||||||||||||||||||||||||||||||||
| 60 | 30 | my $p0 = -1; # The index of the boundary string found first | |||||||||||||||||||||||||||||||||
| 61 | 30 | my $p1 = 0; # Offset position of the message body after the boundary string | |||||||||||||||||||||||||||||||||
| 62 | 30 | my $ct = ""; # Boundary string found first such as "Content-Type: message/rfc822" | |||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | 30 | for my $e ( @$boundaries ) { | |||||||||||||||||||||||||||||||||
| 65 | # Look for a boundary string from the message body | ||||||||||||||||||||||||||||||||||
| 66 | 81 | ▶ | $p0 = index($$mbody, $e."\n"); next if $p0 < 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 67 | 13 | $p1 = $p0 + length($e) + 2; | |||||||||||||||||||||||||||||||||
| 68 | 13 | $ct = $e; last; | |||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||
| 70 | 30 | ▶ | last if $p0 < 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||
| 72 | 13 | my $cx = substr($$mbody, $p1,); | |||||||||||||||||||||||||||||||||
| 73 | 13 | my $p2 = index($cx,, "\n\n"); | |||||||||||||||||||||||||||||||||
| 74 | 13 | my $cv = substr($cx, $p2 + 2,); | |||||||||||||||||||||||||||||||||
| 75 | 13 | $emailparts = Sisimai::RFC5322->part(\$cv, [$ct], 0); | |||||||||||||||||||||||||||||||||
| 76 | 13 | last; | |||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||
| 78 | 855 | ▶ | return undef if ref($emailparts) eq '' || $emailparts->[0] eq ''; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $emailparts eq "" or $emailparts->[0] eq ""
MC/DC0%0/2
ref $emailparts eq "" or $emailparts->[0] eq ""
ref $emailparts eq ""
$emailparts->[0] eq ""
Truth table33%1/3
A or B
A= ref $emailparts eq ""B= $emailparts->[0] eq ""
| |||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | 855 | ▶ | if( index($emailparts->[0], $startingof->{"message"}->[0]) < 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 81 | # There is no "Content-Type: message/delivery-status" line in the message body | ||||||||||||||||||||||||||||||||||
| 82 | # Insert "Content-Type: message/delivery-status" before "Reporting-MTA:" field | ||||||||||||||||||||||||||||||||||
| 83 | 169 | my $cv = "\n\nReporting-MTA:"; | |||||||||||||||||||||||||||||||||
| 84 | 169 | my $e0 = $emailparts->[0]; | |||||||||||||||||||||||||||||||||
| 85 | 169 | my $p0 = index($e0, $cv); | |||||||||||||||||||||||||||||||||
| 86 | 169 | ▶ | $emailparts->[0] = sprintf("%s\n\n%s%s", substr($e0, 0, $p0), $startingof->{"message"}->[0], substr($e0, $p0,)) if $p0 > 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | 855 | for my $e ("Final-Recipient", "Original-Recipient") { | |||||||||||||||||||||||||||||||||
| 90 | # Fix the malformed field "Final-Recipient: <kijitora@example.jp>" | ||||||||||||||||||||||||||||||||||
| 91 | 1710 | my $cv = "\n".$e.": "; | |||||||||||||||||||||||||||||||||
| 92 | 1710 | my $cx = $cv."<"; | |||||||||||||||||||||||||||||||||
| 93 | 1710 | ▶ | my $p0 = index($emailparts->[0], $cx); next if $p0 < 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||
| 95 | 26 | substr($emailparts->[0], $p0, length($cv) + 1, $cv."rfc822; "); | |||||||||||||||||||||||||||||||||
| 96 | 26 | my $p1 = index($emailparts->[0], ">\n", $p0 + 2); substr($emailparts->[0], $p1, 1, ""); | |||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | 855 | for my $e ( split("\n", $emailparts->[0]) ) { | |||||||||||||||||||||||||||||||||
| 100 | # Read error messages and delivery status lines from the head of the email to the previous | ||||||||||||||||||||||||||||||||||
| 101 | # line of the beginning of the original message. | ||||||||||||||||||||||||||||||||||
| 102 | 22842 | ▶ | if( $readcursor == 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 103 | # Beginning of the bounce message or message/delivery-status part | ||||||||||||||||||||||||||||||||||
| 104 | 16124 | ▶ | $readcursor |= $indicators->{'deliverystatus'} if index($e, $startingof->{'message'}->[0]) == 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | 16124 | while(1) { | |||||||||||||||||||||||||||||||||
| 107 | # Append each string before startingof["message"][0] except the following patterns | ||||||||||||||||||||||||||||||||||
| 108 | # for the later reference | ||||||||||||||||||||||||||||||||||
| 109 | 16124 | ▶ | last if $e eq "" || $goestonext; # Blank line or the part is text/html, image/icon, in multipart/* | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$e eq "" or $goestonext
MC/DC50%1/2
$e eq "" or $goestonext
$e eq ""
$goestonext
Truth table66%2/3
A or B
A= $e eq ""B= $goestonext
| |||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | # This line is a boundary kept in "multiparts" as a string, when the end of the boundary | ||||||||||||||||||||||||||||||||||
| 112 | # appeared, the condition above also returns true. | ||||||||||||||||||||||||||||||||||
| 113 | 12325 | ▶ | if( grep { index($e, $_) == 0 } @$isboundary ) { $goestonext = 0; last } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 114 | 6347 | ▶ | if( index($e, "Content-Type:") == 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 115 | # Content-Type: field in multipart/* | ||||||||||||||||||||||||||||||||||
| 116 | 795 | ▶ | if( index($e, "multipart/") > 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 117 | # Content-Type: multipart/alternative; boundary=aa00220022222222ffeebb | ||||||||||||||||||||||||||||||||||
| 118 | # Pick the boundary string and store it into "isboucdary" | ||||||||||||||||||||||||||||||||||
| 119 | 1 | push @$isboundary, Sisimai::RFC2045->boundary($e, 0); | |||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | } elsif( index($e, "text/plain") ) { | ||||||||||||||||||||||||||||||||||
| 122 | # Content-Type: "text/plain" | ||||||||||||||||||||||||||||||||||
| 123 | 794 | $goestonext = 0; | |||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | } else { | ||||||||||||||||||||||||||||||||||
| 126 | # Other types: for example, text/html, image/jpg, and so on | ||||||||||||||||||||||||||||||||||
| 127 | 0 | $goestonext = 1; | |||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||
| 129 | 795 | last; | |||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | 5552 | ▶ | last if index($e, "Content-") == 0; # Content-Disposition, ... | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 133 | 5537 | ▶ | last if index($e, "This is a MIME") == 0; # This is a MIME-formatted message. | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 134 | 5356 | ▶ | last if index($e, "This is a multi") == 0; # This is a multipart message in MIME format | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 135 | 5268 | ▶ | last if index($e, "This is an auto") == 0; # This is an automatically generated ... | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 136 | 5148 | ▶ | last if index($e, "This multi-part") == 0; # This multi-part MIME message contains... | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 137 | 5143 | ▶ | last if index($e, "###") == 0; # A frame like ##### | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 138 | 5133 | ▶ | last if index($e, "***") == 0; # A frame like ***** | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 139 | 5133 | ▶ | last if index($e, "--") == 0; # Boundary string | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 140 | 5100 | ▶ | last if index($e, "--- The follow") > -1; # ----- The following addresses had delivery problems ----- | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 141 | 5035 | ▶ | last if index($e, "--- Transcript") > -1; # ----- Transcript of session follows ----- | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 142 | 5012 | $beforemesg .= $e." "; last; | |||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||
| 144 | 16124 | next; | |||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||
| 146 | 6718 | ▶ | 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 ""
| |||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||
| 148 | 5927 | ▶ | if( my $f = Sisimai::RFC1894->match($e) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 149 | # $e matched with any field defined in RFC3464 | ||||||||||||||||||||||||||||||||||
| 150 | 5247 | ▶ | next unless my $o = Sisimai::RFC1894->field($e); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 151 | 5082 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||
| 153 | 5082 | ▶ | if( $o->[3] eq "addr" ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 154 | # Final-Recipient: rfc822; kijitora@example.jp | ||||||||||||||||||||||||||||||||||
| 155 | # X-Actual-Recipient: rfc822; kijitora@example.co.jp | ||||||||||||||||||||||||||||||||||
| 156 | 957 | ▶ | if( $o->[0] eq "final-recipient" ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 157 | # Final-Recipient: rfc822; kijitora@example.jp | ||||||||||||||||||||||||||||||||||
| 158 | # Final-Recipient: x400; /PN=... | ||||||||||||||||||||||||||||||||||
| 159 | 745 | ▶ | my $cv = Sisimai::Address->s3s4($o->[2]); next unless Sisimai::Address->is_emailaddress($cv); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 160 | 745 | ▶ | my $cw = scalar @$dscontents; next if $cw > 0 && $cv eq $dscontents->[$cw - 1]->{'recipient'}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cw > 0 and $cv eq $$dscontents[$cw - 1]{"recipient"}
MC/DC0%0/2
$cw > 0 and $cv eq $$dscontents[$cw - 1]{"recipient"}
$cw > 0
$cv eq $$dscontents[$cw - 1]{"recipient"}
Truth table33%1/3
A and B
A= $cw > 0B= $cv eq $$dscontents[$cw - 1]{"recipient"}
| |||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||
| 162 | 745 | ▶ | if( $v->{'recipient'} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 163 | # There are multiple recipient addresses in the message body. | ||||||||||||||||||||||||||||||||||
| 164 | 32 | push @$dscontents, Sisimai::Lhost->DELIVERYSTATUS; | |||||||||||||||||||||||||||||||||
| 165 | 32 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||
| 167 | 745 | $v->{'recipient'} = $cv; | |||||||||||||||||||||||||||||||||
| 168 | 745 | $recipients++; | |||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||
| 170 | } else { | ||||||||||||||||||||||||||||||||||
| 171 | # X-Actual-Recipient: rfc822; kijitora@example.co.jp | ||||||||||||||||||||||||||||||||||
| 172 | 212 | $v->{'alias'} = $o->[2]; | |||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||
| 174 | } elsif( $o->[3] eq "code" ) { | ||||||||||||||||||||||||||||||||||
| 175 | # Diagnostic-Code: SMTP; 550 5.1.1 <userunknown@example.jp>... User Unknown | ||||||||||||||||||||||||||||||||||
| 176 | 670 | $v->{'spec'} = $o->[1]; | |||||||||||||||||||||||||||||||||
| 177 | 670 | $v->{'diagnosis'} .= $o->[2]." "; | |||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||
| 179 | } else { | ||||||||||||||||||||||||||||||||||
| 180 | # Other DSN fields defined in RFC3464 | ||||||||||||||||||||||||||||||||||
| 181 | 3455 | ▶ | if( $o->[4] ne "" ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 182 | # There are other error messages as a comment such as the following: | ||||||||||||||||||||||||||||||||||
| 183 | # Status: 5.0.0 (permanent failure) | ||||||||||||||||||||||||||||||||||
| 184 | # Status: 4.0.0 (cat.example.net: host name lookup failure) | ||||||||||||||||||||||||||||||||||
| 185 | 659 | $v->{'diagnosis'} .= " ".$o->[4]." "; | |||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||
| 187 | 3455 | ▶ | next unless exists $fieldtable->{ $o->[0] }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 188 | 3455 | ▶ | next if $o->[3] eq "host" && Sisimai::RFC1123->is_internethost($o->[2]) == 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$o->[3] eq "host" and "Sisimai::RFC1123"->is_internethost($o->[2]) == 0
MC/DC100%2/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 table100%3/3
A and B
A= $o->[3] eq "host"B= "Sisimai::RFC1123"->is_internethost($o->[2]) == 0
| |||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||
| 190 | 3215 | $v->{ $fieldtable->{ $o->[0] } } = $o->[2]; | |||||||||||||||||||||||||||||||||
| 191 | 3215 | ▶ | next unless $f == 1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 192 | 1292 | $permessage->{ $fieldtable->{ $o->[0] } } = $o->[2]; | |||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||
| 194 | } else { | ||||||||||||||||||||||||||||||||||
| 195 | # Check that the line is a continued line of the value of Diagnostic-Code: field or not | ||||||||||||||||||||||||||||||||||
| 196 | 680 | ▶ | if( index($e, "X-") == 0 && index($e, ": ") > 1 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
index($e, "X-") == 0 and index($e, ": ") > 1
MC/DC50%1/2
index($e, "X-") == 0 and index($e, ": ") > 1
index($e, "X-") == 0
index($e, ": ") > 1
Truth table66%2/3
A and B
A= index($e, "X-") == 0B= index($e, ": ") > 1
| |||||||||||||||||||||||||||||||||||
| 197 | # This line is a MTA-Specific fields begins with "X-" | ||||||||||||||||||||||||||||||||||
| 198 | 238 | ▶ | next unless Sisimai::RFC3464::ThirdParty->is3rdparty($e); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||
| 200 | 32 | my $cv = Sisimai::RFC3464::ThirdParty->xfield($e); | |||||||||||||||||||||||||||||||||
| 201 | 32 | ▶ | if( scalar(@$cv) > 0 && not exists $fieldtable->{ lc $cv->[0] } ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
scalar @$cv > 0 and not exists $$fieldtable{lc $cv->[0]}
MC/DC50%1/2
scalar @$cv > 0 and not exists $$fieldtable{lc $cv->[0]}
scalar @$cv > 0
not exists $$fieldtable{lc $cv->[0]}
Truth table66%2/3
A and not(B)
A= scalar @$cv > 0B= not exists $$fieldtable{lc $cv->[0]}
| |||||||||||||||||||||||||||||||||||
| 202 | # Check the first element is a field defined in RFC1894 or not | ||||||||||||||||||||||||||||||||||
| 203 | 16 | ▶ | $v->{'reason'} = substr($cv->[4], index($cv->[4], ":") + 1,) if index($cv->[4], "reason:") == 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||
| 205 | } else { | ||||||||||||||||||||||||||||||||||
| 206 | # Set the value picked from "X-*" field to $dscontents when the current value is empty | ||||||||||||||||||||||||||||||||||
| 207 | 16 | ▶ | my $z = $fieldtable->{ lc $cv->[0] }; next unless $z; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 208 | 16 | ▶ | $v->{ $z } ||= $cv->[2]; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$v->{$z} ||= $cv->[2]
MC/DC0%0/2
$v->{$z} ||= $cv->[2]
$v->{$z}
$cv->[2]
Truth table33%1/3
A ||= B
A= $v->{$z}B= $cv->[2]
| |||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||
| 210 | } else { | ||||||||||||||||||||||||||||||||||
| 211 | # The line may be a continued line of the value of the Diagnostic-Code: field | ||||||||||||||||||||||||||||||||||
| 212 | 442 | ▶ | if( index($p, 'Diagnostic-Code:') < 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 213 | # In the case of multiple "message/delivery-status" line | ||||||||||||||||||||||||||||||||||
| 214 | 233 | ▶ | next if index($e, "Content-") == 0; # Content-Disposition:, ... | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 215 | 223 | ▶ | next if index($e, "--") == 0; # Boundary string | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 216 | 207 | $beforemesg .= $e." "; next | |||||||||||||||||||||||||||||||||
| 217 | 207 | } | |||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | # Diagnostic-Code: SMTP; 550-5.7.26 The MAIL FROM domain [email.example.jp] | ||||||||||||||||||||||||||||||||||
| 220 | # has an SPF record with a hard fail | ||||||||||||||||||||||||||||||||||
| 221 | 209 | ▶ | next unless index($e, " ") == 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 222 | 176 | $v->{'diagnosis'} .= " ".$e; | |||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||
| 225 | } continue { | ||||||||||||||||||||||||||||||||||
| 226 | # Save the current line for the next loop | ||||||||||||||||||||||||||||||||||
| 227 | 22842 | $p = $e; | |||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||
| 230 | 855 | ▶ | while( $recipients == 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 231 | # There is no valid recipient address, Try to use the alias addaress as a final recipient | ||||||||||||||||||||||||||||||||||
| 232 | 142 | ▶ | last unless length $dscontents->[0]->{'alias'} > 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 233 | 26 | ▶ | last unless Sisimai::Address->is_emailaddress($dscontents->[0]->{'alias'}); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 234 | 26 | $dscontents->[0]->{'recipient'} = $dscontents->[0]->{'alias'}; | |||||||||||||||||||||||||||||||||
| 235 | 26 | $recipients++; | |||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||
| 237 | 855 | ▶ | return undef unless $recipients; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||
| 239 | 739 | require Sisimai::SMTP::Reply; | |||||||||||||||||||||||||||||||||
| 240 | 739 | require Sisimai::SMTP::Status; | |||||||||||||||||||||||||||||||||
| 241 | 739 | require Sisimai::SMTP::Command; | |||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||
| 243 | 739 | ▶ | if( $beforemesg ne "" ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 244 | # Pick some values of $dscontents from the string before $startingof->{'message'} | ||||||||||||||||||||||||||||||||||
| 245 | 729 | $beforemesg = Sisimai::String->sweep($beforemesg); | |||||||||||||||||||||||||||||||||
| 246 | 729 | $alternates->{'command'} = Sisimai::SMTP::Command->find($beforemesg); | |||||||||||||||||||||||||||||||||
| 247 | 729 | $alternates->{'replycode'} = Sisimai::SMTP::Reply->find($beforemesg, $dscontents->[0]->{'status'}); | |||||||||||||||||||||||||||||||||
| 248 | 729 | $alternates->{'status'} = Sisimai::SMTP::Status->find($beforemesg, $alternates->{'replycode'}); | |||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||
| 250 | 739 | my $issuedcode = lc $beforemesg; | |||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||
| 252 | 739 | for my $e ( @$dscontents ) { | |||||||||||||||||||||||||||||||||
| 253 | # Set default values stored in "permessage" if each value in "dscontents" is empty. | ||||||||||||||||||||||||||||||||||
| 254 | 771 | ▶ | $e->{ $_ } ||= $permessage->{ $_ } || '' for keys %$permessage; | ||||||||||||||||||||||||||||||||
|
Condition60%3/5
$e->{$_} ||= $permessage->{$_} || ""
$permessage->{$_} || ''
MC/DC0%0/2
$e->{$_} ||= $permessage->{$_} || ""
$e->{$_}
$permessage->{$_}
Truth table66%2/3
A ||= B
A= $e->{$_}B= $permessage->{$_}
| |||||||||||||||||||||||||||||||||||
| 255 | 771 | my $lowercased = lc $e->{'diagnosis'}; | |||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||
| 257 | 771 | ▶ | if( $recipients == 1 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 258 | # Do not mix the error message of each recipient with "beforemesg" when there is | ||||||||||||||||||||||||||||||||||
| 259 | # multiple recipient addresses in the bounce message | ||||||||||||||||||||||||||||||||||
| 260 | 712 | ▶ | if( index($issuedcode, $lowercased) > -1 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 261 | # $beforemesg contains the entire strings of $e->{'diagnosis'} | ||||||||||||||||||||||||||||||||||
| 262 | 83 | $e->{'diagnosis'} = $beforemesg; | |||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||
| 264 | } else { | ||||||||||||||||||||||||||||||||||
| 265 | # The value of $e->{'diagnosis'} is not contained in $beforemesg | ||||||||||||||||||||||||||||||||||
| 266 | # There may be an important error message in $beforemesg | ||||||||||||||||||||||||||||||||||
| 267 | 629 | $e->{'diagnosis'} = sprintf("%s %s", $beforemesg, $e->{'diagnosis'}); | |||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||
| 270 | 771 | ▶ | $e->{'command'} = Sisimai::SMTP::Command->find($e->{'diagnosis'}) || $alternates->{'command'}; | ||||||||||||||||||||||||||||||||
|
Condition100%3/3
'Sisimai::SMTP::Command'->find($e->{'diagnosis'}) || $alternates->{'command'}
MC/DC100%2/2
'Sisimai::SMTP::Command'->find($e->{'diagnosis'}) || $alternates->{'command'}
'Sisimai::SMTP::Command'->find($e->{'diagnosis'})
$alternates->{'command'}
Truth table100%3/3
A || B
A= 'Sisimai::SMTP::Command'->find($e->{'diagnosis'})B= $alternates->{'command'}
| |||||||||||||||||||||||||||||||||||
| 271 | 771 | ▶ | $e->{'replycode'} = Sisimai::SMTP::Reply->find($e->{'diagnosis'}, $e->{'status'}) || $alternates->{'replycode'}; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
'Sisimai::SMTP::Reply'->find($e->{'diagnosis'}, $e->{'status'}) || $alternates->{'replycode'}
MC/DC50%1/2
'Sisimai::SMTP::Reply'->find($e->{'diagnosis'}, $e->{'status'}) || $alternates->{'replycode'}
'Sisimai::SMTP::Reply'->find($e->{'diagnosis'}, $e->{'status'})
$alternates->{'replycode'}
Truth table66%2/3
A || B
A= 'Sisimai::SMTP::Reply'->find($e->{'diagnosis'}, $e->{'status'})B= $alternates->{'replycode'}
| |||||||||||||||||||||||||||||||||||
| 272 | 771 | ▶ | $e->{'status'} ||= Sisimai::SMTP::Status->find($e->{'diagnosis'}, $e->{'replycode'}) || $alternates->{'status'}; | ||||||||||||||||||||||||||||||||
|
Condition83%5/6
$e->{"status"} ||= "Sisimai::SMTP::Status"->find($e->{"diagnosis"}, $e->{"replycode"}) || $alternates->{"status"}
'Sisimai::SMTP::Status'->find($e->{'diagnosis'}, $e->{'replycode'}) || $alternates->{'status'}
MC/DC0%0/3
$e->{"status"} ||= "Sisimai::SMTP::Status"->find($e->{"diagnosis"}, $e->{"replycode"}) || $alternates->{"status"}
$e->{"status"}
'Sisimai::SMTP::Status'->find($e->{'diagnosis'}, $e->{'replycode'})
$alternates->{'status'}
Truth table0%0/4
A ||= B || C
A= $e->{"status"}B= 'Sisimai::SMTP::Status'->find($e->{'diagnosis'}, $e->{'replycode'})C= $alternates->{'status'}
| |||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||
| 275 | # Set the recipient address as To: header in the original message part | ||||||||||||||||||||||||||||||||||
| 276 | 739 | ▶ | $emailparts->[1] = sprintf("To: <%s>\n", $dscontents->[0]->{'recipient'}) unless $emailparts->[1]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||
| 278 | 739 | return {"ds" => $dscontents, "rfc822" => $emailparts->[1]}; | |||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||
| 281 | 33 | 1; | |||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||
| 283 | __END__ | ||||||||||||||||||||||||||||||||||