lib/Mail/DKIM2/Address.pm

filter: Statementstmt 53.4% 149 / 279 Branchbran 46.3% 101 / 218 Conditioncond 24.5% 28 / 114 MC/DCmcdc 9.3% 6 / 64 Subroutinesub 62.0% 18 / 29 Podpod 100% 21 / 21 totaltotal 44.5% 323 / 725 CC 159 SCAR 49.2
CC
159
Cov
45%
from_mailbox
329.5
from_mailbox
329.5
relaxed_domain_match
29.6
CRAP 136.9
« lib/Mail/DKIM2/Fold.pm ↑ Summary bin/dkim2-milter »
1 package Mail::DKIM2::Address;
2 222 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 222 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 222 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 222 our $VERSION = '0.34';
7  
8 222 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 222 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 222 our @EXPORT_OK = qw(
12 extract_domain
13 to_rfc5321_path
14 domain_of
15 to_alabel
16 from_domain
17 from_mailbox
18 from_authentic
19 from_refusal_note
20 relaxed_domain_match
21 parent_from_matcher
22 from_pair_error
23 );
24  
25 # Extract the domain from an email address (handles <user@domain> and
26 # user@domain). Deprecated: domain_of is the one the library uses -- it
27 # lowercases, drops a trailing dot and knows a domain literal.
28 1 ▶sub extract_domain {
Subroutine extract_domain: called CC=3 SCAR=16.0
Pod documented
29 0 ▶ my ($addr) = @_;
Subroutine extract_domain: not called CC=3 SCAR=16.0
Pod documented
30 0 ▶ return unless $addr;
Branch: 2 branches
BranchTrueFalseTotal
unless $addr 0 1 1
unless $addr 0 0 0
31 0 $addr =~ s/^.*<//;
32 0 $addr =~ s/>.*$//;
33 0 ▶ return unless $addr =~ /\@(.+)$/;
Branch: 2 branches
BranchTrueFalseTotal
unless $addr =~ /\@(.+)$/u 0 1 1
unless $addr =~ /\@(.+)$/u 0 0 0
34 0 return $1;
35 }
36  
37 # Wrap an address as an RFC5321 reverse-/forward-path for mf=/rt= (-09
38 # sections 10.5, 10.6): angle brackets MUST be present. Empty/undef -> "<>"; an
39 # already-bracketed value (incl. "<>") is returned unchanged.
40 1295 ▶sub to_rfc5321_path {
Subroutine to_rfc5321_path: called CC=4 SCAR=20.9
Pod documented
41 0 ▶ my ($addr) = @_;
Subroutine to_rfc5321_path: not called CC=4 SCAR=20.9
Pod documented
42 0 ▶ return '<>' unless defined $addr && length $addr;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $addr and length $addr 0 1295 1295
unless defined $addr and length $addr 0 0 0
Condition16%1/6
defined $addr and length $addr
!ll&&!rl&&r
001295
defined $addr and length $addr
!ll&&!rl&&r
000
MC/DC0%0/2
defined $addr and length $addr
defined $addr length $addr
MC/DC0%0/2
defined $addr and length $addr
defined $addr length $addr
Truth table33%1/3
A and B
A= defined $addrB= length $addr
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $addrB= length $addr
ABresult
0X0
100
111
43 0 ▶ return $addr if $addr =~ /^<.*>$/s;
Branch: 2 branches
BranchTrueFalseTotal
if $addr =~ /^<.*>$/su 114 1181 1295
if $addr =~ /^<.*>$/su 0 0 0
44 0 return "<$addr>";
45 }
46  
47 # domain_of($addr): the domain of an address or path, as ($domain,
48 # $is_literal), or the empty list when there is none (no "@", or "<>").
49 # The text between the last "@" and the closing ">" (or the end),
50 # lowercased, with one trailing dot taken off: Postfix hands on
51 # "<A@Example.COM.>" as it was given. A domain literal ("[192.0.2.1]") is
52 # returned with $is_literal true; it never matches anything (-09 section
53 # 7.2).
54 2830 ▶sub domain_of {
Subroutine domain_of: called CC=5 SCAR=22.2
Pod documented
55 0 ▶ my ($addr) = @_;
Subroutine domain_of: not called CC=5 SCAR=22.2
Pod documented
56 0 ▶ return unless defined $addr;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $addr 0 2830 2830
unless defined $addr 0 0 0
57 0 my $at = rindex($addr, '@');
58 0 ▶ return if $at < 0;
Branch: 2 branches
BranchTrueFalseTotal
if $at < 0 2 2828 2830
if $at < 0 0 0 0
59 0 my $dom = substr($addr, $at + 1);
60 0 $dom =~ s/>.*\z//s;
61 0 $dom =~ s/\A\s+|\s+\z//g;
62 0 $dom =~ tr/A-Z/a-z/; # ASCII only: the octets may be UTF-8
63 0 $dom =~ s/\.\z//;
64 0 ▶ return unless length $dom;
Branch: 2 branches
BranchTrueFalseTotal
unless length $dom 0 2828 2828
unless length $dom 0 0 0
65 0 ▶ return ($dom, $dom =~ /\A\[/ ? 1 : 0);
Branch: 2 branches
BranchTrueFalseTotal
$dom =~ /\A\[/u ? : 8 2820 2828
$dom =~ /\A\[/u ? : 0 0 0
66 }
67  
68 # to_alabel($domain): $domain with each label that is not ASCII lowercased
69 # and written as its A-label, "xn--" and the RFC 3492 Punycode of the label
70 # (-09 section 18). ASCII labels are left as they are. The input is UTF-8
71 # octets, as a header field or a decoded mf=/rt= carries it (a character
72 # string is taken as it is); a label that is not valid UTF-8 is left alone.
73 # This is the label mapping only, not UTS 46.
74 7930 ▶sub to_alabel {
Subroutine to_alabel: called CC=7 SCAR=27.5
Pod documented
75 0 ▶ my ($domain) = @_;
Subroutine to_alabel: not called CC=7 SCAR=27.5
Pod documented
76 0 ▶ return $domain unless defined $domain && $domain =~ /[^\x00-\x7F]/;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $domain and $domain =~ /[^\x00-\x7F]/u 7923 7 7930
unless defined $domain and $domain =~ /[^\x00-\x7F]/u 0 0 0
Condition33%2/6
defined $domain and $domain =~ /[^\x00-\x7F]/u
!ll&&!rl&&r
079237
defined $domain and $domain =~ /[^\x00-\x7F]/u
!ll&&!rl&&r
000
MC/DC50%1/2
defined $domain and $domain =~ /[^\x00-\x7F]/u
defined $domain $domain =~ /[^\x00-\x7F]/u
MC/DC0%0/2
defined $domain and $domain =~ /[^\x00-\x7F]/u
defined $domain $domain =~ /[^\x00-\x7F]/u
Truth table66%2/3
A and B
A= defined $domainB= $domain =~ /[^\x00-\x7F]/u
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $domainB= $domain =~ /[^\x00-\x7F]/u
ABresult
0X0
100
111
77 0 require URI::_punycode;
78 return join '.', map {
79 0 my $label = $_;
80 0 ▶ if ($label =~ /[^\x00-\x7F]/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($label =~ /[^\x00-\x7F]/u) 7 8 15
if ($label =~ /[^\x00-\x7F]/u) 0 0 0
81 my $chars = utf8::is_utf8($label) ? $label
82 0 ▶ : eval { Encode::decode('UTF-8', $label, Encode::FB_CROAK() | Encode::LEAVE_SRC()) };
Branch: 2 branches
BranchTrueFalseTotal
utf8::is_utf8($label) ? : 0 7 7
utf8::is_utf8($label) ? : 0 0 0
83 0 ▶ die $@ if ref $@;
Branch: 2 branches
BranchTrueFalseTotal
if ref $@ 0 7 7
if ref $@ 0 0 0
84 0 ▶ $label = 'xn--' . URI::_punycode::encode_punycode(lc $chars) if defined $chars;
Branch: 2 branches
BranchTrueFalseTotal
if defined $chars 6 1 7
if defined $chars 0 0 0
85 }
86 0 $label;
87 } split /\./, $domain, -1;
88 }
89  
90 # from_domain(@values): the domain a From header field is Authentic for
91 # (-09 section 11), from the values of every From field in one version of
92 # the header (each as header_raw gives it, folded or not): the lowercased
93 # A-label domain of its one mailbox, or undef when there is none -- no From
94 # field or more than one, a field that is not exactly one mailbox (a list
95 # of them, a group), no "@", or a domain literal. Lenient otherwise: the
96 # display name, quoted or RFC 2047 encoded, and comments are skipped; the
97 # mailbox is "Name <addr>" or a bare addr-spec ("Name addr", display text
98 # with no angle brackets, is not one).
99 8 ▶sub from_domain {
Subroutine from_domain: called CC=2 SCAR=9.2
Pod documented
100 0 ▶ my ($state, $dom) = from_mailbox(@_);
Subroutine from_domain: not called CC=2 SCAR=9.2
Pod documented
101 0 ▶ return $state eq 'ok' ? $dom : undef;
Branch: 2 branches
BranchTrueFalseTotal
$state eq 'ok' ? : 6 2 8
$state eq 'ok' ? : 0 0 0
102 }
103  
104 # The longest From field value read for its mailbox, in octets with the
105 # line breaks of folding and the white space around it left out; a longer
106 # one is not one mailbox. Every implementation in the interop repository
107 # has this limit.
108 222 our $MAX_FROM_LENGTH = 2048;
109  
110 1440 ▶sub _from_length {
Subroutine _from_length: called CC=2 SCAR=10.0
111 0 ▶ my ($v) = @_;
Subroutine _from_length: not called CC=2 SCAR=10.0
112 0 ▶ utf8::encode($v) if utf8::is_utf8($v);
Branch: 2 branches
BranchTrueFalseTotal
if utf8::is_utf8($v) 0 1440 1440
if utf8::is_utf8($v) 0 0 0
113 0 $v =~ tr/\r\n//d;
114 0 $v =~ s/\A[ \t]+//;
115 0 $v =~ s/[ \t]+\z//;
116 0 return length $v;
117 }
118  
119 # from_mailbox(@values): from_domain's reading of the From field(s), with the
120 # reason when there is no domain (-09 section 14.8 names them): ('ok',
121 # $domain); ('multiple') for more than one mailbox -- two From fields, or a
122 # list of addresses; ('literal') for a domain literal; ('none') for no From
123 # field, or a value that is not one mailbox (a group, no "@", bad syntax,
124 # or longer than $MAX_FROM_LENGTH).
125 1536 ▶sub from_mailbox {
Subroutine from_mailbox: called CC=37 SCAR=58.0
Pod documented
126 0 ▶ my (@values) = @_;
Subroutine from_mailbox: not called CC=37 SCAR=58.0
Pod documented
127 0 ▶ return 'multiple' if @values > 1;
Branch: 2 branches
BranchTrueFalseTotal
if @values > 1 12 1524 1536
if @values > 1 0 0 0
128 0 ▶ return 'none' unless @values == 1 && defined $values[0];
Branch: 2 branches
BranchTrueFalseTotal
unless @values == 1 and defined $values[0] 84 1440 1524
unless @values == 1 and defined $values[0] 0 0 0
Condition33%2/6
@values == 1 and defined $values[0]
!ll&&!rl&&r
8401440
@values == 1 and defined $values[0]
!ll&&!rl&&r
000
MC/DC50%1/2
@values == 1 and defined $values[0]
@values == 1 defined $values[0]
MC/DC0%0/2
@values == 1 and defined $values[0]
@values == 1 defined $values[0]
Truth table66%2/3
A and B
A= @values == 1B= defined $values[0]
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= @values == 1B= defined $values[0]
ABresult
0X0
100
111
129 0 ▶ return 'none' if _from_length($values[0]) > $MAX_FROM_LENGTH;
Branch: 2 branches
BranchTrueFalseTotal
if _from_length($values[0]) > $Mail::DKIM2::Address::MAX_FROM_LENGTH 2 1438 1440
if _from_length($values[0]) > $Mail::DKIM2::Address::MAX_FROM_LENGTH 0 0 0
130 0 (my $v = $values[0]) =~ s/\r?\n(?=[ \t])//g;
131 # One pass: comments dropped, quoted strings kept whole, and the
132 # structure outside them ($skel) and the angle brackets found.
133 0 my ($out, $skel, $depth, $inq, $inlit, @lt, @gt) = ('', '', 0, 0, 0);
134 0 ▶ for (my $i = 0; $i < length $v; $i++) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i < length $v) 48580 1438 50018
if ($i < length $v) 0 0 0
135 0 my $c = substr($v, $i, 1);
136 # A domain literal's ":"s (IPv6) are not a group: "[...]" is kept
137 # whole, out of the structure.
138 0 ▶ if ($inlit) {
Branch: 2 branches
BranchTrueFalseTotal
if ($inlit) 57 48523 48580
if ($inlit) 0 0 0
139 0 ▶ if ($c eq '\\') { $out .= substr($v, $i++, 2); next }
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq "\\") 0 57 57
if ($c eq "\\") 0 0 0
140 0 ▶ $inlit = 0 if $c eq ']';
Branch: 2 branches
BranchTrueFalseTotal
if $c eq "]" 5 52 57
if $c eq "]" 0 0 0
141 0 $out .= $c;
142 0 next;
143 }
144 0 ▶ if ($inq) {
Branch: 2 branches
BranchTrueFalseTotal
if ($inq) 9399 39124 48523
if ($inq) 0 0 0
145 0 ▶ if ($c eq '\\') { $out .= substr($v, $i++, 2); next }
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq "\\") 0 9399 9399
if ($c eq "\\") 0 0 0
146 0 ▶ $inq = 0 if $c eq '"';
Branch: 2 branches
BranchTrueFalseTotal
if $c eq "\"" 308 9091 9399
if $c eq "\"" 0 0 0
147 0 $out .= $c;
148 0 next;
149 }
150 0 ▶ if ($depth) {
Branch: 2 branches
BranchTrueFalseTotal
if ($depth) 28 39096 39124
if ($depth) 0 0 0
151 0 ▶ if ($c eq '\\') { $i++ }
Branch: 6 branches
BranchTrueFalseTotal
if ($c eq '\\') { } 0 28 28
elsif ($c eq '(') { } 0 28 28
elsif ($c eq ')') { } 2 26 28
if ($c eq '\\') { } 0 0 0
elsif ($c eq '(') { } 0 0 0
elsif ($c eq ')') { } 0 0 0
152 0 elsif ($c eq '(') { $depth++ }
153 0 elsif ($c eq ')') { $depth-- }
154 0 next;
155 }
156 0 ▶ if ($c eq '(') { $depth = 1; $out .= ' '; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq "(") 2 39094 39096
if ($c eq "(") 0 0 0
157 0 ▶ if ($c eq '"') { $inq = 1; $out .= $c; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq "\"") 308 38786 39094
if ($c eq "\"") 0 0 0
158 0 ▶ if ($c eq '[') { $inlit = 1; $out .= $c; next }
Branch: 2 branches
BranchTrueFalseTotal
if ($c eq "[") 5 38781 38786
if ($c eq "[") 0 0 0
159 0 ▶ push @lt, length $out if $c eq '<';
Branch: 2 branches
BranchTrueFalseTotal
if $c eq "<" 915 37866 38781
if $c eq "<" 0 0 0
160 0 ▶ push @gt, length $out if $c eq '>';
Branch: 2 branches
BranchTrueFalseTotal
if $c eq ">" 915 37866 38781
if $c eq ">" 0 0 0
161 0 $skel .= $c;
162 0 $out .= $c;
163 }
164 0 ▶ return 'none' if $inq || $depth || $inlit;
Branch: 2 branches
BranchTrueFalseTotal
if $inq or $depth or $inlit 0 1438 1438
if $inq or $depth or $inlit 0 0 0
Condition16%2/12
$inq or $depth or $inlit
l!l&&r!l&&!r
001438
$inq or $depth
l!l&&r!l&&!r
001438
$inq or $depth or $inlit
l!l&&r!l&&!r
000
$inq or $depth
l!l&&r!l&&!r
000
MC/DC0%0/3
$inq or $depth or $inlit
$inq $depth $inlit
MC/DC0%0/3
$inq or $depth or $inlit
$inq $depth $inlit
Truth table25%1/4
A or B or C
A= $inqB= $depthC= $inlit
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
A or B or C
A= $inqB= $depthC= $inlit
ABCresult
1XX1
01X1
0011
0000
165 # A "," is a second mailbox; a ":" or ";" a group (or an obsolete route).
166 0 ▶ return 'multiple' if $skel =~ /,/;
Branch: 2 branches
BranchTrueFalseTotal
if $skel =~ /,/u 6 1432 1438
if $skel =~ /,/u 0 0 0
167 0 ▶ return 'none' if $skel =~ /[:;]/;
Branch: 2 branches
BranchTrueFalseTotal
if $skel =~ /[:;]/u 3 1429 1432
if $skel =~ /[:;]/u 0 0 0
168 0 my $addr = $out;
169 0 ▶ if (@lt || @gt) {
Branch: 2 branches
BranchTrueFalseTotal
if (@lt or @gt) 911 518 1429
if (@lt or @gt) 0 0 0
Condition33%2/6
@lt or @gt
l!l&&r!l&&!r
9110518
@lt or @gt
l!l&&r!l&&!r
000
MC/DC50%1/2
@lt or @gt
@lt @gt
MC/DC0%0/2
@lt or @gt
@lt @gt
Truth table66%2/3
A or B
A= @ltB= @gt
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= @ltB= @gt
ABresult
1X1
011
000
170 0 ▶ return 'none' unless @lt == 1 && @gt == 1 && $lt[0] < $gt[0]
Branch: 2 branches
BranchTrueFalseTotal
unless @lt == 1 and @gt == 1 and $lt[0] < $gt[0] and not substr($out, $gt[0] + 1) =~ /\S/u 0 911 911
unless @lt == 1 and @gt == 1 and $lt[0] < $gt[0] and not substr($out, $gt[0] + 1) =~ /\S/u 0 0 0
Condition16%3/18
@lt == 1 and @gt == 1 and $lt[0] < $gt[0] and not substr($out, $gt[0] + 1) =~ /\S/u
!ll&&!rl&&r
00911
@lt == 1 and @gt == 1 and $lt[0] < $gt[0]
!ll&&!rl&&r
00911
@lt == 1 and @gt == 1
!ll&&!rl&&r
00911
@lt == 1 and @gt == 1 and $lt[0] < $gt[0] and not substr($out, $gt[0] + 1) =~ /\S/u
!ll&&!rl&&r
000
@lt == 1 and @gt == 1 and $lt[0] < $gt[0]
!ll&&!rl&&r
000
@lt == 1 and @gt == 1
!ll&&!rl&&r
000
MC/DC0%0/4
@lt == 1 and @gt == 1 and $lt[0] < $gt[0] and not substr($out, $gt[0] + 1) =~ /\S/u
@lt == 1 @gt == 1 $lt[0] < $gt[0] not substr($out, $gt[0] + 1) =~ /\S/u
MC/DC0%0/4
@lt == 1 and @gt == 1 and $lt[0] < $gt[0] and not substr($out, $gt[0] + 1) =~ /\S/u
@lt == 1 @gt == 1 $lt[0] < $gt[0] not substr($out, $gt[0] + 1) =~ /\S/u
Truth table20%1/5
A and B and C and not(D)
A= @lt == 1B= @gt == 1C= $lt[0] < $gt[0]D= not substr($out, $gt[0] + 1) =~ /\S/u
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/5
A and B and C and not(D)
A= @lt == 1B= @gt == 1C= $lt[0] < $gt[0]D= not substr($out, $gt[0] + 1) =~ /\S/u
ABCDresult
0XXX0
10XX0
110X0
11100
11111
171 && substr($out, $gt[0] + 1) !~ /\S/;
172 0 $addr = substr($out, $lt[0] + 1, $gt[0] - $lt[0] - 1);
173 }
174 0 $addr =~ s/\A\s+|\s+\z//g;
175 # White space (or a comment) between two parts of the address: "Name
176 # a@b", display text with no angle brackets, is not one mailbox.
177 0 ▶ return 'none' if ($addr =~ s/"(?:[^"\\]|\\.)*"/""/gr) =~ /\s/;
Branch: 2 branches
BranchTrueFalseTotal
if ($addr =~ s/"(?:[^"\\]|\\.)*"/""/gru) =~ /\s/u 3 1426 1429
if ($addr =~ s/"(?:[^"\\]|\\.)*"/""/gru) =~ /\s/u 0 0 0
178 0 ▶ return 'none' unless index($addr, '@') > 0;
Branch: 2 branches
BranchTrueFalseTotal
unless index($addr, "\@") > 0 1 1425 1426
unless index($addr, "\@") > 0 0 0 0
179 0 my ($dom, $literal) = domain_of($addr);
180 0 ▶ return 'none' if !$dom || $dom =~ /\s/;
Branch: 2 branches
BranchTrueFalseTotal
if not $dom or $dom =~ /\s/u 0 1425 1425
if not $dom or $dom =~ /\s/u 0 0 0
Condition16%1/6
not $dom or $dom =~ /\s/u
l!l&&r!l&&!r
001425
not $dom or $dom =~ /\s/u
l!l&&r!l&&!r
000
MC/DC0%0/2
not $dom or $dom =~ /\s/u
not $dom $dom =~ /\s/u
MC/DC0%0/2
not $dom or $dom =~ /\s/u
not $dom $dom =~ /\s/u
Truth table33%1/3
not(A) or B
A= not $domB= $dom =~ /\s/u
ABresult
1X1
011
000
Truth table0%0/3
not(A) or B
A= not $domB= $dom =~ /\s/u
ABresult
1X1
011
000
181 0 ▶ return 'literal' if $literal;
Branch: 2 branches
BranchTrueFalseTotal
if $literal 5 1420 1425
if $literal 0 0 0
182 0 return ('ok', to_alabel($dom) =~ tr/A-Z/a-z/r);
183 }
184  
185 # from_authentic($d, @values): true if the From field(s) of one version of
186 # the header, as from_domain takes them, are Authentic for signing domain
187 # $d: from_domain gives a domain and it relaxed-matches $d (-09 section 11).
188 1 ▶sub from_authentic {
Subroutine from_authentic: called CC=3 SCAR=17.8
Pod documented
189 0 ▶ my ($d, @values) = @_;
Subroutine from_authentic: not called CC=3 SCAR=17.8
Pod documented
190 0 my $dom = from_domain(@values);
191 0 ▶ return defined $dom && relaxed_domain_match($dom, $d) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
defined $dom && relaxed_domain_match($dom, $d) ? : 1 0 1
defined $dom && relaxed_domain_match($dom, $d) ? : 0 0 0
Condition16%1/6
defined $dom and relaxed_domain_match($dom, $d)
!ll&&!rl&&r
001
defined $dom and relaxed_domain_match($dom, $d)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dom and relaxed_domain_match($dom, $d)
defined $dom relaxed_domain_match($dom, $d)
MC/DC0%0/2
defined $dom and relaxed_domain_match($dom, $d)
defined $dom relaxed_domain_match($dom, $d)
Truth table33%1/3
A and B
A= defined $domB= relaxed_domain_match($dom, $d)
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $domB= relaxed_domain_match($dom, $d)
ABresult
0X0
100
111
192 }
193  
194 # from_refusal_note($d, @values): for the log of a signer's From refusal,
195 # the From domain against the signing domain $d, with what to do about it
196 # (final review I3): a DKIM2 list rewrites From to its posting address, and
197 # a milter signing with a domain that is not that one's, or above it,
198 # refuses every post.
199 7 ▶sub from_refusal_note {
Subroutine from_refusal_note: called CC=5 SCAR=22.3
Pod documented
200 0 ▶ my ($d, @values) = @_;
Subroutine from_refusal_note: not called CC=5 SCAR=22.3
Pod documented
201 0 my $from = from_domain(@values);
202 0 ▶ unless (defined $from) {
Branch: 2 branches
BranchTrueFalseTotal
unless (defined $from) 2 5 7
unless (defined $from) 0 0 0
203 0 ▶ if (@values == 1 && defined $values[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if (@values == 1 and defined $values[0]) { } 1 1 2
if (@values == 1 and defined $values[0]) { } 0 0 0
Condition33%2/6
@values == 1 and defined $values[0]
!ll&&!rl&&r
101
@values == 1 and defined $values[0]
!ll&&!rl&&r
000
MC/DC50%1/2
@values == 1 and defined $values[0]
@values == 1 defined $values[0]
MC/DC0%0/2
@values == 1 and defined $values[0]
@values == 1 defined $values[0]
Truth table66%2/3
A and B
A= @values == 1B= defined $values[0]
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= @values == 1B= defined $values[0]
ABresult
0X0
100
111
204 0 (my $text = $values[0]) =~ s/[\r\n]+/ /g;
205 0 $text =~ s/\A\s+|\s+\z//g;
206 0 $from = '(not one mailbox: ' . substr($text, 0, 100) . ')';
207 } else {
208 0 $from = '(' . scalar(@values) . ' From fields)';
209 }
210 }
211 0 ▶ return "From domain $from is not d=" . ($d // '(none)') . " or below it: a DKIM2 "
Condition25%1/4
$d // "(none)"
l!l
70
$d // "(none)"
l!l
00
MC/DC0%0/1
$d // "(none)"
$d
MC/DC0%0/1
$d // "(none)"
$d
Truth table50%1/2
A
A= $d
Aresult
11
00
Truth table0%0/2
A
A= $d
Aresult
11
00
212 . "list's posting address must be in the domain this milter signs with";
213 }
214  
215 # relaxed_domain_match($p1, $p2): the relaxed domain match of -09 section
216 # 7.2. Both are compared as A-labels, without regard to case, and without
217 # one trailing dot. A domain literal on either side never matches. Otherwise
218 # labels come off the LEFT of $p1 only, until it equals $p2 (a match) or
219 # has no dot left (no match): so $p1 may be $p2 or below it, never above.
220 2583 ▶sub relaxed_domain_match {
Subroutine relaxed_domain_match: called CC=9 SCAR=33.9
Pod documented
221 0 ▶ my ($p1, $p2) = @_;
Subroutine relaxed_domain_match: not called CC=9 SCAR=33.9
Pod documented
222 0 ▶ return 0 unless defined $p1 && defined $p2 && length $p1 && length $p2;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $p1 and defined $p2 and length $p1 and length $p2 0 2583 2583
unless defined $p1 and defined $p2 and length $p1 and length $p2 0 0 0
Condition16%3/18
defined $p1 and defined $p2 and length $p1 and length $p2
!ll&&!rl&&r
002583
defined $p1 and defined $p2 and length $p1
!ll&&!rl&&r
002583
defined $p1 and defined $p2
!ll&&!rl&&r
002583
defined $p1 and defined $p2 and length $p1 and length $p2
!ll&&!rl&&r
000
defined $p1 and defined $p2 and length $p1
!ll&&!rl&&r
000
defined $p1 and defined $p2
!ll&&!rl&&r
000
MC/DC0%0/4
defined $p1 and defined $p2 and length $p1 and length $p2
defined $p1 defined $p2 length $p1 length $p2
MC/DC0%0/4
defined $p1 and defined $p2 and length $p1 and length $p2
defined $p1 defined $p2 length $p1 length $p2
Truth table20%1/5
A and B and C and D
A= defined $p1B= defined $p2C= length $p1D= length $p2
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/5
A and B and C and D
A= defined $p1B= defined $p2C= length $p1D= length $p2
ABCDresult
0XXX0
10XX0
110X0
11100
11111
223 0 ($p1, $p2) = map { my $d = to_alabel($_) =~ tr/A-Z/a-z/r; $d =~ s/\.\z//; $d } $p1, $p2;
224 0 ▶ return 0 if $p1 =~ /\A\[/ || $p2 =~ /\A\[/;
Branch: 2 branches
BranchTrueFalseTotal
if $p1 =~ /\A\[/u or $p2 =~ /\A\[/u 1 2582 2583
if $p1 =~ /\A\[/u or $p2 =~ /\A\[/u 0 0 0
Condition33%2/6
$p1 =~ /\A\[/u or $p2 =~ /\A\[/u
l!l&&r!l&&!r
102582
$p1 =~ /\A\[/u or $p2 =~ /\A\[/u
l!l&&r!l&&!r
000
MC/DC50%1/2
$p1 =~ /\A\[/u or $p2 =~ /\A\[/u
$p1 =~ /\A\[/u $p2 =~ /\A\[/u
MC/DC0%0/2
$p1 =~ /\A\[/u or $p2 =~ /\A\[/u
$p1 =~ /\A\[/u $p2 =~ /\A\[/u
Truth table66%2/3
A or B
A= $p1 =~ /\A\[/uB= $p2 =~ /\A\[/u
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $p1 =~ /\A\[/uB= $p2 =~ /\A\[/u
ABresult
1X1
011
000
225 0 while (1) {
226 0 ▶ return 1 if $p1 eq $p2;
Branch: 2 branches
BranchTrueFalseTotal
if $p1 eq $p2 2489 333 2822
if $p1 eq $p2 0 0 0
227 0 ▶ $p1 =~ s/\A[^.]*\.// or return 0;
Branch: 2 branches
BranchTrueFalseTotal
$p1 =~ s/\A[^.]*\.//u or return 0 240 93 333
$p1 =~ s/\A[^.]*\.//u or return 0 0 0 0
228 }
229 }
230  
231 # parent_from_matcher(@domains): a Signer ParentFromCallback (-09 contract
232 # E3.4) that is true for a From domain in @domains, each compared as the
233 # callback gets it: an A-label, lowercased, without one trailing dot.
234 92 ▶sub parent_from_matcher {
Subroutine parent_from_matcher: called CC=2 SCAR=9.5
Pod documented
235 0 my %ok = map { (to_alabel($_) =~ tr/A-Z/a-z/r) =~ s/\.\z//r => 1 }
236 0 ▶ grep { defined && length } @_;
Subroutine parent_from_matcher: not called CC=2 SCAR=9.5
Pod documented
Condition16%1/6
defined $_ && length $_
!ll&&!rl&&r
004
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
237 0 ▶ return sub { $ok{ $_[0] // '' } ? 1 : 0 };
Subroutine __ANON__: called CC=3 SCAR=11.7
Branch: 1 branch
BranchTrueFalseTotal
$ok{$_[0] // ''} ? : 5 3 8
Condition50%1/2
$_[0] // ""
l!l
80
MC/DC0%0/1
$_[0] // ""
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
238 }
239  
240 # from_pair_error($d, $policy, @from): -09 section 14.8 for one signing
241 # domain $d and the From field values it must make Authentic (contract
242 # E3.1), for the Verifier and the Signer alike: undef when Authentic, else
243 # [$state, $text] -- 'fail', 'permerror' or 'temperror', and the text after
244 # "DKIM2-Signature i=<x> ". $policy->($domain) gives that domain's Domain
245 # Policy Record as domain_policy does, or 'temperror'; it is called only
246 # when d= is below the From domain.
247 838 ▶sub from_pair_error {
Subroutine from_pair_error: called CC=11 SCAR=24.0
Pod documented
248 838 my ($d, $policy, @from) = @_;
249 838 my ($state, $dom) = from_mailbox(@from);
250 838 ▶ return ['fail', 'From has more than one address'] if $state eq 'multiple';
Branch: 1 branch
BranchTrueFalseTotal
if $state eq "multiple" 8 830 838
251 830 ▶ return ['fail', 'From uses a domain literal'] if $state eq 'literal';
Branch: 1 branch
BranchTrueFalseTotal
if $state eq "literal" 2 828 830
252 828 ▶ return ['fail', 'matching From is not authentic']
Branch: 1 branch
BranchTrueFalseTotal
unless $state eq "ok" and defined $d and length $d 4 824 828
Condition66%4/6
$state eq "ok" and defined $d and length $d
!ll&&!rl&&r
40824
$state eq "ok" and defined $d
!ll&&!rl&&r
40824
MC/DC33%1/3
$state eq "ok" and defined $d and length $d
$state eq "ok" defined $d length $d
Truth table50%2/4
A and B and C
A= $state eq "ok"B= defined $dC= length $d
ABCresult
0XX0
10X0
1100
1111
253 unless $state eq 'ok' && defined $d && length $d;
254 824 ▶ return undef if relaxed_domain_match($dom, $d);
Branch: 1 branch
BranchTrueFalseTotal
if relaxed_domain_match($dom, $d) 784 40 824
255 40 ▶ return ['fail', 'matching From is not authentic'] unless relaxed_domain_match($d, $dom);
Branch: 1 branch
BranchTrueFalseTotal
unless relaxed_domain_match($d, $dom) 11 29 40
256 29 my $p = $policy->($dom);
257 29 ▶ return undef if $p eq 'open';
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "open" 12 17 29
258 17 ▶ return ['fail', "From $dom forbids subdomain signing"] if $p eq 'strict';
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "strict" 14 3 17
259 3 ▶ return ['permerror', "multiple records for $dom policy"] if $p eq 'multiple';
Branch: 1 branch
BranchTrueFalseTotal
if $p eq "multiple" 1 2 3
260 2 return ['temperror', "policy for $dom unavailable"];
261 }
262  
263 222 1;
264  
265 __END__
« lib/Mail/DKIM2/Fold.pm ↑ Summary bin/dkim2-milter »