| 1 | package Sisimai::Lhost::ApacheJames; | ||||||||||||||||||||||||||||||||||||||
| 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 { 'James: https://james.apache.org/' } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
description: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 8 | 888 | ▶ | sub inquire { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
inquire: called CC=33 SCAR=37.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 9 | # Detect an error from Apache James | ||||||||||||||||||||||||||||||||||||||
| 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.26 | ||||||||||||||||||||||||||||||||||||||
| 15 | 888 | my $class = shift; | |||||||||||||||||||||||||||||||||||||
| 16 | 888 | ▶ | 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 | 887 | ▶ | 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 | 886 | ▶ | my $match = 0; $match ||= 1 if $mhead->{'subject'} eq '[BOUNCE]'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$match ||= 1
MC/DC0%0/1
$match ||= 1
$match
Truth table0%0/2
A
A= $match
| |||||||||||||||||||||||||||||||||||||||
| 19 | 886 | ▶ | $match ||= 1 if defined $mhead->{'message-id'} && rindex($mhead->{'message-id'}, '.JavaMail.') > -1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition80%4/5
defined $mhead->{"message-id"} and rindex($mhead->{"message-id"}, ".JavaMail.") != -1
$match ||= 1
MC/DC100%2/2
defined $mhead->{"message-id"} and rindex($mhead->{"message-id"}, ".JavaMail.") != -1
defined $mhead->{"message-id"}
rindex($mhead->{"message-id"}, ".JavaMail.") != -1
MC/DC0%0/1
$match ||= 1
$match
Truth table100%3/3
A and B
A= defined $mhead->{"message-id"}B= rindex($mhead->{"message-id"}, ".JavaMail.") != -1
Truth table50%1/2
A
A= $match
| |||||||||||||||||||||||||||||||||||||||
| 20 | 886 | ▶ | $match ||= 1 if grep { rindex($_, 'JAMES SMTP Server') > -1 } $mhead->{'received'}->@*; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$match ||= 1
MC/DC0%0/1
$match ||= 1
$match
Truth table0%0/2
A
A= $match
| |||||||||||||||||||||||||||||||||||||||
| 21 | 886 | ▶ | return undef unless $match; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||
| 23 | 6 | state $indicators = __PACKAGE__->INDICATORS; | |||||||||||||||||||||||||||||||||||||
| 24 | 6 | state $boundaries = ["Content-Type: message/rfc822"]; | |||||||||||||||||||||||||||||||||||||
| 25 | 6 | state $startingof = { | |||||||||||||||||||||||||||||||||||||
| 26 | # apache-james-2.3.2/src/java/org/apache/james/transport/mailets/ | ||||||||||||||||||||||||||||||||||||||
| 27 | # AbstractNotify.java|124: out.println("Error message below:"); | ||||||||||||||||||||||||||||||||||||||
| 28 | # AbstractNotify.java|128: out.println("Message details:"); | ||||||||||||||||||||||||||||||||||||||
| 29 | "message" => ["Message details:"], | ||||||||||||||||||||||||||||||||||||||
| 30 | }; | ||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | 6 | ▶ | 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)
| |||||||||||||||||||||||||||||||||||||||
| 33 | 6 | my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = $dscontents->[-1]; | |||||||||||||||||||||||||||||||||||||
| 34 | 6 | my $readcursor = 0; # Points the current cursor position | |||||||||||||||||||||||||||||||||||||
| 35 | 6 | my $recipients = 0; # The number of 'Final-Recipient' header | |||||||||||||||||||||||||||||||||||||
| 36 | 6 | my $alternates = ["", "", "", ""]; # [Envelope-From, Header-From, Date, Subject] | |||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||
| 38 | 6 | for my $e ( split("\n", $emailparts->[0]) ) { | |||||||||||||||||||||||||||||||||||||
| 39 | # Read error messages and delivery status lines from the head of the email to the previous | ||||||||||||||||||||||||||||||||||||||
| 40 | # line of the beginning of the original message. | ||||||||||||||||||||||||||||||||||||||
| 41 | 84 | ▶ | unless( $readcursor ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 42 | # Beginning of the bounce message or message/delivery-status part | ||||||||||||||||||||||||||||||||||||||
| 43 | 36 | ▶ | if( index($e, $startingof->{"message"}->[0]) == 0 ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 44 | # Message details: | ||||||||||||||||||||||||||||||||||||||
| 45 | # Subject: Nyaaan | ||||||||||||||||||||||||||||||||||||||
| 46 | 6 | $readcursor |= $indicators->{"deliverystatus"}; next; | |||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||
| 48 | 30 | ▶ | $v->{"diagnosis"} .= $e." " if $e ne ""; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 49 | 30 | next; | |||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||
| 51 | 48 | ▶ | next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq ""; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
MC/DC0%0/2
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
($readcursor & $indicators->{"deliverystatus"}) == 0
$e eq ""
Truth table33%1/3
A or B
A= ($readcursor & $indicators->{"deliverystatus"}) == 0B= $e eq ""
| |||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||
| 53 | # Message details: | ||||||||||||||||||||||||||||||||||||||
| 54 | # Subject: Nyaaan | ||||||||||||||||||||||||||||||||||||||
| 55 | # Sent date: Thu Apr 29 01:20:50 JST 2015 | ||||||||||||||||||||||||||||||||||||||
| 56 | # MAIL FROM: shironeko@example.jp | ||||||||||||||||||||||||||||||||||||||
| 57 | # RCPT TO: kijitora@example.org | ||||||||||||||||||||||||||||||||||||||
| 58 | # From: Neko <shironeko@example.jp> | ||||||||||||||||||||||||||||||||||||||
| 59 | # To: kijitora@example.org | ||||||||||||||||||||||||||||||||||||||
| 60 | # Size (in bytes): 1024 | ||||||||||||||||||||||||||||||||||||||
| 61 | # Number of lines: 64 | ||||||||||||||||||||||||||||||||||||||
| 62 | 48 | ▶ | if( index($e, " RCPT TO: ") == 0 ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||
| 63 | # RCPT TO: kijitora@example.org | ||||||||||||||||||||||||||||||||||||||
| 64 | 6 | ▶ | if( $v->{"recipient"} ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 65 | # There are multiple recipient addresses in the message body. | ||||||||||||||||||||||||||||||||||||||
| 66 | 0 | push @$dscontents, __PACKAGE__->DELIVERYSTATUS; | |||||||||||||||||||||||||||||||||||||
| 67 | 0 | $v = $dscontents->[-1]; | |||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||
| 69 | 6 | $v->{"recipient"} = substr($e, 12,); | |||||||||||||||||||||||||||||||||||||
| 70 | 6 | $recipients++; | |||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||
| 72 | } elsif( index($e, " Sent date: ") == 0 ) { | ||||||||||||||||||||||||||||||||||||||
| 73 | # Sent date: Thu Apr 29 01:20:50 JST 2015 | ||||||||||||||||||||||||||||||||||||||
| 74 | 6 | $v->{"date"} = substr($e, 13,); | |||||||||||||||||||||||||||||||||||||
| 75 | 6 | $alternates->[2] = $v->{"date"}; | |||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||
| 77 | } elsif( index($e, " Subject: ") == 0 ) { | ||||||||||||||||||||||||||||||||||||||
| 78 | # Subject: Nyaaan | ||||||||||||||||||||||||||||||||||||||
| 79 | 6 | $alternates->[3] = substr($e, 11,); | |||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||
| 81 | } elsif( index($e, " MAIL FROM: ") == 0 ) { | ||||||||||||||||||||||||||||||||||||||
| 82 | # MAIL FROM: shironeko@example.jp | ||||||||||||||||||||||||||||||||||||||
| 83 | 6 | $alternates->[0] = substr($e, 13,); | |||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||
| 85 | } elsif( index($e, " From: ") == 0 ) { | ||||||||||||||||||||||||||||||||||||||
| 86 | # From: Neko <shironeko@example.jp> | ||||||||||||||||||||||||||||||||||||||
| 87 | 6 | $alternates->[1] = substr($e, 8,); | |||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||
| 90 | 6 | ▶ | return undef unless $recipients; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||
| 92 | 6 | ▶ | if( $emailparts->[1] eq "" ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 93 | # The original message is empty | ||||||||||||||||||||||||||||||||||||||
| 94 | 6 | ▶ | $emailparts->[1] .= sprintf("From: %s\n", $alternates->[1]) if $alternates->[1] ne ""; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 95 | 6 | ▶ | $emailparts->[1] .= sprintf("Date: %s\n", $alternates->[2]) if $alternates->[2] ne ""; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||
| 97 | 6 | ▶ | if( index($emailparts->[1], "Return-Path: ") < 0 ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 98 | # Set the envelope from address as a Return-Path: header | ||||||||||||||||||||||||||||||||||||||
| 99 | 6 | ▶ | $emailparts->[1] .= sprintf("Return-Path: <%s>\n", $alternates->[0]) if $alternates->[0] ne ""; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||
| 101 | 6 | ▶ | if( index($emailparts->[1], "\nSubject: ") < 0 ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 102 | # Set the envelope from address as a Return-Path: header | ||||||||||||||||||||||||||||||||||||||
| 103 | 6 | ▶ | $emailparts->[1] .= sprintf("Subject: %s\n", $alternates->[3]) if $alternates->[3] ne ""; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||
| 105 | 6 | return {"ds" => $dscontents, "rfc822" => $emailparts->[1]}; | |||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||
| 108 | 38 | 1; | |||||||||||||||||||||||||||||||||||||
| 109 | __END__ | ||||||||||||||||||||||||||||||||||||||