| 1 | package Sisimai::Lhost::Verizon; | ||||||||||||||||||||||||||||
| 2 | 39 | ▶ | use parent 'Sisimai::Lhost'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 39 | ▶ | use v5.26; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 39 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 39 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | sub description { 'Verizon: https://www.verizon.com/' } | ||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 8 | 899 | ▶ | sub inquire { | ||||||||||||||||||||||||||
|
Subroutine
inquire: called CC=42 SCAR=39.5
Pod
documented
| |||||||||||||||||||||||||||||
| 9 | # Detect an error from Verizon | ||||||||||||||||||||||||||||
| 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 | 899 | my $class = shift; | |||||||||||||||||||||||||||
| 16 | 899 | ▶ | 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 | 898 | ▶ | 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 | 897 | ▶ | return undef unless grep { rindex($_, '.vtext.com (') > -1 } $mhead->{'received'}->@*; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 11 | ▶ | my $match = -1; $match = 1 if $mhead->{'from'} eq 'post_master@vtext.com'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 11 | ▶ | $match = 0 if Sisimai::String->aligned(\$mhead->{'from'}, ['sysadmin@', '.vzwpix.com']); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 11 | ▶ | return undef if $match < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 11 | require Sisimai::Eb; | |||||||||||||||||||||||||||
| 25 | 11 | state $indicators = __PACKAGE__->INDICATORS; | |||||||||||||||||||||||||||
| 26 | 11 | my $boundaries = []; | |||||||||||||||||||||||||||
| 27 | 11 | my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef; | |||||||||||||||||||||||||||
| 28 | 11 | my $emailparts = []; | |||||||||||||||||||||||||||
| 29 | 11 | my $readcursor = 0; # (Integer) Points the current cursor position | |||||||||||||||||||||||||||
| 30 | 11 | my $recipients = 0; # (Integer) The number of 'Final-Recipient' header | |||||||||||||||||||||||||||
| 31 | 11 | my $senderaddr = ''; # (String) Sender address in the message body | |||||||||||||||||||||||||||
| 32 | 11 | my $subjecttxt = ''; # (String) Subject of the original message | |||||||||||||||||||||||||||
| 33 | 11 | my $messagesof = {}; # (Ref->Hash) Error message patterns | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 11 | ▶ | if( $match == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | # vtext.com | ||||||||||||||||||||||||||||
| 37 | 5 | my $markingsof = {'message' => ['Error: ']}; | |||||||||||||||||||||||||||
| 38 | 5 | $messagesof = { | |||||||||||||||||||||||||||
| 39 | # The attempted recipient address does not exist. | ||||||||||||||||||||||||||||
| 40 | $Sisimai::Eb::ReUSER => ['550 - Requested action not taken: no such user here'], | ||||||||||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||||||||||
| 42 | 5 | $boundaries = [Sisimai::RFC2045->boundary($mhead->{'content-type'}, 1)]; | |||||||||||||||||||||||||||
| 43 | 5 | ▶ | $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)
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 5 | for my $e ( split("\n", $emailparts->[0]) ) { | |||||||||||||||||||||||||||
| 46 | # Read error messages and delivery status lines from the head of the email to the previous | ||||||||||||||||||||||||||||
| 47 | # line of the beginning of the original message. | ||||||||||||||||||||||||||||
| 48 | 70 | ▶ | unless( $readcursor ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | # Beginning of the bounce message or delivery status part | ||||||||||||||||||||||||||||
| 50 | 5 | ▶ | $readcursor |= $indicators->{'deliverystatus'} if index($e, $markingsof->{'message'}->[0]) == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 5 | next; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 65 | ▶ | 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 ""
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # Message details: | ||||||||||||||||||||||||||||
| 56 | # Subject: Test message | ||||||||||||||||||||||||||||
| 57 | # Sent date: Wed Jun 12 02:21:53 GMT 2013 | ||||||||||||||||||||||||||||
| 58 | # MAIL FROM: *******@hg.example.com | ||||||||||||||||||||||||||||
| 59 | # RCPT TO: *****@vtext.com | ||||||||||||||||||||||||||||
| 60 | 55 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 55 | ▶ | if( index($e, ' RCPT TO: ') == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 63 | 5 | ▶ | if( $v->{'recipient'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | # There are multiple recipient addresses in the message body. | ||||||||||||||||||||||||||||
| 65 | 0 | push @$dscontents, __PACKAGE__->DELIVERYSTATUS; | |||||||||||||||||||||||||||
| 66 | 0 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 5 | $v->{'recipient'} = substr($e, 11,); | |||||||||||||||||||||||||||
| 69 | 5 | $recipients++; | |||||||||||||||||||||||||||
| 70 | 5 | next; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | } elsif( index($e, ' MAIL FROM: ') == 0 ) { | ||||||||||||||||||||||||||||
| 73 | # MAIL FROM: *******@hg.example.com | ||||||||||||||||||||||||||||
| 74 | 5 | ▶ | $senderaddr ||= substr($e, 13,); | ||||||||||||||||||||||||||
|
Condition33%1/3
$senderaddr ||= substr($e, 13)
MC/DC0%0/2
$senderaddr ||= substr($e, 13)
$senderaddr
substr($e, 13)
Truth table33%1/3
A ||= B
A= $senderaddrB= substr($e, 13)
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | } elsif( index($e, ' Subject: ') == 0 ) { | ||||||||||||||||||||||||||||
| 77 | # Subject: | ||||||||||||||||||||||||||||
| 78 | 5 | ▶ | $subjecttxt ||= substr($e, 11,); | ||||||||||||||||||||||||||
|
Condition33%1/3
$subjecttxt ||= substr($e, 11)
MC/DC0%0/2
$subjecttxt ||= substr($e, 11)
$subjecttxt
substr($e, 11)
Truth table33%1/3
A ||= B
A= $subjecttxtB= substr($e, 11)
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | } else { | ||||||||||||||||||||||||||||
| 81 | # 550 - Requested action not taken: no such user here | ||||||||||||||||||||||||||||
| 82 | 40 | ▶ | $v->{'diagnosis'} = $e if index($e, ' - ') > 2; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } else { | ||||||||||||||||||||||||||||
| 86 | # vzwpix.com | ||||||||||||||||||||||||||||
| 87 | 6 | my $startingof = {'message' => ['Message could not be delivered to mobile']}; | |||||||||||||||||||||||||||
| 88 | 6 | $messagesof = {$Sisimai::Eb::ReUSER => ['No valid recipients for this MM']}; | |||||||||||||||||||||||||||
| 89 | 6 | $boundaries = [Sisimai::RFC2045->boundary($mhead->{'content-type'})]; | |||||||||||||||||||||||||||
| 90 | 6 | ▶ | $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)
| |||||||||||||||||||||||||||||
| 91 | 6 | for my $e ( split("\n", $emailparts->[0]) ) { | |||||||||||||||||||||||||||
| 92 | # Read error messages and delivery status lines from the head of the email to the previous | ||||||||||||||||||||||||||||
| 93 | # line of the beginning of the original message. | ||||||||||||||||||||||||||||
| 94 | 54 | ▶ | unless( $readcursor ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | # Beginning of the bounce message or delivery status part | ||||||||||||||||||||||||||||
| 96 | 6 | ▶ | $readcursor |= $indicators->{'deliverystatus'} if index($e, $startingof->{'message'}->[0]) == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 6 | next; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 48 | ▶ | 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 ""
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | # Original Message: | ||||||||||||||||||||||||||||
| 102 | # From: kijitora <kijitora@example.jp> | ||||||||||||||||||||||||||||
| 103 | # To: 0000000000@vzwpix.com | ||||||||||||||||||||||||||||
| 104 | # Subject: test for bounce | ||||||||||||||||||||||||||||
| 105 | # Date: Wed, 20 Jun 2013 10:29:52 +0000 | ||||||||||||||||||||||||||||
| 106 | 36 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 36 | ▶ | if( index($e, 'To: ') == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 109 | 6 | ▶ | if( $v->{'recipient'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | # There are multiple recipient addresses in the message body. | ||||||||||||||||||||||||||||
| 111 | 0 | push @$dscontents, __PACKAGE__->DELIVERYSTATUS; | |||||||||||||||||||||||||||
| 112 | 0 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | 6 | $v->{'recipient'} = Sisimai::Address->s3s4(substr($e, 4,)); | |||||||||||||||||||||||||||
| 115 | 6 | $recipients++; | |||||||||||||||||||||||||||
| 116 | 6 | next; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | } elsif( index($e, 'From: ') == 0 ) { | ||||||||||||||||||||||||||||
| 119 | # From: kijitora <kijitora@example.jp> | ||||||||||||||||||||||||||||
| 120 | 6 | ▶ | $senderaddr ||= Sisimai::Address->s3s4(substr($e, 6,)); | ||||||||||||||||||||||||||
|
Condition33%1/3
$senderaddr ||= "Sisimai::Address"->s3s4(substr($e, 6))
MC/DC0%0/2
$senderaddr ||= "Sisimai::Address"->s3s4(substr($e, 6))
$senderaddr
"Sisimai::Address"->s3s4(substr($e, 6))
Truth table33%1/3
A ||= B
A= $senderaddrB= "Sisimai::Address"->s3s4(substr($e, 6))
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | } elsif( index($e, 'Subject: ') == 0 ) { | ||||||||||||||||||||||||||||
| 123 | # Subject: | ||||||||||||||||||||||||||||
| 124 | 6 | ▶ | $subjecttxt ||= substr($e, 9,); | ||||||||||||||||||||||||||
|
Condition33%1/3
$subjecttxt ||= substr($e, 9)
MC/DC0%0/2
$subjecttxt ||= substr($e, 9)
$subjecttxt
substr($e, 9)
Truth table33%1/3
A ||= B
A= $subjecttxtB= substr($e, 9)
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | } else { | ||||||||||||||||||||||||||||
| 127 | # Message could not be delivered to mobile. | ||||||||||||||||||||||||||||
| 128 | # Error: No valid recipients for this MM | ||||||||||||||||||||||||||||
| 129 | 18 | ▶ | $v->{'diagnosis'} = substr($e, 7,) if index($e, 'Error: ') == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 11 | ▶ | return undef unless $recipients; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | # Set the value of "MAIL FROM:" and "From:" | ||||||||||||||||||||||||||||
| 136 | 11 | ▶ | $emailparts->[1] .= sprintf("From: %s\n", $senderaddr) if index($emailparts->[1], "\nFrom: ") < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 137 | 11 | ▶ | $emailparts->[1] .= sprintf("Subject: %s\n", $subjecttxt) if index($emailparts->[1], "\nSubject: ") < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 11 | for my $e ( @$dscontents ) { | |||||||||||||||||||||||||||
| 140 | 11 | SESSION: for my $r ( keys %$messagesof ) { | |||||||||||||||||||||||||||
| 141 | # Verify each regular expression of session errors | ||||||||||||||||||||||||||||
| 142 | 11 | ▶ | next unless grep { index($e->{'diagnosis'}, $_) > -1 } $messagesof->{ $r }->@*; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 11 | $e->{'reason'} = $r; | |||||||||||||||||||||||||||
| 144 | 11 | last; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | 11 | return {"ds" => $dscontents, "rfc822" => $emailparts->[1]}; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 39 | 1; | |||||||||||||||||||||||||||
| 151 | __END__ | ||||||||||||||||||||||||||||