Sisimai/Lhost/Domino.pm

filter: Statementstmt 94.9% 94 / 99 Branchbran 82.0% 41 / 50 Conditioncond 57.4% 27 / 47 MC/DCmcdc 30.7% 8 / 26 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 77.7% 182 / 234 CC 48 SCAR 40.3
CC
48
Cov
83%
inquire
66.4
BEGIN
1.0
BEGIN
1.0
CRAP 56.1
« Sisimai/Address.pm ↑ Summary Sisimai/Lhost/Exchange2003.pm »
1 package Sisimai::Lhost::Domino;
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 38 ▶use Sisimai::Eb;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 38 ▶use Sisimai::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 38 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 38 ▶use Encode::Guess; Encode::Guess->add_suspects(Sisimai::String->encodenames->@*);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶sub description { 'HCL Domino' }
Subroutine description: called CC=1 SCAR=0.0
Pod documented
12 905 ▶sub inquire {
Subroutine inquire: called CC=48 SCAR=42.0
Pod documented
13 # Detect an error from HCL Domino (Formerly IBM Domino (Formerly Lotus Domino))
14 # @param [Hash] mhead Message headers of a bounce email
15 # @param [String] mbody Message body of a bounce email
16 # @return [Hash] Bounce data list and message/rfc822 part
17 # @return [undef] failed to decode or the arguments are missing
18 # @since v4.0.2
19 905 my $class = shift;
20 905 ▶ my $mhead = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
9041
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
21 904 ▶ my $mbody = shift // return undef;
Condition100%2/2
shift() // (return undef)
l!l
9031
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
22  
23 903 ▶ my $match = 0; $match ||= 1 if index($mhead->{'subject'}, 'DELIVERY FAILURE:') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($mhead->{"subject"}, "DELIVERY FAILURE:") == 0 17 886 903
Condition50%1/2
$match ||= 1
l!l
017
MC/DC0%0/1
$match ||= 1
$match
Truth table50%1/2
A
A= $match
Aresult
11
00
24 903 ▶ $match ||= 1 if index($mhead->{'subject'}, 'DELIVERY_FAILURE:') == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($mhead->{"subject"}, "DELIVERY_FAILURE:") == 0 0 903 903
Condition0%0/2
$match ||= 1
l!l
00
MC/DC0%0/1
$match ||= 1
$match
Truth table0%0/2
A
A= $match
Aresult
11
00
25 903 ▶ return undef unless $match > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $match > 0 886 17 903
26  
27 17 state $indicators = __PACKAGE__->INDICATORS;
28 17 state $boundaries = ['Content-Type: message/rfc822'];
29 17 state $startingof = {'message' => ['Your message']};
30 17 state $messagesof = {
31 $Sisimai::Eb::ReUSER => [
32 'not listed in Domino Directory',
33 'not listed in public Name & Address Book',
34 'no se encuentra en el Directorio de Domino',
35 "non répertorié dans l'annuaire Domino",
36 'Domino ディレクトリには見つかりません',
37 ],
38 };
39  
40 17 require Sisimai::RFC1123;
41 17 ▶ my $emailparts = Sisimai::RFC5322->part($mbody, $boundaries) // return undef; return undef unless $emailparts->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $emailparts->[0] 0 17 17
Condition50%1/2
"Sisimai::RFC5322"->part($mbody, $boundaries) // (return undef)
l!l
170
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
42 17 my $fieldtable = Sisimai::RFC1894->FIELDTABLE;
43 17 my $dscontents = [__PACKAGE__->DELIVERYSTATUS]; my $v = undef;
44 17 my $permessage = {}; # (Hash) Store values of each Per-Message field
45 17 my $readcursor = 0; # (Integer) Points the current cursor position
46 17 my $recipients = 0; # (Integer) The number of 'Final-Recipient' header
47 17 my $subjecttxt = ''; # (String) The value of Subject:
48 17 my $p = '';
49  
50 17 for my $e ( split("\n", $emailparts->[0]) ) {
51 # Read error messages and delivery status lines from the head of the email to the previous
52 # line of the beginning of the original message.
53 297 ▶ unless( $readcursor ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($readcursor) 17 280 297
54 # Beginning of the bounce message or message/delivery-status part
55 17 ▶ $readcursor |= $indicators->{'deliverystatus'} if index($e, $startingof->{'message'}->[0]) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($e, $startingof->{"message"}[0]) == 0 17 0 17
56 17 next;
57 }
58 280 ▶ next if ($readcursor & $indicators->{'deliverystatus'}) == 0 || $e eq "";
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq "" 112 168 280
Condition66%2/3
($readcursor & $indicators->{"deliverystatus"}) == 0 or $e eq ""
l!l&&r!l&&!r
0112168
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 ""
ABresult
1X1
011
000
59  
60 # Your message
61 #
62 # Subject: Test Bounce
63 #
64 # was not delivered to:
65 #
66 # kijitora@example.net
67 #
68 # because:
69 #
70 # User some.name (kijitora@example.net) not listed in Domino Directory
71 #
72 168 $v = $dscontents->[-1];
73 168 ▶ if( $e eq 'was not delivered to:' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($e eq 'was not delivered to:') { } 17 151 168
elsif (index($e, ' ') == 0 and index($e, '@') != -1 and index($e, ' ', 3) == -1) { } 17 134 151
elsif ($e eq 'because:') { } 17 117 134
74 # was not delivered to:
75 # kijitora@example.net
76 17 ▶ if( $v->{'recipient'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"recipient"}) 0 17 17
77 # There are multiple recipient addresses in the message body.
78 0 push @$dscontents, __PACKAGE__->DELIVERYSTATUS;
79 0 $v = $dscontents->[-1];
80 }
81 17 ▶ $v->{'recipient'} ||= $e;
Condition33%1/3
$v->{"recipient"} ||= $e
l!l&&r!l&&!r
0170
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
82 17 $recipients++;
83  
84 ▶ } elsif( index($e, ' ') == 0 && index($e, '@') > -1 && index($e, ' ', 3) < 0 ) {
Condition100%6/6
index($e, " ") == 0 and index($e, "\@") != -1 and index($e, " ", 3) == -1
!ll&&!rl&&r
1231117
index($e, " ") == 0 and index($e, "\@") != -1
!ll&&!rl&&r
1002328
MC/DC100%3/3
index($e, " ") == 0 and index($e, "\@") != -1 and index($e, " ", 3) == -1
index($e, " ") == 0 index($e, "\@") != -1 index($e, " ", 3) == -1
Truth table100%4/4
A and B and C
A= index($e, " ") == 0B= index($e, "\@") != -1C= index($e, " ", 3) == -1
ABCresult
0XX0
10X0
1100
1111
85 # Continued from the line "was not delivered to:"
86 # kijitora@example.net
87 17 $v->{'recipient'} = Sisimai::Address->s3s4(substr($e, 2,));
88  
89 } elsif( $e eq 'because:' ) {
90 # because:
91 # User some.name (kijitora@example.net) not listed in Domino Directory
92 17 $v->{'diagnosis'} = $e;
93  
94 } else {
95 117 ▶ if( exists $v->{'diagnosis'} && $v->{'diagnosis'} eq 'because:' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $v->{'diagnosis'} and $v->{'diagnosis'} eq 'because:') { } 17 100 117
elsif (index($e, ' Subject: ') == 0) { } 17 83 100
Condition66%2/3
exists $v->{"diagnosis"} and $v->{"diagnosis"} eq "because:"
!ll&&!rl&&r
010017
MC/DC50%1/2
exists $v->{"diagnosis"} and $v->{"diagnosis"} eq "because:"
exists $v->{"diagnosis"} $v->{"diagnosis"} eq "because:"
Truth table66%2/3
A and B
A= exists $v->{"diagnosis"}B= $v->{"diagnosis"} eq "because:"
ABresult
0X0
100
111
96 # Error message, continued from the line "because:"
97 17 $v->{'diagnosis'} = $e;
98  
99 } elsif( index($e, ' Subject: ') == 0 ) {
100 # Subject: Nyaa
101 17 $subjecttxt = substr($e, 11,);
102  
103 } else {
104 # There are some fields defined in RFC3464, try to match
105 83 ▶ my $f = Sisimai::RFC1894->match($e); next if $f < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $f < 1 22 61 83
106 61 ▶ my $o = Sisimai::RFC1894->field($e); next unless $o;
Branch: 1 branch
BranchTrueFalseTotal
unless $o 0 61 61
107 61 ▶ next if $o->[3] eq 'addr';
Branch: 1 branch
BranchTrueFalseTotal
if $o->[3] eq "addr" 11 50 61
108  
109 50 ▶ if( $o->[3] eq 'code' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->[3] eq 'code') { } 11 39 50
110 # Diagnostic-Code: SMTP; 550 5.1.1 <userunknown@example.jp>... User Unknown
111 11 ▶ $v->{'spec'} ||= $o->[1];
Condition33%1/3
$v->{"spec"} ||= $o->[1]
l!l&&r!l&&!r
0110
MC/DC0%0/2
$v->{"spec"} ||= $o->[1]
$v->{"spec"} $o->[1]
Truth table33%1/3
A ||= B
A= $v->{"spec"}B= $o->[1]
ABresult
1X1
011
000
112 11 ▶ $v->{'diagnosis'} ||= $o->[2];
Condition33%1/3
$v->{"diagnosis"} ||= $o->[2]
l!l&&r!l&&!r
1100
MC/DC0%0/2
$v->{"diagnosis"} ||= $o->[2]
$v->{"diagnosis"} $o->[2]
Truth table33%1/3
A ||= B
A= $v->{"diagnosis"}B= $o->[2]
ABresult
1X1
011
000
113  
114 } else {
115 # Other DSN fields defined in RFC3464
116 39 ▶ next unless exists $fieldtable->{ $o->[0] };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$fieldtable{$o->[0]} 0 39 39
117 39 ▶ next if $o->[3] eq "host" && Sisimai::RFC1123->is_internethost($o->[2]) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $o->[3] eq "host" and "Sisimai::RFC1123"->is_internethost($o->[2]) == 0 0 39 39
Condition66%2/3
$o->[3] eq "host" and "Sisimai::RFC1123"->is_internethost($o->[2]) == 0
!ll&&!rl&&r
22170
MC/DC0%0/2
$o->[3] eq "host" and "Sisimai::RFC1123"->is_internethost($o->[2]) == 0
$o->[3] eq "host" "Sisimai::RFC1123"->is_internethost($o->[2]) == 0
Truth table66%2/3
A and B
A= $o->[3] eq "host"B= "Sisimai::RFC1123"->is_internethost($o->[2]) == 0
ABresult
0X0
100
111
118 39 $v->{ $fieldtable->{ $o->[0] } } = $o->[2];
119  
120 39 ▶ next unless $f == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $f == 1 28 11 39
121 11 $permessage->{ $fieldtable->{ $o->[0] } } = $o->[2];
122 }
123 }
124 }
125 }
126 17 ▶ return undef unless $recipients;
Branch: 1 branch
BranchTrueFalseTotal
unless $recipients 0 17 17
127  
128 17 for my $e ( @$dscontents ) {
129 # Check the utf8 flag and fix
130 17 UTF8FLAG: while(1) {
131 # Delete the utf8 flag because there are a string including some characters which have
132 # utf8 flag but utf8::is_utf8 returns false
133 17 ▶ last if $e->{'diagnosis'} eq "" || Sisimai::String->is_8bit(\$e->{'diagnosis'}) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"diagnosis"} eq "" or "Sisimai::String"->is_8bit(\$e->{"diagnosis"}) == 0 12 5 17
Condition66%2/3
$e->{"diagnosis"} eq "" or "Sisimai::String"->is_8bit(\$e->{"diagnosis"}) == 0
l!l&&r!l&&!r
0125
MC/DC50%1/2
$e->{"diagnosis"} eq "" or "Sisimai::String"->is_8bit(\$e->{"diagnosis"}) == 0
$e->{"diagnosis"} eq "" "Sisimai::String"->is_8bit(\$e->{"diagnosis"}) == 0
Truth table66%2/3
A or B
A= $e->{"diagnosis"} eq ""B= "Sisimai::String"->is_8bit(\$e->{"diagnosis"}) == 0
ABresult
1X1
011
000
134  
135 5 my $cv = $e->{'diagnosis'};
136 5 my $ce = Encode::Guess->guess($cv);
137 5 ▶ last unless ref $ce;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ce 5 0 5
138  
139 0 $cv = Encode::encode_utf8($cv);
140 0 $e->{'diagnosis'} = $cv;
141 0 last;
142 }
143  
144 17 $e->{'diagnosis'} = Sisimai::String->sweep($e->{'diagnosis'});
145 17 $e->{'recipient'} = Sisimai::Address->s3s4($e->{'recipient'});
146 17 ▶ $e->{ $_ } ||= $permessage->{ $_ } || '' for keys %$permessage;
Condition20%1/5
$e->{$_} ||= $permessage->{$_} || ""
l!l&&r!l&&!r
1100
$permessage->{$_} || ''
l!l
00
MC/DC0%0/2
$e->{$_} ||= $permessage->{$_} || ""
$e->{$_} $permessage->{$_}
Truth table33%1/3
A ||= B
A= $e->{$_}B= $permessage->{$_}
ABresult
1X1
011
000
147  
148 17 for my $r ( keys %$messagesof ) {
149 # Check each regular expression of Domino error messages
150 17 ▶ next unless grep { index($e->{'diagnosis'}, $_) > -1 } $messagesof->{ $r }->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {index($e->{"diagnosis"}, $_) != -1;} @{$$messagesof{$r}} 6 11 17
151 11 $e->{'reason'} = $r;
152 11 ▶ $e->{'status'} ||= Sisimai::SMTP::Status->code($r, 0) || '';
Condition60%3/5
$e->{"status"} ||= "Sisimai::SMTP::Status"->code($r, 0) || ""
l!l&&r!l&&!r
560
'Sisimai::SMTP::Status'->code($r, 0) || ''
l!l
60
MC/DC0%0/2
$e->{"status"} ||= "Sisimai::SMTP::Status"->code($r, 0) || ""
$e->{"status"} 'Sisimai::SMTP::Status'->code($r, 0)
Truth table66%2/3
A ||= B
A= $e->{"status"}B= 'Sisimai::SMTP::Status'->code($r, 0)
ABresult
1X1
011
000
153 11 last;
154 }
155 }
156  
157 # Set the value of $subjecttxt as a Subject if there is no original message in the bounce mail.
158 17 ▶ $emailparts->[1] .= sprintf("Subject: %s\n", $subjecttxt) if index($emailparts->[1], "\nSubject:") < 0;
Branch: 1 branch
BranchTrueFalseTotal
if index($emailparts->[1], "\nSubject:") == -1 6 11 17
159  
160 17 return {"ds" => $dscontents, "rfc822" => $emailparts->[1]};
161 }
162  
163 38 1;
164 __END__
« Sisimai/Address.pm ↑ Summary Sisimai/Lhost/Exchange2003.pm »