| 1 | package Sisimai::Lhost::Courier; | ||||||||||||||||||||||||||||
| 2 | 37 | ▶ | use parent 'Sisimai::Lhost'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 37 | ▶ | use v5.26; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 37 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 37 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | sub description { 'Courier MTA' } | ||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 8 | 893 | ▶ | sub inquire { | ||||||||||||||||||||||||||
|
Subroutine
inquire: called CC=43 SCAR=39.5
Pod
documented
| |||||||||||||||||||||||||||||
| 9 | # Detect an error from Courier MTA | ||||||||||||||||||||||||||||
| 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.0.0 | ||||||||||||||||||||||||||||
| 15 | 893 | my $class = shift; | |||||||||||||||||||||||||||
| 16 | 893 | ▶ | 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 | 892 | ▶ | 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 | 891 | ▶ | my $match = 0; $match ||= 1 if index($mhead->{'from'}, 'Courier mail server at ') > -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$match ||= 1
MC/DC0%0/1
$match ||= 1
$match
Truth table0%0/2
A
A= $match
| |||||||||||||||||||||||||||||
| 19 | 891 | ▶ | $match ||= 1 if index($mhead->{'subject'}, 'NOTICE: mail delivery status.') > -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$match ||= 1
MC/DC0%0/1
$match ||= 1
$match
Truth table50%1/2
A
A= $match
| |||||||||||||||||||||||||||||
| 20 | 891 | ▶ | $match ||= 1 if index($mhead->{'subject'}, 'WARNING: delayed mail.') > -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$match ||= 1
MC/DC0%0/1
$match ||= 1
$match
Truth table0%0/2
A
A= $match
| |||||||||||||||||||||||||||||
| 21 | 891 | ▶ | if( defined $mhead->{'message-id'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | # Message-ID: <courier.4D025E3A.00001792@5jo.example.org> | ||||||||||||||||||||||||||||
| 23 | 829 | ▶ | $match ||= 1 if index($mhead->{'message-id'}, '<courier.') == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$match ||= 1
MC/DC0%0/1
$match ||= 1
$match
Truth table50%1/2
A
A= $match
| |||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | 891 | ▶ | return undef unless $match; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 21 | require Sisimai::Eb; | |||||||||||||||||||||||||||
| 28 | 21 | require Sisimai::RFC1123; | |||||||||||||||||||||||||||
| 29 | 21 | require Sisimai::SMTP::Command; | |||||||||||||||||||||||||||
| 30 | 21 | state $indicators = __PACKAGE__->INDICATORS; | |||||||||||||||||||||||||||
| 31 | 21 | state $boundaries = ['Content-Type: :message/rfc822', 'Content-Type: text/rfc822-headers']; | |||||||||||||||||||||||||||
| 32 | 21 | state $startingof = { | |||||||||||||||||||||||||||
| 33 | # https://www.courier-mta.org/courierdsn.html | ||||||||||||||||||||||||||||
| 34 | # courier/module.dsn/dsn*.txt | ||||||||||||||||||||||||||||
| 35 | 'message' => ['DELAYS IN DELIVERING YOUR MESSAGE', 'UNDELIVERABLE MAIL'], | ||||||||||||||||||||||||||||
| 36 | }; | ||||||||||||||||||||||||||||
| 37 | 21 | state $messagesof = { | |||||||||||||||||||||||||||
| 38 | # courier/module.esmtp/esmtpclient.c:526| hard_error(del, ctf, "No such domain."); | ||||||||||||||||||||||||||||
| 39 | $Sisimai::Eb::ReHOST => ['No such domain.'], | ||||||||||||||||||||||||||||
| 40 | # courier/module.esmtp/esmtpclient.c:531| hard_error(del, ctf, | ||||||||||||||||||||||||||||
| 41 | # courier/module.esmtp/esmtpclient.c:532| "This domain's DNS violates RFC 1035."); | ||||||||||||||||||||||||||||
| 42 | $Sisimai::Eb::RePROC => ["This domain's DNS violates RFC 1035."], | ||||||||||||||||||||||||||||
| 43 | # courier/module.esmtp/esmtpclient.c:535| soft_error(del, ctf, "DNS lookup failed."); | ||||||||||||||||||||||||||||
| 44 | $Sisimai::Eb::ReINET => ['DNS lookup failed.'], | ||||||||||||||||||||||||||||
| 45 | }; | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 21 | ▶ | 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)
| |||||||||||||||||||||||||||||
| 48 | 21 | my $fieldtable = Sisimai::RFC1894->FIELDTABLE; | |||||||||||||||||||||||||||
| 49 | 21 | my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef; | |||||||||||||||||||||||||||
| 50 | 21 | my $permessage = {}; # (Hash) Store values of each Per-Message field | |||||||||||||||||||||||||||
| 51 | 21 | my $readcursor = 0; # (Integer) Points the current cursor position | |||||||||||||||||||||||||||
| 52 | 21 | my $recipients = 0; # (Integer) The number of 'Final-Recipient' header | |||||||||||||||||||||||||||
| 53 | 21 | my $thecommand = ''; # (String) SMTP Command name begin with the string '>>>' | |||||||||||||||||||||||||||
| 54 | 21 | my $p = ''; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 21 | for my $e ( split("\n", $emailparts->[0]) ) { | |||||||||||||||||||||||||||
| 57 | # Read error messages and delivery status lines from the head of the email to the previous | ||||||||||||||||||||||||||||
| 58 | # line of the beginning of the original message. | ||||||||||||||||||||||||||||
| 59 | 1060 | ▶ | unless( $readcursor ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | # Beginning of the bounce message or message/delivery-status part | ||||||||||||||||||||||||||||
| 61 | 252 | ▶ | if( rindex($e, $startingof->{'message'}->[0]) > -1 || rindex($e, $startingof->{'message'}->[1]) > -1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
rindex($e, $startingof->{"message"}[0]) != -1 or rindex($e, $startingof->{"message"}[1]) != -1
MC/DC50%1/2
rindex($e, $startingof->{"message"}[0]) != -1 or rindex($e, $startingof->{"message"}[1]) != -1
rindex($e, $startingof->{"message"}[0]) != -1
rindex($e, $startingof->{"message"}[1]) != -1
Truth table66%2/3
A or B
A= rindex($e, $startingof->{"message"}[0]) != -1B= rindex($e, $startingof->{"message"}[1]) != -1
| |||||||||||||||||||||||||||||
| 62 | 21 | $readcursor |= $indicators->{'deliverystatus'}; | |||||||||||||||||||||||||||
| 63 | 21 | next; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 1039 | ▶ | 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 ""
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 609 | ▶ | if( my $f = Sisimai::RFC1894->match($e) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | # $e matched with any field defined in RFC3464 | ||||||||||||||||||||||||||||
| 70 | 163 | ▶ | next unless my $o = Sisimai::RFC1894->field($e); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 163 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 163 | ▶ | if( $o->[3] eq 'addr' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 74 | # Final-Recipient: rfc822; kijitora@example.jp | ||||||||||||||||||||||||||||
| 75 | # X-Actual-Recipient: rfc822; kijitora@example.co.jp | ||||||||||||||||||||||||||||
| 76 | 21 | ▶ | if( $o->[0] eq 'final-recipient' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | # Final-Recipient: rfc822; kijitora@example.jp | ||||||||||||||||||||||||||||
| 78 | 21 | ▶ | if( $v->{'recipient'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | # There are multiple recipient addresses in the message body. | ||||||||||||||||||||||||||||
| 80 | 0 | push @$dscontents, __PACKAGE__->DELIVERYSTATUS; | |||||||||||||||||||||||||||
| 81 | 0 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | 21 | $v->{'recipient'} = $o->[2]; | |||||||||||||||||||||||||||
| 84 | 21 | $recipients++; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | } else { | ||||||||||||||||||||||||||||
| 87 | # X-Actual-Recipient: rfc822; kijitora@example.co.jp | ||||||||||||||||||||||||||||
| 88 | 0 | $v->{'alias'} = $o->[2]; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | } elsif( $o->[3] eq 'code' ) { | ||||||||||||||||||||||||||||
| 91 | # Diagnostic-Code: SMTP; 550 5.1.1 <userunknown@example.jp>... User Unknown | ||||||||||||||||||||||||||||
| 92 | 21 | $v->{'spec'} = $o->[1]; | |||||||||||||||||||||||||||
| 93 | 21 | $v->{'diagnosis'} = $o->[2]; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | } else { | ||||||||||||||||||||||||||||
| 96 | # Other DSN fields defined in RFC3464 | ||||||||||||||||||||||||||||
| 97 | 121 | ▶ | next unless exists $fieldtable->{ $o->[0] }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 121 | ▶ | 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
| |||||||||||||||||||||||||||||
| 99 | 99 | $v->{ $fieldtable->{ $o->[0] } } = $o->[2]; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 99 | ▶ | next unless $f == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 57 | $permessage->{ $fieldtable->{ $o->[0] } } = $o->[2]; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | } else { | ||||||||||||||||||||||||||||
| 105 | # The line does not begin with a DSN field defined in RFC3464 | ||||||||||||||||||||||||||||
| 106 | # | ||||||||||||||||||||||||||||
| 107 | # This is a delivery status notification from marutamachi.example.org, | ||||||||||||||||||||||||||||
| 108 | # running the Courier mail server, version 0.65.2. | ||||||||||||||||||||||||||||
| 109 | # | ||||||||||||||||||||||||||||
| 110 | # The original message was received on Sat, 11 Dec 2010 12:19:57 +0900 | ||||||||||||||||||||||||||||
| 111 | # from [127.0.0.1] (c10920.example.com [192.0.2.20]) | ||||||||||||||||||||||||||||
| 112 | # | ||||||||||||||||||||||||||||
| 113 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 114 | # | ||||||||||||||||||||||||||||
| 115 | # UNDELIVERABLE MAIL | ||||||||||||||||||||||||||||
| 116 | # | ||||||||||||||||||||||||||||
| 117 | # Your message to the following recipients cannot be delivered: | ||||||||||||||||||||||||||||
| 118 | # | ||||||||||||||||||||||||||||
| 119 | # <kijitora@example.co.jp>: | ||||||||||||||||||||||||||||
| 120 | # mx.example.co.jp [74.207.247.95]: | ||||||||||||||||||||||||||||
| 121 | # >>> RCPT TO:<kijitora@example.co.jp> | ||||||||||||||||||||||||||||
| 122 | # <<< 550 5.1.1 <kijitora@example.co.jp>... User Unknown | ||||||||||||||||||||||||||||
| 123 | # | ||||||||||||||||||||||||||||
| 124 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 125 | 446 | ▶ | if( index($e, '>>> ') == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | # >>> DATA | ||||||||||||||||||||||||||||
| 127 | 16 | $thecommand = Sisimai::SMTP::Command->find($e); | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | } else { | ||||||||||||||||||||||||||||
| 130 | # Continued line of the value of Diagnostic-Code field | ||||||||||||||||||||||||||||
| 131 | 430 | ▶ | next unless index($p, 'Diagnostic-Code:') == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 5 | ▶ | next unless index($e, ' ') == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 5 | $v->{'diagnosis'} .= ' '.$e; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | } continue { | ||||||||||||||||||||||||||||
| 137 | # Save the current line for the next loop | ||||||||||||||||||||||||||||
| 138 | 1060 | $p = $e; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | 21 | ▶ | return undef unless $recipients; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 21 | for my $e ( @$dscontents ) { | |||||||||||||||||||||||||||
| 143 | # Set default values if each value is empty. | ||||||||||||||||||||||||||||
| 144 | 21 | ▶ | $e->{ $_ } ||= $permessage->{ $_ } || '' for keys %$permessage; | ||||||||||||||||||||||||||
|
Condition20%1/5
$e->{$_} ||= $permessage->{$_} || ""
$permessage->{$_} || ''
MC/DC0%0/2
$e->{$_} ||= $permessage->{$_} || ""
$e->{$_}
$permessage->{$_}
Truth table33%1/3
A ||= B
A= $e->{$_}B= $permessage->{$_}
| |||||||||||||||||||||||||||||
| 145 | 21 | $e->{'diagnosis'} = Sisimai::String->sweep($e->{'diagnosis'}); | |||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 21 | for my $r ( keys %$messagesof ) { | |||||||||||||||||||||||||||
| 148 | # Verify each regular expression of session errors | ||||||||||||||||||||||||||||
| 149 | 54 | ▶ | next unless grep { index($e->{'diagnosis'}, $_) > -1 } $messagesof->{ $r }->@*; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 5 | $e->{'reason'} = $r; | |||||||||||||||||||||||||||
| 151 | 5 | last; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | 21 | ▶ | $e->{'command'} ||= $thecommand || ''; | ||||||||||||||||||||||||||
|
Condition80%4/5
$e->{"command"} ||= $thecommand || ""
$thecommand || ''
MC/DC50%1/2
$e->{"command"} ||= $thecommand || ""
$e->{"command"}
$thecommand
Truth table66%2/3
A ||= B
A= $e->{"command"}B= $thecommand
| |||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | 21 | return {"ds" => $dscontents, "rfc822" => $emailparts->[1]}; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 37 | 1; | |||||||||||||||||||||||||||
| 159 | __END__ | ||||||||||||||||||||||||||||