| 1 | package Sisimai::RFC3464::ThirdPartyscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/; |
| 2 | use v5.26scip-perl cpan Sisimai v5.7.0 `v5.26`/; |
| 3 | use strictscip-perl cpan Sisimai v5.7.0 strict/; |
| 4 | use warningsscip-perl cpan Sisimai v5.7.0 warnings/; |
| 5 | |
| 6 | state $ThirdParty = { |
| 7 | #"Aol" => ["X-Outbound-Mail-Relay-"], # X-Outbound-Mail-Relay-(Queue-ID|Sender) |
| 8 | "PowerMTA" => ["X-PowerMTA-"], # X-PowerMTA-(VirtualMTA|BounceCategory) |
| 9 | #"Yandex" => ["X-Yandex-"], # X-Yandex-(Queue-ID|Sender) |
| 10 | }; |
| 11 | |
| 12 | sub is3rdpartyscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/is3rdparty(). { |
| 13 | # is3rdparty() returns true if the argument is a line generated by a MTA which have fields defined |
| 14 | # in RFC3464 inside of a bounce mail the MTA returns |
| 15 | # @param string argv1 A line of a bounce mail |
| 16 | # @return bool The line indicates that a bounce mail generated by the 3rd party MTA |
| 17 | my $class = shiftscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/shift().; |
| 18 | my $argv1 = shiftscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/shift(). || return 0; return __PACKAGE__->returnedbyscip-perl cpan Sisimai v5.7.0 __PACKAGE__/returnedby().($argv1) ? 1 : 0; |
| 19 | } |
| 20 | |
| 21 | sub returnedbyscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/returnedby(). { |
| 22 | # returnedby() returns an MTA name of the 3rd party |
| 23 | # @param string argv1 A line of a bounce mail |
| 24 | # @return string An MTA name of the 3rd party |
| 25 | my $class = shiftscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/shift().; |
| 26 | my $argv1 = shiftscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/shift(). || return 0; return 0 unless indexscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/index().($argv1, "X-") == 0; |
| 27 | |
| 28 | for my $e ( keysscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/keys(). %$ThirdParty ) { |
| 29 | # Does the argument include the 3rd party specific field? |
| 30 | return $e if indexscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/index().($argv1, $ThirdParty->{ $e }->[0]) == 0; |
| 31 | } |
| 32 | return "" |
| 33 | } |
| 34 | |
| 35 | sub xfieldscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/xfield(). { |
| 36 | # xfield() returns rfc1894.Field() compatible slice for the specific field of the 3rd party MTA |
| 37 | # @param string argv1 A line of the error message |
| 38 | # @return [] RFC1894->field() compatible array |
| 39 | # @see Sisimai::RFC1894 |
| 40 | my $class = shiftscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/shift().; |
| 41 | my $argv1 = shiftscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/shift(). || return []; |
| 42 | my $party = __PACKAGE__->returnedbyscip-perl cpan Sisimai v5.7.0 __PACKAGE__/returnedby().($argv1); return [] unless $party; |
| 43 | return sprintfscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/sprintf().("Sisimai::RFC3464::ThirdParty::%s", $party)->xfieldscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/xfield().($argv1); |
| 44 | } |
| 45 | 1; |
| 46 | |
| 47 | # ------------------------------------------------------------------------------------------------- |
| 48 | package Sisimai::RFC3464::ThirdParty::PowerMTAscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/PowerMTA/; |
| 49 | use v5.26scip-perl cpan Sisimai v5.7.0 `v5.26`/; |
| 50 | use strictscip-perl cpan Sisimai v5.7.0 strict/; |
| 51 | use warningsscip-perl cpan Sisimai v5.7.0 warnings/; |
| 52 | |
| 53 | state $FieldGroup = { |
| 54 | "x-powermta-virtualmta" => "host", # X-PowerMTA-VirtualMTA: mx22.neko.example.jp |
| 55 | "x-powermta-bouncecategory" => "text", # X-PowerMTA-BounceCategory: bad-mailbox |
| 56 | }; |
| 57 | state $MessagesOf = { |
| 58 | "bad-domain" => "hostunknown", |
| 59 | "bad-mailbox" => "userunknown", |
| 60 | "inactive-mailbox" => "suspend", |
| 61 | "message-expired" => "expired", |
| 62 | "no-answer-from-host" => "networkerror", |
| 63 | "policy-related" => "policyviolation", |
| 64 | "quota-issues" => "mailboxfull", |
| 65 | "routing-errors" => "systemerror", |
| 66 | "spam-related" => "spamdetected", |
| 67 | }; |
| 68 | |
| 69 | sub xfieldscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/PowerMTA/xfield(). { |
| 70 | # Returns an array which is compatible with the value returned from Sisimai::RFC1894->field() |
| 71 | # @param string argv1 A line of the error message |
| 72 | # @return Array ["field-name", "value-type", "value", "field-group", "comment"] |
| 73 | # @see https://bird.com/email/power-mta |
| 74 | my $class = shiftscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/PowerMTA/shift().; |
| 75 | my $argv1 = shiftscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/PowerMTA/shift(). || return []; |
| 76 | |
| 77 | my $fieldparts = [splitscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/PowerMTA/split().(":", $argv1, 2)]; # ["Final-Recipient", " rfc822; <[email protected]>"] |
| 78 | my $xfieldname = lcscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/PowerMTA/lc(). $fieldparts->[0]; # "final-recipient" |
| 79 | my $xgroupname = $FieldGroup->{ $xfieldname }; return [] unless $xgroupname; |
| 80 | my $xfieldlist = ["", "", Sisimai::String->sweepscip-perl cpan Sisimai v5.7.0 Sisimai/String/sweep().($fieldparts->[1]), $xgroupname, "", "PowerMTA"]; |
| 81 | |
| 82 | # - 0: Field-Name |
| 83 | # - 1: Sub Type: RFC822, DNS, X-Unix, and so on) |
| 84 | # - 2: Value |
| 85 | # - 3: Field Group(addr, code, date, host, stat, text) |
| 86 | # - 4: Comment |
| 87 | # - 5: 3rd Party MTA-Name |
| 88 | if( $xfieldname eq "x-powermta-bouncecategory" ) { |
| 89 | # X-PowerMTA-BounceCategory: bad-mailbox |
| 90 | # Set the bounce reason picked from the value of the field |
| 91 | $xfieldlist->[0] = $xfieldname; |
| 92 | $xfieldlist->[4] = sprintfscip-perl cpan Sisimai v5.7.0 Sisimai/RFC3464/ThirdParty/PowerMTA/sprintf().("reason:%s", $MessagesOf->{ $xfieldlist->[2] } || ""); |
| 93 | |
| 94 | } elsif( $xfieldname eq "x-powermta-virtualmta" ) { |
| 95 | # X-PowerMTA-VirtualMTA: mx22.neko.example.jp |
| 96 | $xfieldlist->[0] = "Reporting-MTA"; |
| 97 | } |
| 98 | |
| 99 | return $xfieldlist; |
| 100 | } |
| 101 | |
| 102 | 1; |
| 103 | |
| 104 | __END__ |
| 105 | =encoding utf-8 |
| 106 | |
| 107 | =head1 NAME |
| 108 | |
| 109 | Sisimai::RFC3464::ThirdParty - bounce mail decoder class for a bounce mail which have fields defined |
| 110 | in RFC3464 and some fields begin with "X-" |
| 111 | |
| 112 | =head1 SYNOPSIS |
| 113 | |
| 114 | use Sisimai::RFC3464::ThirdParty; |
| 115 | |
| 116 | =head1 DESCRIPTION |
| 117 | |
| 118 | C<Sisimai::RFC3464::ThirdParty> is a class which called from called from only C<Sisimai::RFC3464> |
| 119 | when the bounce message have a field which begins with "X-" such as "X-PowerMTA-BounceCategory:" |
| 120 | |
| 121 | =head1 CLASS METHODS |
| 122 | |
| 123 | =head2 C<B<is3rdparty()>> |
| 124 | |
| 125 | C<is3rdparty()> method returns true when the argument is a supported "X-" field |
| 126 | |
| 127 | print Sisimai::RFC3464->is3rdparty(); |
| 128 | |
| 129 | =head2 C<B<inquire(I<header data>, I<reference to body string>)>> |
| 130 | |
| 131 | C<inquire()> method method decodes a bounced email and return results as an array reference. |
| 132 | See C<Sisimai::Message> for more details. |
| 133 | |
| 134 | =head1 AUTHOR |
| 135 | |
| 136 | azumakuniyuki |
| 137 | |
| 138 | =head1 COPYRIGHT |
| 139 | |
| 140 | Copyright (C) 2024,2025 azumakuniyuki, All rights reserved. |
| 141 | |
| 142 | =head1 LICENSE |
| 143 | |
| 144 | This software is distributed under The BSD 2-Clause License. |
| 145 | |
| 146 | =cut |
| 147 |