| 1 | package Sisimai::RFC3464::ThirdParty; | ||||||||||||||||||||
| 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::Eb; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 33 | state $ThirdParty = { | |||||||||||||||||||
| 8 | #"Aol" => ["X-Outbound-Mail-Relay-"], # X-Outbound-Mail-Relay-(Queue-ID|Sender) | ||||||||||||||||||||
| 9 | "PowerMTA" => ["X-PowerMTA-"], # X-PowerMTA-(VirtualMTA|BounceCategory) | ||||||||||||||||||||
| 10 | #"Yandex" => ["X-Yandex-"], # X-Yandex-(Queue-ID|Sender) | ||||||||||||||||||||
| 11 | }; | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 238 | ▶ | sub is3rdparty { | ||||||||||||||||||
|
Subroutine
is3rdparty: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||
| 14 | # is3rdparty() returns true if the argument is a line generated by a MTA which have fields defined | ||||||||||||||||||||
| 15 | # in RFC3464 inside of a bounce mail the MTA returns | ||||||||||||||||||||
| 16 | # @param string argv1 A line of a bounce mail | ||||||||||||||||||||
| 17 | # @return bool The line indicates that a bounce mail generated by the 3rd party MTA | ||||||||||||||||||||
| 18 | 238 | my $class = shift; | |||||||||||||||||||
| 19 | 238 | ▶ | my $argv1 = shift || return 0; return __PACKAGE__->returnedby($argv1) ? 1 : 0; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
shift() || (return 0)
MC/DC0%0/1
shift() || (return 0)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 20 | } | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 270 | ▶ | sub returnedby { | ||||||||||||||||||
|
Subroutine
returnedby: called CC=5 SCAR=16.3
Pod
undocumented
| |||||||||||||||||||||
| 23 | # returnedby() returns an MTA name of the 3rd party | ||||||||||||||||||||
| 24 | # @param string argv1 A line of a bounce mail | ||||||||||||||||||||
| 25 | # @return string An MTA name of the 3rd party | ||||||||||||||||||||
| 26 | 270 | my $class = shift; | |||||||||||||||||||
| 27 | 270 | ▶ | my $argv1 = shift || return 0; return 0 unless index($argv1, "X-") == 0; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
shift() || (return 0)
MC/DC0%0/1
shift() || (return 0)
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 270 | for my $e ( keys %$ThirdParty ) { | |||||||||||||||||||
| 30 | # Does the argument include the 3rd party specific field? | ||||||||||||||||||||
| 31 | 270 | ▶ | return $e if index($argv1, $ThirdParty->{ $e }->[0]) == 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | 206 | return "" | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 32 | ▶ | sub xfield { | ||||||||||||||||||
|
Subroutine
xfield: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||
| 37 | # xfield() returns rfc1894.Field() compatible slice for the specific field of the 3rd party MTA | ||||||||||||||||||||
| 38 | # @param string argv1 A line of the error message | ||||||||||||||||||||
| 39 | # @return [] RFC1894->field() compatible array | ||||||||||||||||||||
| 40 | # @see Sisimai::RFC1894 | ||||||||||||||||||||
| 41 | 32 | my $class = shift; | |||||||||||||||||||
| 42 | 32 | ▶ | my $argv1 = shift || return []; | ||||||||||||||||||
|
Condition50%1/2
shift() || (return [])
MC/DC0%0/1
shift() || (return [])
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 43 | 32 | ▶ | my $party = __PACKAGE__->returnedby($argv1); return [] unless $party; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 32 | return sprintf("Sisimai::RFC3464::ThirdParty::%s", $party)->xfield($argv1); | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | 33 | 1; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | # ------------------------------------------------------------------------------------------------- | ||||||||||||||||||||
| 49 | package Sisimai::RFC3464::ThirdParty::PowerMTA; | ||||||||||||||||||||
| 50 | 33 | ▶ | use v5.26; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 51 | 33 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 52 | 33 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 33 | state $FieldGroup = { | |||||||||||||||||||
| 55 | "x-powermta-virtualmta" => "host", # X-PowerMTA-VirtualMTA: mx22.neko.example.jp | ||||||||||||||||||||
| 56 | "x-powermta-bouncecategory" => "text", # X-PowerMTA-BounceCategory: bad-mailbox | ||||||||||||||||||||
| 57 | }; | ||||||||||||||||||||
| 58 | 33 | state $MessagesOf = { | |||||||||||||||||||
| 59 | "bad-domain" => $Sisimai::Eb::ReHOST, | ||||||||||||||||||||
| 60 | "bad-mailbox" => $Sisimai::Eb::ReUSER, | ||||||||||||||||||||
| 61 | "inactive-mailbox" => $Sisimai::Eb::ReQUIT, | ||||||||||||||||||||
| 62 | "message-expired" => $Sisimai::Eb::ReTIME, | ||||||||||||||||||||
| 63 | "no-answer-from-host" => $Sisimai::Eb::ReINET, | ||||||||||||||||||||
| 64 | "policy-related" => $Sisimai::Eb::ReWONT, | ||||||||||||||||||||
| 65 | "quota-issues" => $Sisimai::Eb::ReFULL,, | ||||||||||||||||||||
| 66 | "routing-errors" => $Sisimai::Eb::RePROC, | ||||||||||||||||||||
| 67 | "spam-related" => $Sisimai::Eb::ReSPAM, | ||||||||||||||||||||
| 68 | }; | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 32 | ▶ | sub xfield { | ||||||||||||||||||
|
Subroutine
xfield: called CC=6 SCAR=18.3
| |||||||||||||||||||||
| 71 | # Returns an array which is compatible with the value returned from Sisimai::RFC1894->field() | ||||||||||||||||||||
| 72 | # @param string argv1 A line of the error message | ||||||||||||||||||||
| 73 | # @return Array ["field-name", "value-type", "value", "field-group", "comment"] | ||||||||||||||||||||
| 74 | # @see https://bird.com/email/power-mta | ||||||||||||||||||||
| 75 | 32 | my $class = shift; | |||||||||||||||||||
| 76 | 32 | ▶ | my $argv1 = shift || return []; | ||||||||||||||||||
|
Condition50%1/2
shift() || (return [])
MC/DC0%0/1
shift() || (return [])
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 32 | my $fieldparts = [split(":", $argv1, 2)]; # ["Final-Recipient", " rfc822; <neko@nyaan.jp>"] | |||||||||||||||||||
| 79 | 32 | my $xfieldname = lc $fieldparts->[0]; # "final-recipient" | |||||||||||||||||||
| 80 | 32 | ▶ | my $xgroupname = $FieldGroup->{ $xfieldname }; return [] unless $xgroupname; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | 32 | my $xfieldlist = ["", "", Sisimai::String->sweep($fieldparts->[1]), $xgroupname, "", "PowerMTA"]; | |||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | # - 0: Field-Name | ||||||||||||||||||||
| 84 | # - 1: Sub Type: RFC822, DNS, X-Unix, and so on) | ||||||||||||||||||||
| 85 | # - 2: Value | ||||||||||||||||||||
| 86 | # - 3: Field Group(addr, code, date, host, stat, text) | ||||||||||||||||||||
| 87 | # - 4: Comment | ||||||||||||||||||||
| 88 | # - 5: 3rd Party MTA-Name | ||||||||||||||||||||
| 89 | 32 | ▶ | if( $xfieldname eq "x-powermta-bouncecategory" ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 90 | # X-PowerMTA-BounceCategory: bad-mailbox | ||||||||||||||||||||
| 91 | # Set the bounce reason picked from the value of the field | ||||||||||||||||||||
| 92 | 16 | $xfieldlist->[0] = $xfieldname; | |||||||||||||||||||
| 93 | 16 | ▶ | $xfieldlist->[4] = sprintf("reason:%s", $MessagesOf->{ $xfieldlist->[2] } || ""); | ||||||||||||||||||
|
Condition50%1/2
$$MessagesOf{$xfieldlist->[2]} || ''
MC/DC0%0/1
$$MessagesOf{$xfieldlist->[2]} || ''
$$MessagesOf{$xfieldlist->[2]}
Truth table50%1/2
A
A= $$MessagesOf{$xfieldlist->[2]}
| |||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | } elsif( $xfieldname eq "x-powermta-virtualmta" ) { | ||||||||||||||||||||
| 96 | # X-PowerMTA-VirtualMTA: mx22.neko.example.jp | ||||||||||||||||||||
| 97 | 16 | $xfieldlist->[0] = "Reporting-MTA"; | |||||||||||||||||||
| 98 | } | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 32 | return $xfieldlist; | |||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 33 | 1; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||