| 1 | package Mail::DKIM2::HeaderPlan; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 198 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 198 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 198 | our $VERSION = '0.35'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 198 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 198 | ▶ | use Scalar::Util qw(refaddr); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 198 | ▶ | use Mail::DKIM2::Util (); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 198 | ▶ | use Mail::DKIM2::Common qw(parse_mime); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 198 | ▶ | use Mail::DKIM2::Canon qw(should_skip dkim2_canonicalize_header); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 198 | ▶ | use Mail::DKIM2::MessageInstance; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 198 | ▶ | use Mail::DKIM2::BodyPlan; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # Every Message-Instance's header hash from the header fields as received | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # and the header Recipes, without rebuilding any previous header. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # The fields are split once; a value is only unfolded and canonicalized if | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # its name is in the header hash, once. For each field name an instance | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # has a segment list, as Mail::DKIM2::BodyPlan has for body lines: runs of | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # this name's values as received, numbered bottom up as the Recipes number | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # them ([0, from, to]), and of Recipe literals ([1, from, to]). The top | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # instance has every value; each instance below has its parent's lists, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # with its parent's header Recipe applied to the names that Recipe names. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # A name's list that no Recipe touched is shared, and so is its canonical | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # text. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # new($header, IgnorePrefixes => \@prefixes) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # $header: the header fields as received, as one string, or as a list of | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # fields, each with its folded lines and line break (HeaderParser's | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # {headers}). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # Fields that are never content: header Recipes do not reach them. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 198 | my %NOT_CONTENT = map { $_ => 1 } qw(message-instance dkim2-signature); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1367 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | my ($class, $header, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | Mail::DKIM2::Util::check_options("$class->new", \%opts, qw(IgnorePrefixes)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | prefixes => $opts{IgnorePrefixes}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | by_m => {}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | raw => {}, # lc name => its fields, bottom up | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | literals => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | raw_literals => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | for my $raw (reverse @{ _raw_fields($header) }) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | push @{$self->{raw}{Mail::DKIM2::Canon::field_name(substr($raw, 0, index($raw, ':')))}}, $raw; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # The fields of $header (as new() takes it) as strings, each one field and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # its continuation lines, split as Email::Simple splits them (the undo | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # walk's parser): a line that begins with white space, or has no colon, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # continues the field above it. HeaderParser's fields already are, as long | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # as every line ends in a CRLF; any other line break goes through | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # Email::Simple itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 1708 | ▶ | sub _raw_fields { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_raw_fields: called CC=10 SCAR=32.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | my ($header) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_raw_fields: not called CC=10 SCAR=32.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $text = ref $header ? join('', @$header) : $header; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # A CR or LF that is not part of a CRLF. Two patterns, not one: each | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # starts with a fixed character perl can skip to, and the alternation | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # of the two is far slower. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ($text =~ /(?<!\r)\n/ || $text =~ /\r(?!\n)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
$text =~ /(?<!\r)\n/ or $text =~ /\r(?!\n)/
$text =~ /(?<!\r)\n/ or $text =~ /\r(?!\n)/
MC/DC100%2/2
$text =~ /(?<!\r)\n/ or $text =~ /\r(?!\n)/
$text =~ /(?<!\r)\n/
$text =~ /\r(?!\n)/
MC/DC0%0/2
$text =~ /(?<!\r)\n/ or $text =~ /\r(?!\n)/
$text =~ /(?<!\r)\n/
$text =~ /\r(?!\n)/
Truth table100%3/3
A or B
A= $text =~ /(?<!\r)\n/B= $text =~ /\r(?!\n)/
Truth table0%0/3
A or B
A= $text =~ /(?<!\r)\n/B= $text =~ /\r(?!\n)/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my @pairs = parse_mime("$text\r\n")->header_obj->header_raw_pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return [ map { "$pairs[2 * $_]:$pairs[2 * $_ + 1]\r\n" } 0 .. $#pairs / 2 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | return $header if ref $header; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my @fields; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | for my $line (split /\r\n/, $text) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | next unless length $line; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ($line =~ /^\s+/ or $line !~ /^[^:]+:/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
$line =~ /^\s+/ or not $line =~ /^[^:]+:/
$line =~ /^\s+/ or not $line =~ /^[^:]+:/
MC/DC100%2/2
$line =~ /^\s+/ or not $line =~ /^[^:]+:/
$line =~ /^\s+/
not $line =~ /^[^:]+:/
MC/DC0%0/2
$line =~ /^\s+/ or not $line =~ /^[^:]+:/
$line =~ /^\s+/
not $line =~ /^[^:]+:/
Truth table100%3/3
A or not(B)
A= $line =~ /^\s+/B= not $line =~ /^[^:]+:/
Truth table0%0/3
A or not(B)
A= $line =~ /^\s+/B= not $line =~ /^[^:]+:/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | $fields[-1] .= "$line\r\n" if @fields; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | push @fields, "$line\r\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | return \@fields; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # A field's value as Email::Simple's header_raw gives it: after the colon | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # and any white space, each continuation line's leading white space taken | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # off and the line joined on with one space. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 10600 | ▶ | sub _value { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_value: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my ($raw) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_value: not called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my ($first, @more) = split /\r\n/, $raw; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my ($value) = $first =~ /^[^:]+:\s*(.*)/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | for my $line (@more) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | (my $trimmed = $line) =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | $value .= $value =~ /\S/ ? " $trimmed" : $trimmed; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # fields($header): [name, value] for every field, in order. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 341 | ▶ | sub fields { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields: called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | my ($header) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields: not called CC=1 SCAR=1.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # The name without any WSP before its colon ("From :" is a From). | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | return [ map { [ substr($_, 0, index($_, ':')) =~ s/[ \t]+\z//r, _value($_) ] } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | @{ _raw_fields($header) } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # values($name): the values of the fields named $name, top first. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 411 | ▶ | sub values { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values: called CC=2 SCAR=10.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | my ($self, $name) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values: not called CC=2 SCAR=10.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | return reverse map { _value($_) } @{ $self->{raw}{lc $name} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition25%1/4
$self->{'raw'}{lc $name} || []
$self->{'raw'}{lc $name} || []
MC/DC0%0/1
$self->{'raw'}{lc $name} || []
$self->{'raw'}{lc $name}
MC/DC0%0/1
$self->{'raw'}{lc $name} || []
$self->{'raw'}{lc $name}
Truth table50%1/2
A
A= $self->{'raw'}{lc $name}
Truth table0%0/2
A
A= $self->{'raw'}{lc $name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # plan(@instances): the parsed Message-Instance objects, highest m= first; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # works out every instance's header hashes and header Recipe verdicts. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1367 | ▶ | sub plan { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
plan: called CC=14 SCAR=37.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | my ($self, @mis) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
plan: not called CC=14 SCAR=37.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $impl = Mail::DKIM2::MessageInstance::hash_algs(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | my $raw = $self->{raw}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # Message-Instance and DKIM2-Signature fields are not content (-09 section | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # 6.2): a header Recipe naming one acts on content fields of that name, of | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # which there are none, and never on the instances this walk checks. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $lists = { map { $_ => [[0, 1, scalar @{$raw->{$_}}]] } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | grep { !$NOT_CONTENT{$_} } keys %$raw }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # refaddr of a list => [the list, its canonical text]. Holding the list | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # keeps its address from being reused by a later level's list. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my %text; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | for my $mi (@mis) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my $m = 0 + $mi->get_tag('m'); # m=01 is 1 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | my $hashes = $mi->get_tag('hashes') || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition25%1/4
$mi->get_tag('hashes') || {}
$mi->get_tag('hashes') || {}
MC/DC0%0/1
$mi->get_tag('hashes') || {}
$mi->get_tag('hashes')
MC/DC0%0/1
$mi->get_tag('hashes') || {}
$mi->get_tag('hashes')
Truth table50%1/2
A
A= $mi->get_tag('hashes')
Truth table0%0/2
A
A= $mi->get_tag('hashes')
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my $inst = $self->{by_m}{$m} = { lists => $lists }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ($lists) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | my $data = join '', map { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | ($text{refaddr $lists->{$_}} //= [$lists->{$_}, $self->_text($_, $lists->{$_})])->[1] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$text{builtin::refaddr($lists->{$_})} //= [$lists->{$_}, $self->_text($_, $lists->{$_})]
$text{builtin::refaddr($lists->{$_})} //= [$lists->{$_}, $self->_text($_, $lists->{$_})]
MC/DC100%1/1
$text{builtin::refaddr($lists->{$_})} //= [$lists->{$_}, $self->_text($_, $lists->{$_})]
$text{builtin::refaddr($lists->{$_})}
MC/DC0%0/1
$text{builtin::refaddr($lists->{$_})} //= [$lists->{$_}, $self->_text($_, $lists->{$_})]
$text{builtin::refaddr($lists->{$_})}
Truth table100%2/2
A
A= $text{builtin::refaddr($lists->{$_})}
Truth table0%0/2
A
A= $text{builtin::refaddr($lists->{$_})}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | } grep { $self->_hashed($_) } sort keys %$lists; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | $inst->{hash}{$_} = Mail::DKIM2::MessageInstance::_hash_data_b64($_, $data) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | for grep { $impl->{$_} } keys %$hashes; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # The next instance down: each name this Recipe names, in turn, in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # the order undo applies them. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | my $rh = $mi->get_tag('rh') or next; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | next unless $lists; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my %next = %$lists; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | for my $h (sort keys %$rh) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my $lc = Mail::DKIM2::Canon::field_name($h); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | my $cur = $next{$lc} || []; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$next{$lc} || []
$next{$lc} || []
MC/DC100%1/1
$next{$lc} || []
$next{$lc}
MC/DC0%0/1
$next{$lc} || []
$next{$lc}
Truth table100%2/2
A
A= $next{$lc}
Truth table0%0/2
A
A= $next{$lc}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $count += $_->[2] - $_->[1] + 1 for @$cur; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | unless (eval { Mail::DKIM2::MessageInstance::_check_recipe("$h header", $rh->{$h}, $count); 1 }) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $inst->{error} = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $lists = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $first = @{$self->{literals}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $next{$lc} = Mail::DKIM2::BodyPlan::compose($cur, $rh->{$h}, $self->{literals}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # values_at() wants them as they are. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | push @{$self->{raw_literals}}, @{$self->{literals}}[$first .. $#{$self->{literals}}]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | # Literals are values of this name: canonicalize them as such. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | $_ = dkim2_canonicalize_header("$lc: $_\r\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | for @{$self->{literals}}[$first .. $#{$self->{literals}}]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | $lists = \%next if $lists; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 23632 | ▶ | sub _hashed { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hashed: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | my ($self, $lc) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hashed: not called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | return $self->{hashed}{$lc} //= !should_skip($lc, $self->{prefixes}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$self->{"hashed"}{$lc} //= !should_skip($lc, $self->{"prefixes"})
$self->{"hashed"}{$lc} //= !should_skip($lc, $self->{"prefixes"})
MC/DC100%1/1
$self->{"hashed"}{$lc} //= !should_skip($lc, $self->{"prefixes"})
$self->{"hashed"}{$lc}
MC/DC0%0/1
$self->{"hashed"}{$lc} //= !should_skip($lc, $self->{"prefixes"})
$self->{"hashed"}{$lc}
Truth table100%2/2
A
A= $self->{"hashed"}{$lc}
Truth table0%0/2
A
A= $self->{"hashed"}{$lc}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | # The canonical text of one name's segment list; each value as received is | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # canonicalized the first time any list wants it. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 7750 | ▶ | sub _text { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_text: called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | my ($self, $lc, $segs) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_text: not called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | my $canon = $self->{canon}{$lc} //= [ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | map { dkim2_canonicalize_header("$lc: " . _value($_) . "\r\n") } @{ $self->{raw}{$lc} || [] } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%4/8
$self->{"canon"}{$lc} //= [map({dkim2_canonicalize_header("${lc}: " . _value($_) . "\r\n");} @{$self->{"raw"}{$lc} or [];})]
$self->{'raw'}{$lc} || []
$self->{"canon"}{$lc} //= [map({dkim2_canonicalize_header("${lc}: " . _value($_) . "\r\n");} @{$self->{"raw"}{$lc} or [];})]
$self->{'raw'}{$lc} || []
MC/DC100%1/1
$self->{"canon"}{$lc} //= [map({dkim2_canonicalize_header("${lc}: " . _value($_) . "\r\n");} @{$self->{"raw"}{$lc} or [];})]
$self->{"canon"}{$lc}
MC/DC100%1/1
$self->{'raw'}{$lc} || []
$self->{'raw'}{$lc}
MC/DC0%0/1
$self->{"canon"}{$lc} //= [map({dkim2_canonicalize_header("${lc}: " . _value($_) . "\r\n");} @{$self->{"raw"}{$lc} or [];})]
$self->{"canon"}{$lc}
MC/DC0%0/1
$self->{'raw'}{$lc} || []
$self->{'raw'}{$lc}
Truth table100%2/2
A
A= $self->{"canon"}{$lc}
Truth table100%2/2
A
A= $self->{'raw'}{$lc}
Truth table0%0/2
A
A= $self->{"canon"}{$lc}
Truth table0%0/2
A
A= $self->{'raw'}{$lc}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | return join '', map { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my ($type, $s, $e) = @$_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | $type ? @{$self->{literals}}[$s .. $e] : @{$canon}[$s - 1 .. $e - 1] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } @$segs; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # header_hash($m, $alg): the base64 header hash of instance m= by $alg, or | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | # undef if a header Recipe above it does not undo or it has no $alg hash-set. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 3414 | ▶ | sub header_hash { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header_hash: called CC=3 SCAR=16.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | my ($self, $m, $alg) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header_hash: not called CC=3 SCAR=16.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | my $inst = $self->{by_m}{0 + $m} or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | return $inst->{hash} && $inst->{hash}{lc $alg}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$inst->{'hash'} && $inst->{'hash'}{lc $alg}
$inst->{'hash'} && $inst->{'hash'}{lc $alg}
MC/DC50%1/2
$inst->{'hash'} && $inst->{'hash'}{lc $alg}
$inst->{'hash'}
$inst->{'hash'}{lc $alg}
MC/DC0%0/2
$inst->{'hash'} && $inst->{'hash'}{lc $alg}
$inst->{'hash'}
$inst->{'hash'}{lc $alg}
Truth table66%2/3
A && B
A= $inst->{'hash'}B= $inst->{'hash'}{lc $alg}
Truth table0%0/3
A && B
A= $inst->{'hash'}B= $inst->{'hash'}{lc $alg}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # recipe_error($m): why instance m='s header Recipe does not undo, or undef. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 1453 | ▶ | sub recipe_error { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
recipe_error: called CC=2 SCAR=10.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | my ($self, $m) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
recipe_error: not called CC=2 SCAR=10.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | my $inst = $self->{by_m}{0 + $m} or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | return $inst->{error}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # values_at($m, $name): the values of the fields named $name in the header | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | # as it was when instance m= was the highest (the header Recipes above it | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # applied), each as Email::Simple's header_raw gives it; undef if a header | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # Recipe on the way down does not undo. Bottom up, as Recipes number them. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1184 | ▶ | sub values_at { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values_at: called CC=6 SCAR=23.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | my ($self, $m, $name) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values_at: not called CC=6 SCAR=23.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | my $inst = $self->{by_m}{0 + $m} or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | my $lists = $inst->{lists} or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $lc = lc $name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | my $raw = $self->{raw}{$lc} || []; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$self->{'raw'}{$lc} || []
$self->{'raw'}{$lc} || []
MC/DC100%1/1
$self->{'raw'}{$lc} || []
$self->{'raw'}{$lc}
MC/DC0%0/1
$self->{'raw'}{$lc} || []
$self->{'raw'}{$lc}
Truth table100%2/2
A
A= $self->{'raw'}{$lc}
Truth table0%0/2
A
A= $self->{'raw'}{$lc}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | return [ map { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my ($type, $s, $e) = @$_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | $type ? @{$self->{raw_literals}}[$s .. $e] : map { _value($raw->[$_ - 1]) } $s .. $e | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | } @{ $lists->{$lc} || [] } ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%2/4
$lists->{$lc} || []
$lists->{$lc} || []
MC/DC100%1/1
$lists->{$lc} || []
$lists->{$lc}
MC/DC0%0/1
$lists->{$lc} || []
$lists->{$lc}
Truth table100%2/2
A
A= $lists->{$lc}
Truth table0%0/2
A
A= $lists->{$lc}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 198 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||