| 1 | package Sisimai::Lhost::Notes; | ||||||||||||||||||||||||||||
| 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 | 37 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | sub description { 'HCL Notes' } | ||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 9 | 889 | ▶ | sub inquire { | ||||||||||||||||||||||||||
|
Subroutine
inquire: called CC=29 SCAR=37.0
Pod
documented
| |||||||||||||||||||||||||||||
| 10 | # Detect an error from HCL Notes (Formerly IBM Notes(Formerly Lotus Notes)) | ||||||||||||||||||||||||||||
| 11 | # @param [Hash] mhead Message headers of a bounce email | ||||||||||||||||||||||||||||
| 12 | # @param [String] mbody Message body of a bounce email | ||||||||||||||||||||||||||||
| 13 | # @return [Hash] Bounce data list and message/rfc822 part | ||||||||||||||||||||||||||||
| 14 | # @return [undef] failed to decode or the arguments are missing | ||||||||||||||||||||||||||||
| 15 | # @since v4.1.1 | ||||||||||||||||||||||||||||
| 16 | 889 | my $class = shift; | |||||||||||||||||||||||||||
| 17 | 889 | ▶ | 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()
| |||||||||||||||||||||||||||||
| 18 | 888 | ▶ | 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()
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 887 | ▶ | return undef unless $mhead->{'subject'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 869 | ▶ | return undef unless index($mhead->{'subject'}, 'Undeliverable message') == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 16 | require Sisimai::Eb; | |||||||||||||||||||||||||||
| 24 | 16 | state $indicators = __PACKAGE__->INDICATORS; | |||||||||||||||||||||||||||
| 25 | 16 | state $boundaries = ['------- Returned Message --------']; | |||||||||||||||||||||||||||
| 26 | 16 | state $startingof = {'message' => ['------- Failure Reasons ']}; | |||||||||||||||||||||||||||
| 27 | 16 | state $messagesof = { | |||||||||||||||||||||||||||
| 28 | $Sisimai::Eb::ReUSER => [ | ||||||||||||||||||||||||||||
| 29 | 'User not listed in public Name & Address Book', | ||||||||||||||||||||||||||||
| 30 | 'ディレクトリのリストにありません', | ||||||||||||||||||||||||||||
| 31 | ], | ||||||||||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 16 | ▶ | 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 | 16 | my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef; | |||||||||||||||||||||||||||
| 36 | 16 | my $readcursor = 0; # (Integer) Points the current cursor position | |||||||||||||||||||||||||||
| 37 | 16 | my $recipients = 0; # (Integer) The number of 'Final-Recipient' header | |||||||||||||||||||||||||||
| 38 | 16 | my $removedmsg = 'MULTIBYTE CHARACTERS HAVE BEEN REMOVED'; | |||||||||||||||||||||||||||
| 39 | 16 | my $encodedmsg = ''; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 16 | my $characters = ''; | |||||||||||||||||||||||||||
| 42 | 16 | ▶ | if( index($mhead->{'content-type'}, 'charset=') > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | # Get character set name, Content-Type: text/plain; charset=ISO-2022-JP | ||||||||||||||||||||||||||||
| 44 | 16 | $characters = lc substr($mhead->{'content-type'}, index($mhead->{'content-type'}, 'charset=') + 8,); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 16 | for my $e ( split("\n", $emailparts->[0]) ) { | |||||||||||||||||||||||||||
| 48 | # Read error messages and delivery status lines from the head of the email to the previous | ||||||||||||||||||||||||||||
| 49 | # line of the beginning of the original message. | ||||||||||||||||||||||||||||
| 50 | 64 | ▶ | unless( $readcursor ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | # Beginning of the bounce message or message/delivery-status part | ||||||||||||||||||||||||||||
| 52 | 16 | ▶ | $readcursor |= $indicators->{'deliverystatus'} if index($e, $startingof->{'message'}->[0]) == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 16 | next; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 48 | ▶ | next if ($readcursor & $indicators->{'deliverystatus'}) == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # ------- Failure Reasons -------- | ||||||||||||||||||||||||||||
| 58 | # | ||||||||||||||||||||||||||||
| 59 | # User not listed in public Name & Address Book | ||||||||||||||||||||||||||||
| 60 | # kijitora@notes.example.jp | ||||||||||||||||||||||||||||
| 61 | # | ||||||||||||||||||||||||||||
| 62 | # ------- Returned Message -------- | ||||||||||||||||||||||||||||
| 63 | 48 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||
| 64 | 48 | ▶ | if( index($e, '@') > 1 && index($e, ' ') < 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
index($e, "\@") > 1 and index($e, " ") == -1
MC/DC50%1/2
index($e, "\@") > 1 and index($e, " ") == -1
index($e, "\@") > 1
index($e, " ") == -1
Truth table66%2/3
A and B
A= index($e, "\@") > 1B= index($e, " ") == -1
| |||||||||||||||||||||||||||||
| 65 | # kijitora@notes.example.jp | ||||||||||||||||||||||||||||
| 66 | 16 | ▶ | if( $v->{'recipient'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | # There are multiple recipient addresses in the message body. | ||||||||||||||||||||||||||||
| 68 | 0 | push @$dscontents, __PACKAGE__->DELIVERYSTATUS; | |||||||||||||||||||||||||||
| 69 | 0 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 16 | ▶ | $v->{'recipient'} ||= $e; | ||||||||||||||||||||||||||
|
Condition33%1/3
$v->{"recipient"} ||= $e
MC/DC0%0/2
$v->{"recipient"} ||= $e
$v->{"recipient"}
$e
Truth table33%1/3
A ||= B
A= $v->{"recipient"}B= $e
| |||||||||||||||||||||||||||||
| 72 | 16 | $recipients++; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||
| 75 | 32 | ▶ | next if $e eq '' || index($e, '-') == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$e eq "" or index($e, "-") == 0
MC/DC50%1/2
$e eq "" or index($e, "-") == 0
$e eq ""
index($e, "-") == 0
Truth table66%2/3
A or B
A= $e eq ""B= index($e, "-") == 0
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 16 | ▶ | if( $e =~ /[^\x20-\x7e]/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | # Error message is not ISO-8859-1 | ||||||||||||||||||||||||||||
| 79 | 11 | $encodedmsg = $e; | |||||||||||||||||||||||||||
| 80 | 11 | ▶ | if( $characters ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | # Try to convert string | ||||||||||||||||||||||||||||
| 82 | 11 | eval { Encode::from_to($encodedmsg, $characters, 'utf8'); }; | |||||||||||||||||||||||||||
| 83 | 11 | ▶ | $encodedmsg = $removedmsg if $@; # Failed to convert | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | } else { | ||||||||||||||||||||||||||||
| 86 | # No character set in Content-Type header | ||||||||||||||||||||||||||||
| 87 | 0 | $encodedmsg = $removedmsg; | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | 11 | $v->{'diagnosis'} .= $encodedmsg; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | } else { | ||||||||||||||||||||||||||||
| 92 | # Error message does not include multi-byte character | ||||||||||||||||||||||||||||
| 93 | 5 | $v->{'diagnosis'} .= $e; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 16 | ▶ | unless( $recipients ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | # Fallback: Get the recpient address from RFC822 part | ||||||||||||||||||||||||||||
| 100 | 0 | my $p1 = index($emailparts->[1], "\nTo: "); | |||||||||||||||||||||||||||
| 101 | 0 | my $p2 = index($emailparts->[1], "\n", $p1 + 6); | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | if( $p1 > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | $v->{'recipient'} = Sisimai::Address->s3s4(substr($emailparts->[1], $p1 + 5, $p2 - $p1 - 5)); | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | $recipients++ if $v->{'recipient'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 16 | ▶ | return undef unless $recipients; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 16 | for my $e ( @$dscontents ) { | |||||||||||||||||||||||||||
| 110 | 16 | $e->{'diagnosis'} = Sisimai::String->sweep($e->{'diagnosis'}); | |||||||||||||||||||||||||||
| 111 | 16 | $e->{'recipient'} = Sisimai::Address->s3s4($e->{'recipient'}); | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 16 | for my $r ( keys %$messagesof ) { | |||||||||||||||||||||||||||
| 114 | # Check each regular expression of Notes error messages | ||||||||||||||||||||||||||||
| 115 | 16 | ▶ | next unless grep { index($e->{'diagnosis'}, $_) > -1 } $messagesof->{ $r }->@*; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 10 | $e->{'reason'} = $r; | |||||||||||||||||||||||||||
| 117 | 10 | ▶ | $e->{'status'} = Sisimai::SMTP::Status->code($r) || ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
'Sisimai::SMTP::Status'->code($r) || ''
MC/DC0%0/1
'Sisimai::SMTP::Status'->code($r) || ''
'Sisimai::SMTP::Status'->code($r)
Truth table50%1/2
A
A= 'Sisimai::SMTP::Status'->code($r)
| |||||||||||||||||||||||||||||
| 118 | 10 | last; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 16 | return {"ds" => $dscontents, "rfc822" => $emailparts->[1]}; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 37 | 1; | |||||||||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||||||||||