| 1 | package Sisimai::Lhost::mFILTER; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 38 | ▶ | use parent 'Sisimai::Lhost'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 38 | ▶ | use v5.26; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 38 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 38 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | sub description { 'Digital Arts m-FILTER: https://www.daj.jp/bs/mf/' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 905 | ▶ | sub inquire { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inquire: called CC=38 SCAR=37.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | # Detect an error from Digital Arts m-FILTER | ||||||||||||||||||||||||||||||||||||||||||
| 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.1 | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 905 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 905 | ▶ | 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 | 904 | ▶ | 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 | 903 | state $indicators = __PACKAGE__->INDICATORS; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 903 | state $boundaries = ['-------original message', '-------original mail info']; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 903 | state $startingof = { | |||||||||||||||||||||||||||||||||||||||||
| 22 | 'command' => ['-------SMTP command'], | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 'error' => ['-------server message'], | ||||||||||||||||||||||||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | # X-Mailer: m-FILTER | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 903 | my $proceedsto = 0; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 903 | ▶ | $proceedsto = 1 if defined $mhead->{'x-mailer'} && $mhead->{'x-mailer'} eq 'm-FILTER'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $mhead->{"x-mailer"} and $mhead->{"x-mailer"} eq "m-FILTER"
MC/DC100%2/2
defined $mhead->{"x-mailer"} and $mhead->{"x-mailer"} eq "m-FILTER"
defined $mhead->{"x-mailer"}
$mhead->{"x-mailer"} eq "m-FILTER"
Truth table100%3/3
A and B
A= defined $mhead->{"x-mailer"}B= $mhead->{"x-mailer"} eq "m-FILTER"
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 903 | ▶ | $proceedsto ||= 1 if grep { index($$mbody, $_) > 1 } @$boundaries; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$proceedsto ||= 1
MC/DC100%1/1
$proceedsto ||= 1
$proceedsto
Truth table100%2/2
A
A= $proceedsto
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 903 | ▶ | $proceedsto ||= 1 if grep { index($$mbody, $_) > 1 } $startingof->{'command'}->@*; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$proceedsto ||= 1
MC/DC0%0/1
$proceedsto ||= 1
$proceedsto
Truth table50%1/2
A
A= $proceedsto
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 903 | ▶ | $proceedsto ||= 1 if grep { index($$mbody, $_) > 1 } $startingof->{'error'}->@*; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$proceedsto ||= 1
MC/DC0%0/1
$proceedsto ||= 1
$proceedsto
Truth table50%1/2
A
A= $proceedsto
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 903 | ▶ | return undef unless $proceedsto; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 27 | ▶ | 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)
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 27 | my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 27 | my $readcursor = 0; # (Integer) Points the current cursor position | |||||||||||||||||||||||||||||||||||||||||
| 37 | 27 | my $recipients = 0; # (Integer) The number of 'Final-Recipient' header | |||||||||||||||||||||||||||||||||||||||||
| 38 | 27 | my $markingset = {'diagnosis' => 0, 'command' => 0}; | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 27 | for my $e ( split("\n", $emailparts->[0]) ) { | |||||||||||||||||||||||||||||||||||||||||
| 41 | # Read error messages and delivery status lines from the head of the email to the previous | ||||||||||||||||||||||||||||||||||||||||||
| 42 | # line of the beginning of the original message. | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 351 | ▶ | unless( $readcursor ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | # Beginning of the bounce message or message/delivery-status part | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 162 | ▶ | if( index($e, '@') > 1 && index($e, ' ') < 0 && Sisimai::Address->is_emailaddress($e) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
index($e, "\@") > 1 and index($e, " ") == -1 and "Sisimai::Address"->is_emailaddress($e)
index($e, "\@") > 1 and index($e, " ") == -1
MC/DC66%2/3
index($e, "\@") > 1 and index($e, " ") == -1 and "Sisimai::Address"->is_emailaddress($e)
index($e, "\@") > 1
index($e, " ") == -1
"Sisimai::Address"->is_emailaddress($e)
Truth table75%3/4
A and B and C
A= index($e, "\@") > 1B= index($e, " ") == -1C= "Sisimai::Address"->is_emailaddress($e)
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 27 | $readcursor |= $indicators->{'deliverystatus'}; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 351 | ▶ | next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq ""; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
MC/DC100%2/2
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
($readcursor & $indicators->{"deliverystatus"}) == 0
$e eq ""
Truth table100%3/3
A or B
A= ($readcursor & $indicators->{"deliverystatus"}) == 0B= $e eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | # このメールは「m-FILTER」が自動的に生成して送信しています。 | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # メールサーバーとの通信中、下記の理由により | ||||||||||||||||||||||||||||||||||||||||||
| 53 | # このメールは送信できませんでした。 | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # 以下のメールアドレスへの送信に失敗しました。 | ||||||||||||||||||||||||||||||||||||||||||
| 56 | # kijitora@example.jp | ||||||||||||||||||||||||||||||||||||||||||
| 57 | # | ||||||||||||||||||||||||||||||||||||||||||
| 58 | # | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # -------server message | ||||||||||||||||||||||||||||||||||||||||||
| 60 | # 550 5.1.1 unknown user <kijitora@example.jp> | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # -------SMTP command | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # DATA | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # -------original message | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 135 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 135 | ▶ | if( index($e, '@') > 0 && index($e, ' ') < 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
index($e, "\@") > 0 and index($e, " ") == -1
MC/DC100%2/2
index($e, "\@") > 0 and index($e, " ") == -1
index($e, "\@") > 0
index($e, " ") == -1
Truth table100%3/3
A and B
A= index($e, "\@") > 0B= index($e, " ") == -1
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | # 以下のメールアドレスへの送信に失敗しました。 | ||||||||||||||||||||||||||||||||||||||||||
| 70 | # kijitora@example.jp | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 27 | ▶ | if( $v->{'recipient'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | # There are multiple recipient addresses in the message body. | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | push @$dscontents, __PACKAGE__->DELIVERYSTATUS; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 27 | $v->{'recipient'} = $e; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 27 | $recipients++; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | ▶ | } elsif( length $e == 4 && index($e, ' ') < 0 ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
length $e == 4 and index($e, " ") == -1
MC/DC50%1/2
length $e == 4 and index($e, " ") == -1
length $e == 4
index($e, " ") == -1
Truth table66%2/3
A and B
A= length $e == 4B= index($e, " ") == -1
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | # -------SMTP command | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # DATA | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 27 | ▶ | next if $v->{'command'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 27 | ▶ | $v->{'command'} = $e if $markingset->{'command'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # Get error message and SMTP command | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 81 | ▶ | if( $e eq $startingof->{'error'}->[0] ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | # -------server message | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 27 | $markingset->{'diagnosis'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | } elsif( $e eq $startingof->{'command'}->[0] ) { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | # -------SMTP command | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 27 | $markingset->{'command'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # 550 5.1.1 unknown user <kijitora@example.jp> | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 27 | ▶ | next if index($e, '-') == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 27 | ▶ | next if $v->{'diagnosis'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 27 | $v->{'diagnosis'} = $e; | |||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | } # End of error message part | ||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 27 | ▶ | return undef unless $recipients; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 27 | for my $e ( @$dscontents ) { | |||||||||||||||||||||||||||||||||||||||||
| 106 | # Get localhost and remote host name from Received header. | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 27 | ▶ | next unless scalar $mhead->{'received'}->@*; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 27 | my $rheads = $mhead->{'received'}; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 27 | my $rhosts = Sisimai::RFC5322->received($rheads->[-1]); | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 27 | ▶ | $e->{'lhost'} ||= shift Sisimai::RFC5322->received($rheads->[0])->@*; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$e->{"lhost"} ||= shift @{"Sisimai::RFC5322"->received($rheads->[0])}
MC/DC0%0/2
$e->{"lhost"} ||= shift @{"Sisimai::RFC5322"->received($rheads->[0])}
$e->{"lhost"}
shift @{"Sisimai::RFC5322"->received($rheads->[0])}
Truth table33%1/3
A ||= B
A= $e->{"lhost"}B= shift @{"Sisimai::RFC5322"->received($rheads->[0])}
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 27 | for my $ee ( $rhosts->[0], $rhosts->[1] ) { | |||||||||||||||||||||||||||||||||||||||||
| 113 | # Avoid "... by m-FILTER" | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 54 | ▶ | next unless rindex($ee, '.') > -1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 27 | $e->{'rhost'} = $ee; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | 27 | return {"ds" => $dscontents, "rfc822" => $emailparts->[1]}; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 38 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 122 | __END__ | ||||||||||||||||||||||||||||||||||||||||||