Sisimai/Lhost/Notes.pm

filter: Statementstmt 89.4% 68 / 76 Branchbran 63.8% 23 / 36 Conditioncond 64.7% 11 / 17 MC/DCmcdc 40.0% 4 / 10 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 77.7% 115 / 148 CC 29 SCAR 35.2
CC
29
Cov
79%
inquire
40.5
BEGIN
1.0
BEGIN
1.0
CRAP 33.7
« Sisimai/Lhost/qmail.pm ↑ Summary Sisimai/Lhost/MessagingServer.pm »
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)
l!l
8881
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
18 888 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
8871
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
19  
20 887 ▶ return undef unless $mhead->{'subject'};
Branch: 1 branch
BranchTrueFalseTotal
unless $mhead->{"subject"} 18 869 887
21 869 ▶ return undef unless index($mhead->{'subject'}, 'Undeliverable message') == 0;
Branch: 1 branch
BranchTrueFalseTotal
unless index($mhead->{"subject"}, "Undeliverable message") == 0 853 16 869
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
BranchTrueFalseTotal
unless $emailparts->[0] 0 16 16
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
160
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)
Aresult
11
00
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
BranchTrueFalseTotal
if (index($mhead->{"content-type"}, "charset=") > 0) 16 0 16
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
BranchTrueFalseTotal
unless ($readcursor) 16 48 64
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
BranchTrueFalseTotal
if index($e, $startingof->{"message"}[0]) == 0 16 0 16
53 16 next;
54 }
55 48 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 0 48 48
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
BranchTrueFalseTotal
if (index($e, '@') > 1 and index($e, ' ') == -1) { } 16 32 48
Condition66%2/3
index($e, "\@") > 1 and index($e, " ") == -1
!ll&&!rl&&r
32016
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
ABresult
0X0
100
111
65 # kijitora@notes.example.jp
66 16 ▶ if( $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 0 16 16
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
l!l&&r!l&&!r
0160
MC/DC0%0/2
$v->{"recipient"} ||= $e
$v->{"recipient"} $e
Truth table33%1/3
A ||= B
A= $v->{"recipient"}B= $e
ABresult
1X1
011
000
72 16 $recipients++;
73  
74 } else {
75 32 ▶ next if $e eq '' || index($e, '-') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $e eq "" or index($e, "-") == 0 16 16 32
Condition66%2/3
$e eq "" or index($e, "-") == 0
l!l&&r!l&&!r
16016
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
ABresult
1X1
011
000
76  
77 16 ▶ if( $e =~ /[^\x20-\x7e]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e =~ /[^\x20-\x7e]/u) { } 11 5 16
78 # Error message is not ISO-8859-1
79 11 $encodedmsg = $e;
80 11 ▶ if( $characters ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($characters) { } 11 0 11
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
BranchTrueFalseTotal
if $@ 0 11 11
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
BranchTrueFalseTotal
unless ($recipients) 0 16 16
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
BranchTrueFalseTotal
if ($p1 > 0) 0 0 0
103 0 $v->{'recipient'} = Sisimai::Address->s3s4(substr($emailparts->[1], $p1 + 5, $p2 - $p1 - 5));
104 0 ▶ $recipients++ if $v->{'recipient'};
Branch: 1 branch
BranchTrueFalseTotal
if $v->{"recipient"} 0 0 0
105 }
106 }
107 16 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 0 16 16
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
BranchTrueFalseTotal
unless grep {index($e->{"diagnosis"}, $_) != -1;} @{$$messagesof{$r}} 6 10 16
116 10 $e->{'reason'} = $r;
117 10 ▶ $e->{'status'} = Sisimai::SMTP::Status->code($r) || '';
Condition50%1/2
'Sisimai::SMTP::Status'->code($r) || ''
l!l
100
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)
Aresult
11
00
118 10 last;
119 }
120 }
121 16 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
122 }
123  
124 37 1;
125 __END__
« Sisimai/Lhost/qmail.pm ↑ Summary Sisimai/Lhost/MessagingServer.pm »