| 1 | package Sisimai::ARF; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use v5.26; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use Sisimai::Eb; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 8 | ▶ | use Sisimai::Lhost; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use Sisimai::RFC5322; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | sub description { return 'Abuse Feedback Reporting Format' } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 164 | ▶ | sub is_arf { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_arf: called CC=9 SCAR=22.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # Email is a Feedback-Loop message or not | ||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # @param [Hash] heads Email header including "Content-Type", "From" and "Subject" field | ||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # @return [Integer] 1: Feedback Loop | ||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # 0: is not Feedback loop | ||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 164 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 164 | ▶ | my $heads = shift || return 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || (return 0)
MC/DC100%1/1
shift() || (return 0)
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 163 | my $abuse = ['staff@hotmail.com', 'complaints@email-abuse.amazonses.com']; | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 163 | ▶ | my $ctype = $heads->{"content-type"} || ""; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$heads->{'content-type'} || ''
MC/DC100%1/1
$heads->{'content-type'} || ''
$heads->{'content-type'}
Truth table100%2/2
A
A= $heads->{'content-type'}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # Content-Type: multipart/report; report-type=feedback-report; ... | ||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 163 | ▶ | return 1 if Sisimai::String->aligned(\$ctype, ["report-type=", "feedback-report"]); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 97 | ▶ | if( index($ctype, "multipart/mixed") > -1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # Microsoft (Hotmail, MSN, Live, Outlook) uses its own report format. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # Amazon SES Complaints bounces | ||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 34 | ▶ | if( index($heads->{"subject"}, "complaint about message from ") > -1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # From: staff@hotmail.com | ||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # From: complaints@email-abuse.amazonses.com | ||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # Subject: complaint about message from 192.0.2.1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 30 | ▶ | return 1 if grep { index($heads->{"from"}, $_) > -1 } @$abuse; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # X-Apple-Unsubscribe: true | ||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 67 | ▶ | return 0 unless exists $heads->{"x-apple-unsubscribe"}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | ▶ | return 1 if $heads->{"x-apple-unsubscribe"} eq "true"; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 164 | ▶ | sub inquire { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inquire: called CC=43 SCAR=38.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # Detect an error for Feedback Loop | ||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # @param [Hash] mhead Message headers of a bounce email | ||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # @param [String] mbody Message body of a bounce email | ||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # @return [Hash] Bounce data list and message/rfc822 part | ||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # @return [undef] failed to decode or the arguments are missing | ||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 164 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 164 | ▶ | my $mhead = shift // return undef; return undef unless is_arf(undef, $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()
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 101 | ▶ | my $mbody = shift // return undef; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // (return undef)
MC/DC0%0/1
shift() // (return undef)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # http://tools.ietf.org/html/rfc5965 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # http://en.wikipedia.org/wiki/Feedback_loop_(email) | ||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # http://en.wikipedia.org/wiki/Abuse_Reporting_Format | ||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # Netease DMARC uses: This is a spf/dkim authentication-failure report for an email message received from IP | ||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # OpenDMARC 1.3.0 uses: This is an authentication failure report for an email message received from IP | ||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # Abusix ARF uses: this is an autogenerated email abuse complaint regarding your network. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 101 | state $indicators = Sisimai::Lhost->INDICATORS; | |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 101 | state $reportfrom = "Content-Type: message/feedback-report"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 101 | state $boundaries = [ | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | "Content-Type: message/rfc822", | ||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | "Content-Type: text/rfc822-headers", | ||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | "Content-Type: text/rfc822-header", # ?? | ||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 101 | state $arfpreface = [ | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | ["this is a", "abuse report"], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ["this is a", "authentication", "failure report"], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ["this is a", " report for"], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | ["this is an authentication", "failure report"], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ["this is an autogenerated email abuse complaint"], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ["this is an email abuse report"], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 101 | ▶ | 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)
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 101 | my $dscontents = [Sisimai::Lhost->DELIVERYSTATUS]; my $v = $dscontents->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 101 | my $reportpart = 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 101 | my $readcursor = 0; # Points the current cursor position | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 101 | my $recipients = 0; # The number of "Final-Recipient" header | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 101 | my $timestamp0 = ""; # The value of "Arrival-Date" or "Received-Date" | |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 101 | my $remotehost = ""; # The value of "Source-IP" field | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 101 | my $reportedby = ""; # The value of "Reporting-MTA" field | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 101 | my $anotherone = ""; # Other fields(append to Diagnosis) | |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # 3.1. Required Fields | ||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # The following report header fields MUST appear exactly once: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | # o "Feedback-Type" contains the type of feedback report (as defined | ||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # in the corresponding IANA registry and later in this memo). This | ||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # is intended to let report parsers distinguish among different | ||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # types of reports. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | # o "User-Agent" indicates the name and version of the software | ||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | # program that generated the report. The format of this field MUST | ||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # follow section 14.43 of [HTTP]. This field is for documentation | ||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # only; there is no registry of user agent names or versions, and | ||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | # report receivers SHOULD NOT expect user agent names to belong to a | ||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # known set. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # o "Version" indicates the version of specification that the report | ||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | # generator is using to generate the report. The version number in | ||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # this specification is set to "1". | ||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 101 | for my $e ( split("\n", $emailparts->[0]) ) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # Read error messages and delivery status lines from the head of the email to the | ||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # previous line of the beginning of the original message. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1721 | ▶ | unless( $readcursor ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # Beginning of the bounce message or message/delivery-status part | ||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 761 | my $r = lc $e; | |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 761 | for my $f ( @$arfpreface ) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # Hello, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # this is an autogenerated email abuse complaint regarding your network. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 4276 | ▶ | next unless Sisimai::String->aligned(\$r, $f); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 66 | $readcursor |= $indicators->{'deliverystatus'}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 66 | $v->{"diagnosis"} .= " ".$e; | |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 66 | last; | |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 761 | next; | |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 960 | ▶ | 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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 810 | ▶ | if( $e eq $reportfrom ) { $reportpart = 1; next } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 744 | ▶ | if( $reportpart ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # Content-Type: message/feedback-report | ||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # MIME-Version: 1.0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # Feedback-Type: abuse | ||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | # User-Agent: SomeGenerator/1.0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # Version: 0.1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # Original-Mail-From: <somespammer@example.net> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # Original-Rcpt-To: <kijitora@example.jp> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # Received-Date: Thu, 29 Apr 2009 00:00:00 JST | ||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # Source-IP: 192.0.2.1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 573 | ▶ | if( index($e, "Original-Rcpt-To: ") == 0 || index($e, "Removal-Recipient: ") == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
Condition100%3/3
index($e, "Original-Rcpt-To: ") == 0 or index($e, "Removal-Recipient: ") == 0
MC/DC100%2/2
index($e, "Original-Rcpt-To: ") == 0 or index($e, "Removal-Recipient: ") == 0
index($e, "Original-Rcpt-To: ") == 0
index($e, "Removal-Recipient: ") == 0
Truth table100%3/3
A or B
A= index($e, "Original-Rcpt-To: ") == 0B= index($e, "Removal-Recipient: ") == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # Original-Rcpt-To header field is optional and may appear any number of times as appropriate: | ||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # Original-Rcpt-To: <kijitora@example.jp> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # Removal-Recipient: user@example.com | ||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 70 | ▶ | my $cv = Sisimai::Address->s3s4(substr($e, index($e, " ") + 1,)); next unless Sisimai::Address->is_emailaddress($cv); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 70 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 70 | ▶ | if( $v->{"recipient"} ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # There are multiple recipient addresses in the message body. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 35 | push @$dscontents, Sisimai::Lhost->DELIVERYSTATUS; | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 35 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 70 | $v->{"recipient"} = Sisimai::Address->s3s4(substr($e, index($e, " ") +1,)); | |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 70 | $recipients++; | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } elsif( index($e, "Feedback-Type: ") == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # The header field MUST appear exactly once. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # Feedback-Type: abuse | ||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 66 | $v->{"feedbacktype"} = substr($e, index($e, " ") + 1,); | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | ▶ | } elsif( index($e, "Authentication-Results: ") == 0 || index($e, "User-Agent: ") == 0 || index($e, "Original-Mail-From: ") == 0 ) { | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
index($e, "Authentication-Results: ") == 0 or index($e, "User-Agent: ") == 0 or index($e, "Original-Mail-From: ") == 0
index($e, "Authentication-Results: ") == 0 or index($e, "User-Agent: ") == 0
MC/DC100%3/3
index($e, "Authentication-Results: ") == 0 or index($e, "User-Agent: ") == 0 or index($e, "Original-Mail-From: ") == 0
index($e, "Authentication-Results: ") == 0
index($e, "User-Agent: ") == 0
index($e, "Original-Mail-From: ") == 0
Truth table100%4/4
A or B or C
A= index($e, "Authentication-Results: ") == 0B= index($e, "User-Agent: ") == 0C= index($e, "Original-Mail-From: ") == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # "Authentication-Results" indicates the result of one or more authentication checks | ||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # run by the report generator. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # - Authentication-Results: mail.example.com; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # - spf=fail smtp.mail=somespammer@example.com | ||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # The header field MUST appear exactly once. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # - User-Agent: SomeGenerator/1.0 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # | ||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # The header is optional and MUST NOT appear more than once. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # - Original-Mail-From: <somespammer@example.net> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 141 | $anotherone .= $e.", "; | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | ▶ | } elsif( index($e, "Received-Date: ") == 0 || index($e, "Arrival-Date: ") == 0 ) { | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
index($e, "Received-Date: ") == 0 or index($e, "Arrival-Date: ") == 0
MC/DC100%2/2
index($e, "Received-Date: ") == 0 or index($e, "Arrival-Date: ") == 0
index($e, "Received-Date: ") == 0
index($e, "Arrival-Date: ") == 0
Truth table100%3/3
A or B
A= index($e, "Received-Date: ") == 0B= index($e, "Arrival-Date: ") == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # Arrival-Date header is optional and MUST NOT appear more than once. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # Received-Date: Thu, 29 Apr 2010 00:00:00 JST | ||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # Arrival-Date: Thu, 29 Apr 2010 00:00:00 +0000 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 51 | $timestamp0 = substr($e, index($e, " ") + 1,); | |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } elsif( index($e, "Reporting-MTA: ") == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # The header is optional and MUST NOT appear more than once. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # Reporting-MTA: dns; mx.example.jp | ||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | my $cv = Sisimai::RFC1894->field($e); next if scalar(@$cv) == 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $reportedby = $cv->[2]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } elsif( index($e, "Source-IP: ") == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # The header is optional and MUST NOT appear more than once. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # Source-IP: 192.0.2.45 | ||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 46 | $remotehost = substr($e, index($e, ' ') + 1,); | |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | # Messages before "Content-Type: message/feedback-report" part | ||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 171 | $v->{"diagnosis"} .= " ".$e; | |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 101 | ▶ | while( $recipients == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # There is no recipient address in the message | ||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 66 | ▶ | if( exists $mhead->{"x-apple-unsubscribe"} ) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # X-Apple-Unsubscribe: true | ||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 5 | ▶ | last if $mhead->{"x-apple-unsubscribe"} ne "true" || index($mhead->{"from"}, "@") < 1; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$mhead->{"x-apple-unsubscribe"} ne "true" or index($mhead->{"from"}, "\@") < 1
MC/DC0%0/2
$mhead->{"x-apple-unsubscribe"} ne "true" or index($mhead->{"from"}, "\@") < 1
$mhead->{"x-apple-unsubscribe"} ne "true"
index($mhead->{"from"}, "\@") < 1
Truth table33%1/3
A or B
A= $mhead->{"x-apple-unsubscribe"} ne "true"B= index($mhead->{"from"}, "\@") < 1
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 5 | $dscontents->[0]->{"recipient"} = $mhead->{"from"}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 5 | $dscontents->[0]->{"diagnosis"} = $emailparts->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 5 | $dscontents->[0]->{"feedbacktype"} = "opt-out"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # Addpend To: field as a pseudo header | ||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 5 | ▶ | $emailparts->[1] = sprintf("To: <%s>\n", $mhead->{"from"}) if $emailparts->[1] eq ""; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # Pick it from the original message part | ||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 61 | ▶ | my $p1 = index($emailparts->[1], "\nTo:"); last if $p1 < 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 31 | ▶ | my $p2 = index($emailparts->[1], "\n", $p1 + 4); last if $p2 < 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 31 | my $cv = Sisimai::Address->s3s4(substr($emailparts->[1], $p1 + 4, $p2 - $p1)); | |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # There is no valid email address in the To: header of the original message such as | ||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # To: <Undisclosed Recipients> | ||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 31 | ▶ | $cv = Sisimai::Address->undisclosed("r") unless Sisimai::Address->is_emailaddress($cv); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 31 | $dscontents->[0]->{"recipient"} = $cv; | |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 36 | $recipients++; | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 101 | ▶ | return undef if $recipients == 0; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 71 | ▶ | $anotherone = ": ".$anotherone if $anotherone ne ""; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 71 | ▶ | substr($anotherone, -1, 1, "") if substr($anotherone, -1, 1) eq ","; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 71 | my $j = -1; for my $e ( @$dscontents ) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # Tidy up the error message in e.Diagnosis, Try to detect the bounce reason. | ||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 106 | $j++; | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 106 | $e->{"diagnosis"} = Sisimai::String->sweep($e->{"diagnosis"}.$anotherone); | |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 106 | $e->{"reason"} = $Sisimai::Eb::ReFEED; | |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 106 | $e->{"rhost"} = $remotehost; | |||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 106 | $e->{"lhost"} = $reportedby; | |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 106 | $e->{"date"} = $timestamp0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # Copy some values from the previous element when the report have 2 or more email address | ||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 106 | ▶ | next if $j == 0 || scalar(@$dscontents) == 1; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$j == 0 or scalar @$dscontents == 1
MC/DC50%1/2
$j == 0 or scalar @$dscontents == 1
$j == 0
scalar @$dscontents == 1
Truth table66%2/3
A or B
A= $j == 0B= scalar @$dscontents == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 35 | $e->{"diagnosis"} = $dscontents->[$j - 1]->{"diagnosis"}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 35 | $e->{"feedbacktype"} = $dscontents->[$j - 1]->{"feedbacktype"}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 71 | return {"ds" => $dscontents, "rfc822" => $emailparts->[1]}; | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||