| 1 | package Sisimai::Lhost::MessagingServer; | ||||||||||||||||||||||||||||||||||||||||||||
| 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 { 'Oracle Communications Messaging Server: https://docs.oracle.com/en/industries/communications/messaging-server/index.html' } | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 8 | 933 | ▶ | sub inquire { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inquire: called CC=34 SCAR=36.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 9 | # Detect an error from Oracle Communications Messaging Server | ||||||||||||||||||||||||||||||||||||||||||||
| 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.3 | ||||||||||||||||||||||||||||||||||||||||||||
| 15 | 933 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 933 | ▶ | 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 | 932 | ▶ | 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 | 931 | ▶ | my $match = 0; $match ||= 1 if rindex($mhead->{'content-type'}, 'Boundary_(ID_') > -1; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$match ||= 1
MC/DC0%0/1
$match ||= 1
$match
Truth table50%1/2
A
A= $match
| |||||||||||||||||||||||||||||||||||||||||||||
| 19 | 931 | ▶ | $match ||= 1 if index($mhead->{'subject'}, 'Delivery Notification: ') == 0; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$match ||= 1
MC/DC0%0/1
$match ||= 1
$match
Truth table50%1/2
A
A= $match
| |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 931 | ▶ | return undef unless $match; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | 61 | state $indicators = __PACKAGE__->INDICATORS; | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 61 | state $boundaries = ['Content-Type: message/rfc822', 'Return-path: ']; | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 61 | state $startingof = {'message' => ['This report relates to a message you sent with the following header fields:']}; | |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 61 | ▶ | 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)
| |||||||||||||||||||||||||||||||||||||||||||||
| 27 | 61 | my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef; | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 61 | my $readcursor = 0; # (Integer) Points the current cursor position | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 61 | my $recipients = 0; # (Integer) The number of 'Final-Recipient' header | |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | 61 | for my $e ( split("\n", $emailparts->[0]) ) { | |||||||||||||||||||||||||||||||||||||||||||
| 32 | # Read error messages and delivery status lines from the head of the email to the previous | ||||||||||||||||||||||||||||||||||||||||||||
| 33 | # line of the beginning of the original message. | ||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2028 | ▶ | unless( $readcursor ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 35 | # Beginning of the bounce message or message/delivery-status part | ||||||||||||||||||||||||||||||||||||||||||||
| 36 | 61 | ▶ | $readcursor |= $indicators->{'deliverystatus'} if index($e, $startingof->{'message'}->[0]) == 0; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 61 | next; | |||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1967 | ▶ | 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 ""
| |||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | # --Boundary_(ID_0000000000000000000000) | ||||||||||||||||||||||||||||||||||||||||||||
| 42 | # Content-type: text/plain; charset=us-ascii | ||||||||||||||||||||||||||||||||||||||||||||
| 43 | # Content-language: en-US | ||||||||||||||||||||||||||||||||||||||||||||
| 44 | # | ||||||||||||||||||||||||||||||||||||||||||||
| 45 | # This report relates to a message you sent with the following header fields: | ||||||||||||||||||||||||||||||||||||||||||||
| 46 | # | ||||||||||||||||||||||||||||||||||||||||||||
| 47 | # Message-id: <CD8C6134-C312-41D5-B083-366F7FA1D752@me.example.com> | ||||||||||||||||||||||||||||||||||||||||||||
| 48 | # Date: Fri, 21 Nov 2014 23:34:45 +0900 | ||||||||||||||||||||||||||||||||||||||||||||
| 49 | # From: Shironeko <shironeko@me.example.com> | ||||||||||||||||||||||||||||||||||||||||||||
| 50 | # To: kijitora@example.jp | ||||||||||||||||||||||||||||||||||||||||||||
| 51 | # Subject: Nyaaaaaaaaaaaaaaaaaaaaaan | ||||||||||||||||||||||||||||||||||||||||||||
| 52 | # | ||||||||||||||||||||||||||||||||||||||||||||
| 53 | # Your message cannot be delivered to the following recipients: | ||||||||||||||||||||||||||||||||||||||||||||
| 54 | # | ||||||||||||||||||||||||||||||||||||||||||||
| 55 | # Recipient address: kijitora@example.jp | ||||||||||||||||||||||||||||||||||||||||||||
| 56 | # Reason: Remote SMTP server has rejected address | ||||||||||||||||||||||||||||||||||||||||||||
| 57 | # Diagnostic code: smtp;550 5.1.1 <kijitora@example.jp>... User Unknown | ||||||||||||||||||||||||||||||||||||||||||||
| 58 | # Remote system: dns;mx.example.jp (TCP|17.111.174.67|47323|192.0.2.225|25) (6jo.example.jp ESMTP SENDMAIL-VM) | ||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1526 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1526 | ▶ | if( Sisimai::String->aligned(\$e, [' Recipient address: ', '@', '.']) || | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition100%3/3
"Sisimai::String"->aligned(\$e, [" Recipient address: ", "\@", "."]) or "Sisimai::String"->aligned(\$e, [" Original address: ", "\@", "."])
MC/DC100%2/2
"Sisimai::String"->aligned(\$e, [" Recipient address: ", "\@", "."]) or "Sisimai::String"->aligned(\$e, [" Original address: ", "\@", "."])
"Sisimai::String"->aligned(\$e, [" Recipient address: ", "\@", "."])
"Sisimai::String"->aligned(\$e, [" Original address: ", "\@", "."])
Truth table100%3/3
A or B
A= "Sisimai::String"->aligned(\$e, [" Recipient address: ", "\@", "."])B= "Sisimai::String"->aligned(\$e, [" Original address: ", "\@", "."])
| |||||||||||||||||||||||||||||||||||||||||||||
| 62 | Sisimai::String->aligned(\$e, [' Original address: ', '@', '.']) ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 63 | # Recipient address: @smtp.example.net:kijitora@server | ||||||||||||||||||||||||||||||||||||||||||||
| 64 | # Original address: kijitora@example.jp | ||||||||||||||||||||||||||||||||||||||||||||
| 65 | 71 | my $cv = Sisimai::Address->s3s4(substr($e, rindex($e, ' ') + 1),); | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 71 | ▶ | next unless Sisimai::Address->is_emailaddress($cv); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 66 | ▶ | if( $v->{'recipient'} && $cv ne $v->{'recipient'}) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$v->{"recipient"} and $cv ne $v->{"recipient"}
MC/DC50%1/2
$v->{"recipient"} and $cv ne $v->{"recipient"}
$v->{"recipient"}
$cv ne $v->{"recipient"}
Truth table66%2/3
A and B
A= $v->{"recipient"}B= $cv ne $v->{"recipient"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 69 | # There are multiple recipient addresses in the message body. | ||||||||||||||||||||||||||||||||||||||||||||
| 70 | 5 | push @$dscontents, __PACKAGE__->DELIVERYSTATUS; | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 5 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 73 | 66 | $v->{'recipient'} = $cv; | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 66 | $recipients++; | |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | } elsif( index($e, ' Date: ') == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 77 | # Date: Fri, 21 Nov 2014 23:34:45 +0900 | ||||||||||||||||||||||||||||||||||||||||||||
| 78 | 61 | $v->{'date'} = substr($e, index($e, ':') + 2,); | |||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | } elsif( index($e, ' Reason: ') == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 81 | # Reason: Remote SMTP server has rejected address | ||||||||||||||||||||||||||||||||||||||||||||
| 82 | 66 | $v->{'diagnosis'} = substr($e, index($e, ':') + 2,); | |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | } elsif( index($e, ' Diagnostic code: ') == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 85 | # Diagnostic code: smtp;550 5.1.1 <kijitora@example.jp>... User Unknown | ||||||||||||||||||||||||||||||||||||||||||||
| 86 | 46 | my $p1 = index($e, ':'); | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 46 | my $p2 = index($e, ';'); | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 46 | $v->{'spec'} = uc substr($e, $p1 + 2, $p2 - $p1 - 2); | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 46 | $v->{'diagnosis'} = substr($e, $p2 + 1,); | |||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | } elsif( index($e, ' Remote system: ') == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 92 | # Remote system: dns;mx.example.jp (TCP|17.111.174.67|47323|192.0.2.225|25) | ||||||||||||||||||||||||||||||||||||||||||||
| 93 | # (6jo.example.jp ESMTP SENDMAIL-VM) | ||||||||||||||||||||||||||||||||||||||||||||
| 94 | 46 | my $p1 = index($e, ';'); | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 46 | my $p2 = index($e, '('); | |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 46 | my $remotehost = substr($e, $p1 + 1, $p2 - $p1 - 2); | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 46 | my $sessionlog = [split('|', substr($e, $p2,))]; | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 46 | $v->{'rhost'} = $remotehost; | |||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | # The value does not include ".", use IP address instead. | ||||||||||||||||||||||||||||||||||||||||||||
| 102 | # (TCP|17.111.174.67|47323|192.0.2.225|25) | ||||||||||||||||||||||||||||||||||||||||||||
| 103 | 46 | ▶ | next unless $sessionlog->[0] eq '(TCP'; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $v->{'lhost'} = $sessionlog->[1]; | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $v->{'rhost'} = $sessionlog->[3] unless index($remotehost, '.') > 1; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 108 | # Original-envelope-id: 0NFC009FLKOUVMA0@mr21p30im-asmtp004.me.com | ||||||||||||||||||||||||||||||||||||||||||||
| 109 | # Reporting-MTA: dns;mr21p30im-asmtp004.me.com (tcp-daemon) | ||||||||||||||||||||||||||||||||||||||||||||
| 110 | # Arrival-date: Thu, 29 Apr 2014 23:34:45 +0000 (GMT) | ||||||||||||||||||||||||||||||||||||||||||||
| 111 | # | ||||||||||||||||||||||||||||||||||||||||||||
| 112 | # Original-recipient: rfc822;kijitora@example.jp | ||||||||||||||||||||||||||||||||||||||||||||
| 113 | # Final-recipient: rfc822;kijitora@example.jp | ||||||||||||||||||||||||||||||||||||||||||||
| 114 | # Action: failed | ||||||||||||||||||||||||||||||||||||||||||||
| 115 | # Status: 5.1.1 (Remote SMTP server has rejected address) | ||||||||||||||||||||||||||||||||||||||||||||
| 116 | # Remote-MTA: dns;mx.example.jp (TCP|17.111.174.67|47323|192.0.2.225|25) | ||||||||||||||||||||||||||||||||||||||||||||
| 117 | # (6jo.example.jp ESMTP SENDMAIL-VM) | ||||||||||||||||||||||||||||||||||||||||||||
| 118 | # Diagnostic-code: smtp;550 5.1.1 <kijitora@example.jp>... User Unknown | ||||||||||||||||||||||||||||||||||||||||||||
| 119 | # | ||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1236 | ▶ | if( index($e, 'Status: ') == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 121 | # Status: 5.1.1 (Remote SMTP server has rejected address) | ||||||||||||||||||||||||||||||||||||||||||||
| 122 | 66 | my $p1 = index($e, ':'); | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 66 | my $p2 = index($e, '('); | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 66 | $v->{'status'} = substr($e, $p1 + 2, $p2 - $p1 - 3); | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 66 | ▶ | $v->{'diagnosis'} ||= substr($e, $p2 + 1, index($e, ')') - $p2 - 1); | ||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$v->{"diagnosis"} ||= substr($e, $p2 + 1, index($e, ")") - $p2 - 1)
MC/DC0%0/2
$v->{"diagnosis"} ||= substr($e, $p2 + 1, index($e, ")") - $p2 - 1)
$v->{"diagnosis"}
substr($e, $p2 + 1, index($e, ")") - $p2 - 1)
Truth table33%1/3
A ||= B
A= $v->{"diagnosis"}B= substr($e, $p2 + 1, index($e, ")") - $p2 - 1)
| |||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | } elsif( index($e, 'Arrival-Date: ') == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 128 | # Arrival-date: Thu, 29 Apr 2014 23:34:45 +0000 (GMT) | ||||||||||||||||||||||||||||||||||||||||||||
| 129 | 51 | ▶ | $v->{'date'} ||= substr($e, index($e, ':') + 2,); | ||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$v->{"date"} ||= substr($e, index($e, ":") + 2)
MC/DC0%0/2
$v->{"date"} ||= substr($e, index($e, ":") + 2)
$v->{"date"}
substr($e, index($e, ":") + 2)
Truth table33%1/3
A ||= B
A= $v->{"date"}B= substr($e, index($e, ":") + 2)
| |||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | } elsif( index($e, 'Reporting-MTA: ') == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
| 132 | # Reporting-MTA: dns;mr21p30im-asmtp004.me.com (tcp-daemon) | ||||||||||||||||||||||||||||||||||||||||||||
| 133 | 61 | my $localhost = substr($e, index($e, ';') + 1,); | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 61 | ▶ | $v->{'lhost'} ||= $localhost; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$v->{"lhost"} ||= $localhost
MC/DC0%0/2
$v->{"lhost"} ||= $localhost
$v->{"lhost"}
$localhost
Truth table33%1/3
A ||= B
A= $v->{"lhost"}B= $localhost
| |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 61 | ▶ | $v->{'lhost'} = $localhost unless index($v->{'lhost'}, '.') > 0; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 137 | } # End of error message part | ||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 139 | 61 | ▶ | return undef unless $recipients; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 61 | return {"ds" => $dscontents, "rfc822" => $emailparts->[1]}; | |||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | 37 | 1; | |||||||||||||||||||||||||||||||||||||||||||
| 144 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||