Sisimai/Address.pm

filter: Statementstmt 93.4% 227 / 243 Branchbran 80.5% 153 / 190 Conditioncond 64.7% 57 / 88 MC/DCmcdc 40.4% 19 / 47 Subroutinesub 100% 15 / 15 Podpod 70.0% 7 / 10 totaltotal 80.6% 478 / 593 CC 139 SCAR 40.9
CC
139
Cov
84%
is_emailaddress
101.2
find
69.5
new
20.1
CRAP 60.0
« Sisimai/Lhost/Sendmail.pm ↑ Summary Sisimai/Lhost/Domino.pm »
1 package Sisimai::Address;
2 93 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 93 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 93 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 93 ▶use Class::Accessor::Lite (
Subroutine BEGIN: called CC=1 SCAR=0.0
6 93 'new' => 0,
7 'ro' => [
8 'address', # [String] Email address
9 'user', # [String] local part of the email address
10 'host', # [String] domain part of the email address
11 'verp', # [String] VERP
12 'alias', # [String] alias of the email address
13 ],
14 'rw' => [
15 'name', # [String] Display name
16 'comment', # [String] (Comment)
17 ]
18 93 );
19 93 ▶use Sisimai::RFC1123;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 14 ▶sub undisclosed {
Subroutine undisclosed: called CC=3 SCAR=11.0
Pod undocumented
22 # Return pseudo recipient or sender address
23 # @param [String] argv0 Address type: true = recipient, false = sender
24 # @return [String] Pseudo recipient address or sender address or an empty value when
25 # the $argv0 is neither 'r' nor 's'
26 14 my $class = shift;
27 14 ▶ my $argv0 = shift // 0;
Condition100%2/2
shift() // 0
l!l
131
MC/DC100%1/1
shift() // 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
28 14 ▶ my $local = $argv0 ? 'recipient' : 'sender';
Branch: 1 branch
BranchTrueFalseTotal
$argv0 ? : 12 2 14
29 14 return sprintf("undisclosed-%s-in-headers%slibsisimai.org.invalid", $local, '@');
30 }
31  
32 10782 ▶sub is_emailaddress {
Subroutine is_emailaddress: called CC=46 SCAR=46.2
Pod documented
33 # Check that the argument is an email address or not
34 # @param [String] email Email address string
35 # @return [Integer] 0: Not email address
36 # 1: Email address
37 10782 my $class = shift;
38 10782 ▶ my $email = shift // return 0; return 0 if length($email) < 5;
Branch: 1 branch
BranchTrueFalseTotal
if length $email < 5 3 10656 10659
Condition100%2/2
shift() // (return 0)
l!l
10659123
MC/DC100%1/1
shift() // (return 0)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
39 10656 $email =~ s/\A[\s\t]+//; $email =~ s/[\s\t]+\z//;
40  
41 10656 my $width = length($email);
42 10656 my $lasta = rindex($email, '@');
43  
44 10656 ▶ return 0 if $width > 254; # The maximum length of an email address is 254
Branch: 1 branch
BranchTrueFalseTotal
if $width > 254 1 10655 10656
45 10655 ▶ return 0 if $lasta < 1 || $lasta > 64; # The maximum length of a local part is 64
Branch: 1 branch
BranchTrueFalseTotal
if $lasta < 1 or $lasta > 64 18 10637 10655
Condition66%2/3
$lasta < 1 or $lasta > 64
l!l&&r!l&&!r
18010637
MC/DC50%1/2
$lasta < 1 or $lasta > 64
$lasta < 1 $lasta > 64
Truth table66%2/3
A or B
A= $lasta < 1B= $lasta > 64
ABresult
1X1
011
000
46 10637 ▶ return 0 if $width - $lasta > 253; # The maximum length of a domain part is 252
Branch: 1 branch
BranchTrueFalseTotal
if $width - $lasta > 253 0 10637 10637
47  
48 10637 ▶ my $quote = __PACKAGE__->is_quotedaddress($email); unless( $quote ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($quote) 10619 18 10637
49 # The email address is not a quoted address
50 10619 ▶ return 0 if index($email, '@') != $lasta; # There are 2 or more '@'.
Branch: 1 branch
BranchTrueFalseTotal
if index($email, "\@") != $lasta 20 10599 10619
51 10599 ▶ return 0 if index($email, ' ') > 0; # There is 1 or more ' '.
Branch: 1 branch
BranchTrueFalseTotal
if index($email, " ") > 0 0 10599 10599
52 }
53 10617 my $ipv46 = Sisimai::RFC1123->is_domainliteral($email);
54  
55 10617 my $j = -1; for my $e ( split('', $email) ) {
56 # 31 < The ASCII code of each character < 127
57 255675 my $p = ord($e); $j++;
58  
59 255675 ▶ if( $j < $lasta ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $lasta) { } 106954 148721 255675
60 # A local part of the email address: string before the last "@"
61 106954 ▶ return 0 if $p < 32 || $p > 126; # Before ' ', After '~'
Branch: 1 branch
BranchTrueFalseTotal
if $p < 32 or $p > 126 0 106954 106954
Condition33%1/3
$p < 32 or $p > 126
l!l&&r!l&&!r
00106954
MC/DC0%0/2
$p < 32 or $p > 126
$p < 32 $p > 126
Truth table33%1/3
A or B
A= $p < 32B= $p > 126
ABresult
1X1
011
000
62 106954 ▶ next if $j == 0; # The character is the first character
Branch: 1 branch
BranchTrueFalseTotal
if $j == 0 10617 96337 106954
63  
64 96337 ▶ if( $quote ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote) { } 264 96073 96337
65 # The email address has quoted local part like "neko@cat"@example.org
66 264 my $jp = substr($email, $j - 1, 1);
67 264 ▶ if( ord($jp) == 92 ) { # 92 = '\'
Branch: 1 branch
BranchTrueFalseTotal
if (ord $jp == 92) { } 0 264 264
68 # When the previous character IS '\', only the followings are allowed: '\', '"'
69 0 ▶ return 0 if $p != 92 && $p != 34;
Branch: 1 branch
BranchTrueFalseTotal
if $p != 92 and $p != 34 0 0 0
Condition0%0/3
$p != 92 and $p != 34
!ll&&!rl&&r
000
MC/DC0%0/2
$p != 92 and $p != 34
$p != 92 $p != 34
Truth table0%0/3
A and B
A= $p != 92B= $p != 34
ABresult
0X0
100
111
70  
71 } else {
72 # When the previous character IS NOT '\'
73 264 ▶ return 0 if $p == 34 && $j + 1 < $lasta;
Branch: 1 branch
BranchTrueFalseTotal
if $p == 34 and $j + 1 < $lasta 0 264 264
Condition66%2/3
$p == 34 and $j + 1 < $lasta
!ll&&!rl&&r
246180
MC/DC0%0/2
$p == 34 and $j + 1 < $lasta
$p == 34 $j + 1 < $lasta
Truth table66%2/3
A and B
A= $p == 34B= $j + 1 < $lasta
ABresult
0X0
100
111
74 }
75 } else {
76 # The local part is not quoted
77 # ".." is not allowed in a local part when the local part is not quoted by "" but
78 # Non-RFC compliant email addresses still persist in the world.
79 #
80 # The following characters are not allowed in a local part without "..."@example.jp
81 96073 ▶ return 0 if $e eq ',' || $e eq '@' || $e eq ':' || $e eq ';' || $e eq '(';
Branch: 1 branch
BranchTrueFalseTotal
if $e eq "," or $e eq "\@" or $e eq ":" or $e eq ";" or $e eq "(" 0 96073 96073
Condition33%4/12
$e eq "," or $e eq "\@" or $e eq ":" or $e eq ";" or $e eq "("
l!l&&r!l&&!r
0096073
$e eq "," or $e eq "\@" or $e eq ":" or $e eq ";"
l!l&&r!l&&!r
0096073
$e eq "," or $e eq "\@" or $e eq ":"
l!l&&r!l&&!r
0096073
$e eq "," or $e eq "\@"
l!l&&r!l&&!r
0096073
MC/DC0%0/5
$e eq "," or $e eq "\@" or $e eq ":" or $e eq ";" or $e eq "("
$e eq "," $e eq "\@" $e eq ":" $e eq ";" $e eq "("
Truth table16%1/6
A or B or C or D or E
A= $e eq ","B= $e eq "\@"C= $e eq ":"D= $e eq ";"E= $e eq "("
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
82 96073 ▶ return 0 if $e eq ')' || $e eq '<' || $e eq '>' || $e eq '[' || $e eq ']';
Branch: 1 branch
BranchTrueFalseTotal
if $e eq ")" or $e eq "<" or $e eq ">" or $e eq "[" or $e eq "]" 0 96073 96073
Condition33%4/12
$e eq ")" or $e eq "<" or $e eq ">" or $e eq "[" or $e eq "]"
l!l&&r!l&&!r
0096073
$e eq ")" or $e eq "<" or $e eq ">" or $e eq "["
l!l&&r!l&&!r
0096073
$e eq ")" or $e eq "<" or $e eq ">"
l!l&&r!l&&!r
0096073
$e eq ")" or $e eq "<"
l!l&&r!l&&!r
0096073
MC/DC0%0/5
$e eq ")" or $e eq "<" or $e eq ">" or $e eq "[" or $e eq "]"
$e eq ")" $e eq "<" $e eq ">" $e eq "[" $e eq "]"
Truth table16%1/6
A or B or C or D or E
A= $e eq ")"B= $e eq "<"C= $e eq ">"D= $e eq "["E= $e eq "]"
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
83 }
84 } else {
85 # A domain part of the email address: string after the last "@"
86 148721 ▶ next if $p == 64; # '@'
Branch: 1 branch
BranchTrueFalseTotal
if $p == 64 10617 138104 148721
87 138104 ▶ return 0 if $p < 45; # Before '-'
Branch: 1 branch
BranchTrueFalseTotal
if $p < 45 0 138104 138104
88 138104 ▶ return 0 if $p == 47; # Equals '/'
Branch: 1 branch
BranchTrueFalseTotal
if $p == 47 0 138104 138104
89 138104 ▶ return 0 if $p == 92; # Equals '\'
Branch: 1 branch
BranchTrueFalseTotal
if $p == 92 0 138104 138104
90 138104 ▶ return 0 if $p > 122; # After 'z'
Branch: 1 branch
BranchTrueFalseTotal
if $p > 122 0 138104 138104
91  
92 138104 ▶ if( $ipv46 == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ipv46 == 0) { } 138034 70 138104
93 # Such as "example.jp", "neko.example.org"
94 138034 ▶ return 0 if $p > 57 && $p < 64; # ':' to '?'
Branch: 1 branch
BranchTrueFalseTotal
if $p > 57 and $p < 64 15 138019 138034
Condition100%3/3
$p > 57 and $p < 64
!ll&&!rl&&r
1704612097315
MC/DC100%2/2
$p > 57 and $p < 64
$p > 57 $p < 64
Truth table100%3/3
A and B
A= $p > 57B= $p < 64
ABresult
0X0
100
111
95 138019 ▶ return 0 if $p > 90 && $p < 97; # '[' to '`'
Branch: 1 branch
BranchTrueFalseTotal
if $p > 90 and $p < 97 0 138019 138019
Condition66%2/3
$p > 90 and $p < 97
!ll&&!rl&&r
173181207010
MC/DC0%0/2
$p > 90 and $p < 97
$p > 90 $p < 97
Truth table66%2/3
A and B
A= $p > 90B= $p < 97
ABresult
0X0
100
111
96  
97 } else {
98 # Such as "[IPv4:192.0.2.25]"
99 70 ▶ return 0 if $p > 59 && $p < 64; # ';' to '?'
Branch: 1 branch
BranchTrueFalseTotal
if $p > 59 and $p < 64 0 70 70
Condition66%2/3
$p > 59 and $p < 64
!ll&&!rl&&r
46240
MC/DC0%0/2
$p > 59 and $p < 64
$p > 59 $p < 64
Truth table66%2/3
A and B
A= $p > 59B= $p < 64
ABresult
0X0
100
111
100 70 ▶ return 0 if $p > 93 && $p < 97; # '^' to '`'
Branch: 1 branch
BranchTrueFalseTotal
if $p > 93 and $p < 97 0 70 70
Condition66%2/3
$p > 93 and $p < 97
!ll&&!rl&&r
6640
MC/DC0%0/2
$p > 93 and $p < 97
$p > 93 $p < 97
Truth table66%2/3
A and B
A= $p > 93B= $p < 97
ABresult
0X0
100
111
101 }
102 }
103 }
104 10602 ▶ return 1 if $ipv46;
Branch: 1 branch
BranchTrueFalseTotal
if $ipv46 4 10598 10602
105 10598 return Sisimai::RFC1123->is_internethost(substr($email, $lasta + 1,));
106 }
107  
108 10637 ▶sub is_quotedaddress {
Subroutine is_quotedaddress: called CC=3 SCAR=11.0
Pod documented
109 # Checks that the local part of the argument is quoted address or not.
110 # @param [String] argv0 Email address
111 # @return [Integer] 0: is not a quoted address
112 # 1: is a quoted address
113 10637 my $class = shift;
114 10637 my $argv0 = shift;
115 10637 ▶ return 1 if index($argv0, '"') == 0 && index($argv0, '"@') > 1;
Branch: 1 branch
BranchTrueFalseTotal
if index($argv0, "\"") == 0 and index($argv0, "\"\@") > 1 18 10619 10637
Condition66%2/3
index($argv0, "\"") == 0 and index($argv0, "\"\@") > 1
!ll&&!rl&&r
10619018
MC/DC50%1/2
index($argv0, "\"") == 0 and index($argv0, "\"\@") > 1
index($argv0, "\"") == 0 index($argv0, "\"\@") > 1
Truth table66%2/3
A and B
A= index($argv0, "\"") == 0B= index($argv0, "\"\@") > 1
ABresult
0X0
100
111
116 10619 return 0;
117 }
118  
119 1603 ▶sub is_mailerdaemon {
Subroutine is_mailerdaemon: called CC=5 SCAR=16.1
Pod documented
120 # Check that the argument is mailer-daemon or not
121 # @param [String] argv0 Email address
122 # @return [Integer] 0: Not mailer-daemon
123 # 1: Mailer-daemon
124 1603 my $class = shift;
125 1603 ▶ my $argv0 = shift // return 0;
Condition100%2/2
shift() // (return 0)
l!l
16021
MC/DC100%1/1
shift() // (return 0)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
126 1602 my $email = lc $argv0;
127  
128 1602 state $postmaster = [
129 'mailer-daemon@', '<mailer-daemon>', '(mailer-daemon)', ' mailer-daemon ',
130 'postmaster@', '<postmaster>', '(postmaster)'
131 ];
132 1602 ▶ return 1 if grep { index($email, $_) > -1 } @$postmaster;
Branch: 1 branch
BranchTrueFalseTotal
if grep {index($email, $_) != -1;} @$postmaster 79 1523 1602
133 1523 ▶ return 1 if $email eq 'mailer-daemon' || $email eq 'postmaster';
Branch: 1 branch
BranchTrueFalseTotal
if $email eq "mailer-daemon" or $email eq "postmaster" 37 1486 1523
Condition100%3/3
$email eq "mailer-daemon" or $email eq "postmaster"
l!l&&r!l&&!r
25121486
MC/DC100%2/2
$email eq "mailer-daemon" or $email eq "postmaster"
$email eq "mailer-daemon" $email eq "postmaster"
Truth table100%3/3
A or B
A= $email eq "mailer-daemon"B= $email eq "postmaster"
ABresult
1X1
011
000
134 1486 return 0;
135 }
136  
137 7438 ▶sub new {
Subroutine new: called CC=20 SCAR=30.0
Pod undocumented
138 # Constructor of Sisimai::Address
139 # @param [Hash] argvs Email address, name, and other elements
140 # @return [Sisimai::Address] Object or undef when the email address was not valid
141 # @since v4.22.1
142 7438 my $class = shift;
143 7438 ▶ my $argvs = shift // return undef; return undef if ref $argvs ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $argvs ne "HASH" 80 7358 7438
Condition50%1/2
shift() // (return undef)
l!l
74380
MC/DC0%0/1
shift() // (return undef)
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
144 7358 my $thing = {
145 'address' => '', # Entire email address
146 'user' => '', # Local part
147 'host' => '', # Domain part
148 'verp' => '', # VERP
149 'alias' => '', # Alias
150 'comment' => '', # Comment
151 'name' => '', # Display name
152 };
153  
154 7358 ▶ return undef unless exists $argvs->{'address'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $argvs->{"address"} 0 7358 7358
155 7358 ▶ return undef unless $argvs->{'address'};
Branch: 1 branch
BranchTrueFalseTotal
unless $argvs->{"address"} 42 7316 7358
156  
157 7316 my $heads = ['<'];
158 7316 my $tails = ['>', ',', '.', ';'];
159 7316 my $point = rindex($argvs->{'address'}, '@');
160  
161 7316 ▶ if( $point > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($point > 0) { } 7294 22 7316
162 # Get the local part and the domain part from the email address
163 7294 my $lpart = substr($argvs->{'address'}, 0, $point);
164 7294 my $dpart = substr($argvs->{'address'}, $point+1,);
165 7294 ▶ my $email = __PACKAGE__->expand_verp($argvs->{'address'}) || '';
Condition100%2/2
__PACKAGE__->expand_verp($argvs->{'address'}) || ''
l!l
17293
MC/DC100%1/1
__PACKAGE__->expand_verp($argvs->{'address'}) || ''
__PACKAGE__->expand_verp($argvs->{'address'})
Truth table100%2/2
A
A= __PACKAGE__->expand_verp($argvs->{'address'})
Aresult
11
00
166 7294 my $alias = 0;
167  
168 7294 ▶ unless( $email ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($email) 7293 1 7294
169 # Is not VERP address, try to expand the address as an alias
170 7293 ▶ $email = __PACKAGE__->expand_alias($argvs->{'address'}) || '';
Condition100%2/2
__PACKAGE__->expand_alias($argvs->{'address'}) || ''
l!l
117282
MC/DC100%1/1
__PACKAGE__->expand_alias($argvs->{'address'}) || ''
__PACKAGE__->expand_alias($argvs->{'address'})
Truth table100%2/2
A
A= __PACKAGE__->expand_alias($argvs->{'address'})
Aresult
11
00
171 7293 ▶ $alias = 1 if $email;
Branch: 1 branch
BranchTrueFalseTotal
if $email 11 7282 7293
172 }
173  
174 7294 ▶ if( index($email, '@') > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($email, "\@") > 0) 12 7282 7294
175 # The address is a VERP or an alias
176 12 ▶ if( $alias ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($alias) { } 11 1 12
177 # The address is an alias: neko+nyaan@example.jp
178 11 $thing->{'alias'} = $argvs->{'address'};
179  
180 } else {
181 # The address is a VERP: b+neko=example.jp@example.org
182 1 $thing->{'verp'} = $argvs->{'address'};
183 }
184 }
185  
186 0 ▶ do { while( substr($lpart, 0, 1) eq $_ ) { substr($lpart, 0, 1, '') }} for @$heads;
Branch: 1 branch
BranchTrueFalseTotal
if (substr($lpart, 0, 1) eq $_) 0 7294 7294
187 7294 ▶ do { while( substr($dpart, -1, 1) eq $_ ) { substr($dpart, -1, 1, '') }} for @$tails;
Branch: 1 branch
BranchTrueFalseTotal
if (substr($dpart, -1, 1) eq $_) 15 29176 29191
188 7294 $thing->{'user'} = $lpart;
189 7294 $thing->{'host'} = $dpart;
190 7294 $thing->{'address'} = $lpart.'@'.$dpart;
191  
192 } else {
193 # The argument does not include "@"
194 22 ▶ return undef unless __PACKAGE__->is_mailerdaemon($argvs->{'address'});
Branch: 1 branch
BranchTrueFalseTotal
unless __PACKAGE__->is_mailerdaemon($argvs->{"address"}) 4 18 22
195 18 ▶ return undef if rindex($argvs->{'address'}, ' ') > -1;
Branch: 1 branch
BranchTrueFalseTotal
if rindex($argvs->{"address"}, " ") != -1 0 18 18
196  
197 # The argument does not include " "
198 18 $thing->{'user'} = $argvs->{'address'};
199 18 $thing->{'address'} = $argvs->{'address'};
200 }
201  
202 7312 ▶ $thing->{'name'} = $argvs->{'name'} || '';
Condition100%2/2
$argvs->{'name'} || ''
l!l
31854127
MC/DC100%1/1
$argvs->{'name'} || ''
$argvs->{'name'}
Truth table100%2/2
A
A= $argvs->{'name'}
Aresult
11
00
203 7312 ▶ $thing->{'comment'} = $argvs->{'comment'} || '';
Condition100%2/2
$argvs->{'comment'} || ''
l!l
557257
MC/DC100%1/1
$argvs->{'comment'} || ''
$argvs->{'comment'}
Truth table100%2/2
A
A= $argvs->{'comment'}
Aresult
11
00
204 7312 return bless($thing, __PACKAGE__);
205 }
206  
207 9693 ▶sub find {
Subroutine find: called CC=58 SCAR=42.4
Pod documented
208 # Email address parser with a name and a comment
209 # @param [String] argv1 String including email address
210 # @param [Boolean] addrs 0 = Returns list including all the elements
211 # 1 = Returns list including email addresses only
212 # @return [Array] Email address list or undef when there is no email address in the argument
213 # @since v4.22.0
214 9693 my $class = shift;
215 9693 ▶ my $argv1 = shift // return undef; y/\r//d, y/\n//d for $argv1; # Remove CR, NL
Condition100%2/2
shift() // (return undef)
l!l
96921
MC/DC100%1/1
shift() // (return undef)
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
216 9692 ▶ my $addrs = shift // undef;
Condition100%2/2
shift() // undef
l!l
59733719
MC/DC100%1/1
shift() // undef
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
217  
218 9692 require Sisimai::String;
219 9692 state $indicators = {
220 'email-address' => (1 << 0), # <neko@example.org>
221 'quoted-string' => (1 << 1), # "Neko, Nyaan"
222 'comment-block' => (1 << 2), # (neko)
223 };
224 9692 state $delimiters = {'<' => 1, '>' => 1, '(' => 1, ')' => 1, '"' => 1, ',' => 1};
225 9692 state $validemail = qr{(?>
226 (?:([^\s]+|["].+?["])) # local part
227 [@]
228 (?:([^@\s]+|[0-9A-Za-z:\.]+)) # domain part
229 )
230 }x;
231  
232 9692 my $emailtable = {'address' => '', 'name' => '', 'comment' => ''};
233 9692 my $addrtables = [];
234 9692 my @readbuffer;
235 9692 my $readcursor = 0;
236 9692 my $v = $emailtable; # temporary buffer
237 9692 my $p = ''; # current position
238  
239 9692 for my $e ( split('', $argv1) ) {
240 # Check each characters
241 269314 ▶ if( $delimiters->{ $e } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delimiters->{$e}) { } 14767 254547 269314
242 # The character is a delimiter character
243 14767 ▶ if( $e eq ',' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e eq ",") 642 14125 14767
244 # Separator of email addresses or not
245 642 ▶ if( index($v->{'address'}, '<') == 0 &&
Branch: 1 branch
BranchTrueFalseTotal
if (index($v->{'address'}, '<') == 0 and rindex($v->{'address'}, '@') != -1 and substr($v->{'address'}, -1, 1) eq '>') { } 2 640 642
Condition66%4/6
index($v->{"address"}, "<") == 0 and rindex($v->{"address"}, "\@") != -1 and substr($v->{"address"}, -1, 1) eq ">"
!ll&&!rl&&r
64002
index($v->{"address"}, "<") == 0 and rindex($v->{"address"}, "\@") != -1
!ll&&!rl&&r
64002
MC/DC33%1/3
index($v->{"address"}, "<") == 0 and rindex($v->{"address"}, "\@") != -1 and substr($v->{"address"}, -1, 1) eq ">"
index($v->{"address"}, "<") == 0 rindex($v->{"address"}, "\@") != -1 substr($v->{"address"}, -1, 1) eq ">"
Truth table50%2/4
A and B and C
A= index($v->{"address"}, "<") == 0B= rindex($v->{"address"}, "\@") != -1C= substr($v->{"address"}, -1, 1) eq ">"
ABCresult
0XX0
10X0
1100
1111
246 rindex($v->{'address'}, '@') > -1 &&
247 substr($v->{'address'}, -1, 1) eq '>' ) {
248 # An email address has already been picked
249 2 ▶ if( $readcursor & $indicators->{'comment-block'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($readcursor & $indicators->{'comment-block'}) { } 0 2 2
elsif ($readcursor & $indicators->{'quoted-string'}) { } 0 2 2
250 # The cursor is in the comment block (Neko, Nyaan)
251 0 $v->{'comment'} .= $e;
252  
253 } elsif( $readcursor & $indicators->{'quoted-string'} ) {
254 # "Neko, Nyaan"
255 0 $v->{'name'} .= $e;
256  
257 } else {
258 # The cursor is not in neither the quoted-string nor the comment block
259 2 $readcursor = 0; # reset cursor position
260 2 push @readbuffer, $v;
261 2 $v = {'address' => '', 'name' => '', 'comment' => ''};
262 2 $p = '';
263 }
264 } else {
265 # "Neko, Nyaan" <neko@nyaan.example.org> OR <"neko,nyaan"@example.org>
266 640 ▶ $p ? ($v->{ $p } .= $e) : ($v->{'name'} .= $e);
Branch: 1 branch
BranchTrueFalseTotal
$p ? : 1 639 640
267 }
268 642 next;
269 } # End of if(',')
270  
271 14125 ▶ if( $e eq '<' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e eq "<") 6282 7843 14125
272 # <: The beginning of an email address or not
273 6282 ▶ if( $v->{'address'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{'address'}) { } 5 6277 6282
274 5 ▶ $p ? ($v->{ $p } .= $e) : ($v->{'name'} .= $e);
Branch: 1 branch
BranchTrueFalseTotal
$p ? : 0 5 5
275  
276 } else {
277 # <neko@nyaan.example.org>
278 6277 $readcursor |= $indicators->{'email-address'};
279 6277 $v->{'address'} .= $e;
280 6277 $p = 'address';
281 }
282 6282 next;
283 } # End of if('<')
284  
285 7843 ▶ if( $e eq '>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e eq ">") 5627 2216 7843
286 # >: The end of an email address or not
287 5627 ▶ if( $readcursor & $indicators->{'email-address'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($readcursor & $indicators->{'email-address'}) { } 5601 26 5627
288 # <neko@example.org>
289 5601 $readcursor &= ~$indicators->{'email-address'};
290 5601 $v->{'address'} .= $e;
291 5601 $p = '';
292  
293 } else {
294 # a comment block or a display name
295 26 ▶ $p ? ($v->{'comment'} .= $e) : ($v->{'name'} .= $e);
Branch: 1 branch
BranchTrueFalseTotal
$p ? : 0 26 26
296 }
297 5627 next;
298 } # End of if('>')
299  
300 2216 ▶ if( $e eq '(' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e eq "(") 125 2091 2216
301 # The beginning of a comment block or not
302 125 ▶ if( $readcursor & $indicators->{'email-address'} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($readcursor & $indicators->{'email-address'}) { } 2 123 125
elsif ($readcursor & $indicators->{'comment-block'}) { } 0 123 123
elsif ($readcursor & $indicators->{'quoted-string'}) { } 0 123 123
303 # <"neko(nyaan)"@example.org> or <neko(nyaan)@example.org>
304 2 ▶ if( rindex($v->{'address'}, '"') > -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (rindex($v->{'address'}, '"') != -1) { } 0 2 2
305 # Quoted local part: <"neko(nyaan)"@example.org>
306 0 $v->{'address'} .= $e;
307  
308 } else {
309 # Comment: <neko(nyaan)@example.org>
310 2 $readcursor |= $indicators->{'comment-block'};
311 2 ▶ $v->{'comment'} .= ' ' if substr($v->{'comment'}, -1, 1) eq ')';
Branch: 1 branch
BranchTrueFalseTotal
if substr($v->{"comment"}, -1, 1) eq ")" 0 2 2
312 2 $v->{'comment'} .= $e;
313 2 $p = 'comment';
314 }
315 } elsif( $readcursor & $indicators->{'comment-block'} ) {
316 # Comment at the outside of an email address (...(...)
317 0 ▶ $v->{'comment'} .= ' ' if substr($v->{'comment'}, -1, 1) eq ')';
Branch: 1 branch
BranchTrueFalseTotal
if substr($v->{"comment"}, -1, 1) eq ")" 0 0 0
318 0 $v->{'comment'} .= $e;
319  
320 } elsif( $readcursor & $indicators->{'quoted-string'} ) {
321 # "Neko, Nyaan(cat)", Deal as a display name
322 0 $v->{'name'} .= $e;
323  
324 } else {
325 # The beginning of a comment block
326 123 $readcursor |= $indicators->{'comment-block'};
327 123 ▶ $v->{'comment'} .= ' ' if substr($v->{'comment'}, -1, 1) eq ')';
Branch: 1 branch
BranchTrueFalseTotal
if substr($v->{"comment"}, -1, 1) eq ")" 29 94 123
328 123 $v->{'comment'} .= $e;
329 123 $p = 'comment';
330 }
331 125 next;
332 } # End of if('(')
333  
334 2091 ▶ if( $e eq ')' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e eq ")") 131 1960 2091
335 # The end of a comment block or not
336 131 ▶ if( $readcursor & $indicators->{'email-address'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($readcursor & $indicators->{'email-address'}) { } 2 129 131
elsif ($readcursor & $indicators->{'comment-block'}) { } 123 6 129
337 # <"neko(nyaan)"@example.org> OR <neko(nyaan)@example.org>
338 2 ▶ if( rindex($v->{'address'}, '"') > -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (rindex($v->{'address'}, '"') != -1) { } 0 2 2
339 # Quoted string in the local part: <"neko(nyaan)"@example.org>
340 0 $v->{'address'} .= $e;
341  
342 } else {
343 # Comment: <neko(nyaan)@example.org>
344 2 $readcursor &= ~$indicators->{'comment-block'};
345 2 $v->{'comment'} .= $e;
346 2 $p = 'address';
347 }
348 } elsif( $readcursor & $indicators->{'comment-block'} ) {
349 # Comment at the outside of an email address (...(...)
350 123 $readcursor &= ~$indicators->{'comment-block'};
351 123 $v->{'comment'} .= $e;
352 123 $p = '';
353  
354 } else {
355 # Deal as a display name
356 6 $readcursor &= ~$indicators->{'comment-block'};
357 6 $v->{'name'} .= $e;
358 6 $p = '';
359 }
360 131 next;
361 } # End of if(')')
362  
363 1960 ▶ if( $e eq '"' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e eq "\"") 1960 0 1960
364 # The beginning or the end of a quoted-string
365 1960 ▶ if( $p ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p) { } 10 1950 1960
366 # email-address or comment-block
367 10 $v->{ $p } .= $e;
368  
369 } else {
370 # Display name like "Neko, Nyaan"
371 1950 $v->{'name'} .= $e;
372 1950 ▶ next unless $readcursor & $indicators->{'quoted-string'};
Branch: 1 branch
BranchTrueFalseTotal
unless $readcursor & $indicators->{"quoted-string"} 1950 0 1950
373 0 ▶ next if substr($v->{'name'}, -2, 2) eq qq|\x5c"|; # "Neko, Nyaan \"...
Branch: 1 branch
BranchTrueFalseTotal
if substr($v->{"name"}, -2, 2) eq "\\\"" 0 0 0
374 0 $readcursor &= ~$indicators->{'quoted-string'};
375 0 $p = '';
376 }
377 10 next;
378 } # End of if('"')
379 } else {
380 # The character is not a delimiter
381 254547 ▶ $p ? ($v->{ $p } .= $e) : ($v->{'name'} .= $e);
Branch: 1 branch
BranchTrueFalseTotal
$p ? : 145966 108581 254547
382 254547 next;
383 }
384 }
385  
386 9692 ▶ if( $v->{'address'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{'address'}) { } 6275 3417 9692
387 # Push the latest values
388 6275 push @readbuffer, $v;
389  
390 } else {
391 # No email address like <neko@example.org> in the argument
392 3417 ▶ if( $v->{'name'} =~ $validemail ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($v->{'name'} =~ /$validemail/u) { } 3242 175 3417
elsif (__PACKAGE__->is_mailerdaemon($v->{'name'})) { } 4 171 175
393 # String like an email address will be set to the value of "address"
394 3242 $v->{'address'} = $1.'@'.$2;
395  
396 } elsif( __PACKAGE__->is_mailerdaemon($v->{'name'}) ) {
397 # Allow if the argument is MAILER-DAEMON
398 4 $v->{'address'} = $v->{'name'};
399 }
400  
401 3417 ▶ if( $v->{'address'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->{"address"}) 3246 171 3417
402 # Remove the comment from the address
403 3246 ▶ if( Sisimai::String->aligned(\$v->{'address'}, ['(', ')']) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Sisimai::String"->aligned(\$v->{"address"}, ["(", ")"])) 0 3246 3246
404 # (nyaan)nekochan@example.org, nekochan(nyaan)cat@example.org or
405 # nekochan(nyaan)@example.org
406 0 my $p1 = index($v->{'address'}, '(');
407 0 my $p2 = index($v->{'address'}, ')');
408 0 $v->{'address'} = substr($v->{'address'}, 0, $p1).substr($v->{'address'}, $p2 + 1,);
409 0 $v->{'comment'} = substr($v->{'address'}, $p1, $p2 - $p1 - 1);
410 }
411 3246 push @readbuffer, $v;
412 }
413 }
414  
415 9692 for my $e ( @readbuffer ) {
416 # The element must not include any character except from 0x20 to 0x7e.
417 9523 ▶ next if $e->{'address'} =~ /[^\x20-\x7e]/;
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"address"} =~ /[^\x20-\x7e]/u 0 9523 9523
418 9523 ▶ if( index($e->{'address'}, '@') == -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($e->{"address"}, "\@") == -1) 29 9494 9523
419 # Allow if the argument is MAILER-DAEMON
420 29 ▶ next unless __PACKAGE__->is_mailerdaemon($e->{'address'});
Branch: 1 branch
BranchTrueFalseTotal
unless __PACKAGE__->is_mailerdaemon($e->{"address"}) 5 24 29
421 }
422  
423 # Remove angle brackets, other brackets, and quotations: []<>{}'` except a domain part is
424 # an IP address like neko@[192.0.2.222]
425 9518 s/\A[\[<{('`]//g, s/[.,'`>});]\z//g for $e->{'address'};
426 9518 ▶ $e->{'address'} =~ s/[^A-Za-z]\z//g unless index($e->{'address'}, '@[') > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless index($e->{"address"}, "\@[") > 1 9510 8 9518
427  
428 9518 ▶ if( index($e->{'address'}, '"@') < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($e->{"address"}, "\"\@") == -1) 9497 21 9518
429 # Remove double-quotations
430 9497 ▶ substr($e->{'address'}, 0, 1, '') if substr($e->{'address'}, 0, 1) eq '"';
Branch: 1 branch
BranchTrueFalseTotal
if substr($e->{"address"}, 0, 1) eq "\"" 25 9472 9497
431 9497 ▶ substr($e->{'address'}, -1, 1, '') if substr($e->{'address'}, -1, 1) eq '"';
Branch: 1 branch
BranchTrueFalseTotal
if substr($e->{"address"}, -1, 1) eq "\"" 21 9476 9497
432 }
433  
434 9518 ▶ if( $addrs ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($addrs) { } 5802 3716 9518
435 # Almost compatible with parse() method, returns email address only
436 5802 delete $e->{'name'};
437 5802 delete $e->{'comment'};
438  
439 } else {
440 # Remove double-quotations, trailing spaces.
441 3716 for my $f ('name', 'comment') { s/\A[ ]//g, s/[ ]\z//g for $e->{ $f } }
442 3716 ▶ $e->{'comment'} = '' unless $e->{'comment'} =~ /\A[(].+[)]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $e->{"comment"} =~ /\A[(].+[)]\z/u 3655 61 3716
443 3716 ▶ $e->{'name'} =~ y/ //s unless $e->{'name'} =~ /\A["].+["]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $e->{"name"} =~ /\A["].+["]\z/u 2803 913 3716
444 3716 ▶ $e->{'name'} =~ s/\A["]// unless $e->{'name'} =~ /\A["].+["][@]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $e->{"name"} =~ /\A["].+["][\@]/u 3708 8 3716
445 3716 ▶ substr($e->{'name'}, -1, 1, '') if substr($e->{'name'}, -1, 1) eq '"';
Branch: 1 branch
BranchTrueFalseTotal
if substr($e->{"name"}, -1, 1) eq "\"" 916 2800 3716
446 }
447 9518 push @$addrtables, $e;
448 }
449  
450 9692 ▶ return undef unless scalar @$addrtables;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$addrtables 176 9516 9692
451 9516 return $addrtables;
452 }
453  
454 5928 ▶sub s3s4 {
Subroutine s3s4: called CC=4 SCAR=13.9
Pod documented
455 # Runs like ruleset 3,4 of sendmail.cf
456 # @param [String] input Text including an email address
457 # @return [String] Email address without comment, brackets
458 5928 my $class = shift;
459 5928 ▶ my $input = shift // return "";
Condition50%1/2
shift() // (return "")
l!l
59280
MC/DC0%0/1
shift() // (return "")
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
460 5928 ▶ my $addrs = __PACKAGE__->find($input, 1) || [];
Condition100%2/2
__PACKAGE__->find($input, 1) || []
l!l
5757171
MC/DC100%1/1
__PACKAGE__->find($input, 1) || []
__PACKAGE__->find($input, 1)
Truth table100%2/2
A
A= __PACKAGE__->find($input, 1)
Aresult
11
00
461 5928 ▶ return $input unless scalar @$addrs;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$addrs 171 5757 5928
462 5757 return $addrs->[0]->{'address'};
463 }
464  
465 7296 ▶sub expand_verp {
Subroutine expand_verp: called CC=4 SCAR=13.9
Pod documented
466 # Expand VERP: Get the original recipient address from VERP
467 # @param [String] email VERP Address
468 # @return [String] Email address
469 7296 my $class = shift;
470 7296 ▶ my $email = shift // return "";
Condition100%2/2
shift() // (return "")
l!l
72951
MC/DC100%1/1
shift() // (return "")
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
471 7295 my $local = (split('@', $email, 2))[0];
472  
473 # bounce+neko=example.org@example.org => neko@example.org
474 7295 ▶ return "" unless $local =~ /\A[-_\w]+?[+](\w[-._\w]+\w)[=](\w[-.\w]+\w)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $local =~ /\A[-_\w]+?[+](\w[-._\w]+\w)[=](\w[-.\w]+\w)\z/u 7293 2 7295
475 2 my $verp0 = $1.'@'.$2;
476 2 ▶ return $verp0 if __PACKAGE__->is_emailaddress($verp0);
Branch: 1 branch
BranchTrueFalseTotal
if __PACKAGE__->is_emailaddress($verp0) 2 0 2
477 }
478  
479 7295 ▶sub expand_alias {
Subroutine expand_alias: called CC=4 SCAR=13.9
Pod documented
480 # Expand alias: remove from '+' to '@'
481 # @param [String] email Email alias string
482 # @return [String] Expanded email address
483 7295 my $class = shift;
484 7295 ▶ my $email = shift // return ""; return "" unless __PACKAGE__->is_emailaddress($email);
Branch: 1 branch
BranchTrueFalseTotal
unless __PACKAGE__->is_emailaddress($email) 20 7274 7294
Condition100%2/2
shift() // (return "")
l!l
72941
MC/DC100%1/1
shift() // (return "")
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
485  
486 # neko+straycat@example.org => neko@example.org
487 7274 my @local = split('@', $email);
488 7274 ▶ return "" unless $local[0] =~ /\A([-_\w]+?)[+].+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $local[0] =~ /\A([-_\w]+?)[+].+\z/u 7262 12 7274
489 12 return $1.'@'.$local[1];
490 }
491  
492 1387 ▶sub TO_JSON {
Subroutine TO_JSON: called CC=1 SCAR=0.0
Pod undocumented
493 # Instance method for JSON::encode()
494 # @return [String] The value of "address" accessor
495 1387 my $self = shift; return $self->address;
496 }
497  
498 93 1;
499 __END__
« Sisimai/Lhost/Sendmail.pm ↑ Summary Sisimai/Lhost/Domino.pm »