| 1 | # Copyrights 1995-2024 by [Mark Overmeer <markov@cpan.org>]. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.03. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # This code is part of the bundle MailTools. Meta-POD processed with | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # OODoc into POD and HTML manual-pages. See README.md for Copyright. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Licensed under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | package Mail::Header;{ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | our $VERSION = '2.22'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | my $MAIL_FROM = 'KEEP'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | my %HDR_LENGTHS = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | our $FIELD_NAME = '[^\x00-\x1f\x7f-\xff :]+:'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ## Private functions | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ## | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | sub _error { warn @_; () } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # tidy up internal hash table and list | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | sub _tidy_header | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tidy_header: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my $deleted = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | for(my $i = 0 ; $i < @{$self->{mail_hdr_list}}; $i++) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | { next if defined $self->{mail_hdr_list}[$i]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | splice @{$self->{mail_hdr_list}}, $i, 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $deleted++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $i--; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if($deleted) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | { local $_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my @del; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | while(my ($key,$ref) = each %{$self->{mail_hdr_hash}} ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | { push @del, $key | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | unless @$ref = grep { ref $_ && defined $$_ } @$ref; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $_ && defined $$_
MC/DC0%0/2
ref $_ && defined $$_
ref $_
defined $$_
Truth table0%0/3
A && B
A= ref $_B= defined $$_
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | delete $self->{'mail_hdr_hash'}{$_} for @del; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # fold the line to the given length | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | my %STRUCTURE = map { (lc $_ => undef) } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | qw{ To Cc Bcc From Date Reply-To Sender | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | Resent-Date Resent-From Resent-Sender Resent-To Return-Path | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | list-help list-post list-unsubscribe Mailing-List | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | Received References Message-ID In-Reply-To | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | Content-Length Content-Type Content-Disposition | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | Delivered-To | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | Lines | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | MIME-Version | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | Precedence | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | Status | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | sub _fold_line | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 27 | ▶ | { my($ln,$maxlen) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fold_line: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 27 | ▶ | $maxlen = 20 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | if $maxlen < 20; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 27 | my $max = int($maxlen - 5); # 4 for leading spcs + 1 for [\,\;] | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 27 | my $min = int($maxlen * 4 / 5) - 4; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 27 | $_[0] =~ s/[\r\n]+//og; # Remove new-lines | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 27 | $_[0] =~ s/\s*\Z/\n/so; # End line with an EOLN | |||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 27 | ▶ | return if $_[0] =~ /^From\s/io; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 27 | ▶ | if(length($_[0]) > $maxlen) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 14 | ▶ | { if($_[0] =~ /^([-\w]+)/ && exists $STRUCTURE{ lc $1 } ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_[0] =~ /^([-\w]+)/ and exists $STRUCTURE{lc $1}
MC/DC50%1/2
$_[0] =~ /^([-\w]+)/ and exists $STRUCTURE{lc $1}
$_[0] =~ /^([-\w]+)/
exists $STRUCTURE{lc $1}
Truth table66%2/3
A and B
A= $_[0] =~ /^([-\w]+)/B= exists $STRUCTURE{lc $1}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | { #Split the line up | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # first bias towards splitting at a , or a ; >4/5 along the line | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # next split a whitespace | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # else we are looking at a single word and probably don't want to split | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 9 | my $x = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 9 | ▶ | $x .= "$1\n " while $_[0] =~ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | s/^\s* | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | ( [^"]{$min,$max} [,;] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | | [^"]{1,$max} [,;\s] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | | [^\s"]*(?:"[^"]*"[ \t]?[^\s"]*)+\s | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | ) //x; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 9 | $x .= $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 9 | $_[0] = $x; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 9 | $_[0] =~ s/(\A\s+|[\t ]+\Z)//sog; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 9 | $_[0] =~ s/\s+\n/\n/sog; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 5 | { $_[0] =~ s/(.{$min,$max})(\s)/$1\n$2/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 5 | $_[0] =~ s/\s*$/\n/s; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 27 | $_[0] =~ s/\A(\S+)\n\s*(?=\S)/$1 /so; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # Tags are case-insensitive, but there is a (slightly) preferred construction | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # being all characters are lowercase except the first of each word. Also | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # if the word is an `acronym' then all characters are uppercase. We decide | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # a word is an acronym if it does not contain a vowel. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # In general, this change of capitalization is a bad idea, but it is in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # the code for ages, and therefore probably crucial for existing | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # applications. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | sub _tag_case | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 61 | ▶ | { my $tag = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tag_case: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 61 | $tag =~ s/\:$//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | join '-' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 61 | ▶ | , map { /^[b-df-hj-np-tv-z]+$|^(?:MIME|SWE|SOAP|LDAP|ID)$/i | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | ? uc($_) : ucfirst(lc($_)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } split m/\-/, $tag, -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # format a complete line | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # ensure line starts with the given tag | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # ensure tag is correct case | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # change the 'From ' tag as required | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # fold the line | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | sub _fmt_line | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 25 | ▶ | { my ($self, $tag, $line, $modify) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_fmt_line: called CC=22 SCAR=38.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 25 | ▶ | $modify ||= $self->{mail_hdr_modify}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$modify ||= $self->{"mail_hdr_modify"}
MC/DC50%1/2
$modify ||= $self->{"mail_hdr_modify"}
$modify
$self->{"mail_hdr_modify"}
Truth table66%2/3
A ||= B
A= $modifyB= $self->{"mail_hdr_modify"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 25 | my $ctag = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 25 | ▶ | ($tag) = $line =~ /^($FIELD_NAME|From )/oi | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | unless defined $tag; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 25 | ▶ | if(defined $tag && $tag =~ /^From /io && $self->{mail_hdr_mail_from} ne 'KEEP') | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $tag and $tag =~ /^From /io and $self->{"mail_hdr_mail_from"} ne "KEEP"
defined $tag and $tag =~ /^From /io
MC/DC0%0/3
defined $tag and $tag =~ /^From /io and $self->{"mail_hdr_mail_from"} ne "KEEP"
defined $tag
$tag =~ /^From /io
$self->{"mail_hdr_mail_from"} ne "KEEP"
Truth table50%2/4
A and B and C
A= defined $tagB= $tag =~ /^From /ioC= $self->{"mail_hdr_mail_from"} ne "KEEP"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | { if($self->{mail_hdr_mail_from} eq 'COERCE') | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | { $line =~ s/^From /Mail-From: /o; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $tag = "Mail-From:"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | elsif($self->{mail_hdr_mail_from} eq 'IGNORE') | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | { return (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | elsif($self->{mail_hdr_mail_from} eq 'ERROR') | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | { return _error "unadorned 'From ' ignored: <$line>"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 25 | ▶ | if(defined $tag) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 25 | { $tag = _tag_case($ctag = $tag); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 25 | ▶ | $ctag = $tag if $modify; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 25 | ▶ | $ctag =~ s/([^ :])$/$1:/o if defined $ctag; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 25 | ▶ | defined $ctag && $ctag =~ /^($FIELD_NAME|From )/oi | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $ctag and $ctag =~ /^($Mail::Header::FIELD_NAME|From )/io
MC/DC0%0/2
defined $ctag and $ctag =~ /^($Mail::Header::FIELD_NAME|From )/io
defined $ctag
$ctag =~ /^($Mail::Header::FIELD_NAME|From )/io
Truth table33%1/3
A and B
A= defined $ctagB= $ctag =~ /^($Mail::Header::FIELD_NAME|From )/io
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | or croak "Bad RFC822 field name '$tag'\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # Ensure the line starts with tag | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 25 | ▶ | if(defined $ctag && ($modify || $line !~ /^\Q$ctag\E/i)) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $ctag and $modify || !($line =~ /^\Q$ctag\E/i)
$modify or not $line =~ /^\Q$ctag\E/i
MC/DC66%2/3
defined $ctag and $modify || !($line =~ /^\Q$ctag\E/i)
defined $ctag
$modify
not $line =~ /^\Q$ctag\E/i
Truth table75%3/4
A and B or not(C)
A= defined $ctagB= $modifyC= not $line =~ /^\Q$ctag\E/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 15 | { (my $xtag = $ctag) =~ s/\s*\Z//o; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 15 | $line =~ s/^(\Q$ctag\E)?\s*/$xtag /i; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | my $maxlen = $self->{mail_hdr_lengths}{$tag} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 25 | ▶ | || $HDR_LENGTHS{$tag} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$self->{'mail_hdr_lengths'}{$tag} || $HDR_LENGTHS{$tag} || $self->fold_length
$self->{"mail_hdr_lengths"}{$tag} or $HDR_LENGTHS{$tag}
MC/DC0%0/3
$self->{'mail_hdr_lengths'}{$tag} || $HDR_LENGTHS{$tag} || $self->fold_length
$self->{"mail_hdr_lengths"}{$tag}
$HDR_LENGTHS{$tag}
$self->fold_length
Truth table25%1/4
A or B || C
A= $self->{"mail_hdr_lengths"}{$tag}B= $HDR_LENGTHS{$tag}C= $self->fold_length
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | || $self->fold_length; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 25 | ▶ | if ($modify && defined $maxlen) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$modify and defined $maxlen
MC/DC50%1/2
$modify and defined $maxlen
$modify
defined $maxlen
Truth table66%2/3
A and B
A= $modifyB= defined $maxlen
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | { # folding will fix bad header continuations for us | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 9 | _fold_line $line, $maxlen; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | elsif($line =~ /\r?\n\S/) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | { return _error "Bad header continuation, skipping '$tag': ", | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | "no space after newline in '$line'\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 24 | $line =~ s/\n*$/\n/so; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 24 | ($tag, $line); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | sub _insert | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 24 | ▶ | { my ($self, $tag, $line, $where) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_insert: called CC=11 SCAR=30.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 24 | ▶ | if($where < 0) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 24 | { $where = @{$self->{mail_hdr_list}} + $where + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 24 | ▶ | $where = 0 if $where < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | elsif($where >= @{$self->{mail_hdr_list}}) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | { $where = @{$self->{mail_hdr_list}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 24 | my $atend = $where == @{$self->{mail_hdr_list}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 24 | splice @{$self->{mail_hdr_list}}, $where, 0, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 24 | ▶ | $self->{mail_hdr_hash}{$tag} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"mail_hdr_hash"}{$tag} ||= []
MC/DC100%1/1
$self->{"mail_hdr_hash"}{$tag} ||= []
$self->{"mail_hdr_hash"}{$tag}
Truth table100%2/2
A
A= $self->{"mail_hdr_hash"}{$tag}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 24 | my $ref = \${$self->{mail_hdr_list}}[$where]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 24 | my $def = $self->{mail_hdr_hash}{$tag}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 24 | ▶ | if($def && $where) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$def and $where
MC/DC50%1/2
$def and $where
$def
$where
Truth table66%2/3
A and B
A= $defB= $where
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 18 | ▶ | { if($atend) { push @$def, $ref } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | { my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | foreach my $ln (@{$self->{mail_hdr_list}}) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | { my $r = \$ln; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | last if $r == $ref; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | $i++ if $r == $def->[$i]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | splice @$def, $i, 0, $ref; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 6 | { unshift @$def, $ref; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | #------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 11 | ▶ | { my $call = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=25.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 11 | ▶ | my $class = ref($call) || $call; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $call || $call
MC/DC0%0/2
ref $call || $call
ref $call
$call
Truth table33%1/3
A || B
A= ref $callB= $call
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 11 | ▶ | my $arg = @_ % 2 ? shift : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 11 | my %opt = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | $opt{Modify} = delete $opt{Reformat} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 11 | ▶ | unless exists $opt{Modify}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | my $self = bless | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | { mail_hdr_list => [] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | , mail_hdr_hash => {} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 11 | ▶ | , mail_hdr_modify => (delete $opt{Modify} || 0) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $opt{'Modify'} || 0
MC/DC100%1/1
delete $opt{'Modify'} || 0
delete $opt{'Modify'}
Truth table100%2/2
A
A= delete $opt{'Modify'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | , mail_hdr_foldlen => 79 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | , mail_hdr_lengths => {} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 11 | ▶ | $self->mail_from( uc($opt{MailFrom} || $MAIL_FROM) ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opt{'MailFrom'} || $MAIL_FROM
MC/DC0%0/2
$opt{'MailFrom'} || $MAIL_FROM
$opt{'MailFrom'}
$MAIL_FROM
Truth table33%1/3
A || B
A= $opt{'MailFrom'}B= $MAIL_FROM
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | $self->fold_length($opt{FoldLength}) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 11 | ▶ | if exists $opt{FoldLength}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 11 | ▶ | if(!ref $arg) {} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 5 | elsif(ref($arg) eq 'ARRAY') { $self->extract( [ @$arg ] ) } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | elsif(defined fileno($arg)) { $self->read($arg) } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 11 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | sub dup | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dup: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 2 | my $dup = ref($self)->new; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 2 | %$dup = %$self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 2 | $dup->empty; # rebuild tables | |||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 2 | $dup->{mail_hdr_list} = [ @{$self->{mail_hdr_list}} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 2 | foreach my $ln ( @{$dup->{mail_hdr_list}} ) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 8 | { my $tag = _tag_case +($ln =~ /^($FIELD_NAME|From )/oi)[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 8 | push @{$dup->{mail_hdr_hash}{$tag}}, \$ln; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 2 | $dup; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | #------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | sub extract | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 6 | ▶ | { my ($self, $lines) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extract: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 6 | $self->empty; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 6 | ▶ | while(@$lines) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 21 | { my $line = shift @$lines; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 21 | ▶ | last if $line =~ /^\r?$/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 19 | ▶ | $line =~ /^($FIELD_NAME|From )/o or next; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 19 | my $tag = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 19 | ▶ | $line .= shift @$lines | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@$lines and $lines->[0] =~ /^[ \t]+/
MC/DC100%2/2
@$lines and $lines->[0] =~ /^[ \t]+/
@$lines
$lines->[0] =~ /^[ \t]+/
Truth table100%3/3
A and B
A= @$linesB= $lines->[0] =~ /^[ \t]+/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | while @$lines && $lines->[0] =~ /^[ \t]+/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 19 | ($tag, $line) = _fmt_line $self, $tag, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 19 | ▶ | _insert $self, $tag, $line, -1 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | if defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 6 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | sub read | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | { my ($self, $fd) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $self->empty; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my ($ln, $tag, $line); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | while(1) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | { $ln = <$fd>; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | if(defined $ln && defined $line && $ln =~ /^[ \t]+/) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $ln and defined $line and $ln =~ /^[ \t]+/
defined $ln and defined $line
MC/DC0%0/3
defined $ln and defined $line and $ln =~ /^[ \t]+/
defined $ln
defined $line
$ln =~ /^[ \t]+/
Truth table0%0/4
A and B and C
A= defined $lnB= defined $lineC= $ln =~ /^[ \t]+/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | { $line .= $ln; # folded line | |||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | if(defined $line) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | { ($tag, $line) = _fmt_line $self, $tag, $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | _insert $self, $tag, $line, -1 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | if defined $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ($tag, $line) = (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | last if !defined $ln || $ln =~ m/^\r?$/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $ln or $ln =~ /^\r?$/
MC/DC0%0/2
not defined $ln or $ln =~ /^\r?$/
not defined $ln
$ln =~ /^\r?$/
Truth table0%0/3
not(A) or B
A= not defined $lnB= $ln =~ /^\r?$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | $ln =~ /^($FIELD_NAME|From )/o or next; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ($tag, $line) = ($1, $ln); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | sub empty | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 8 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
empty: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 8 | $self->{mail_hdr_list} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 8 | $self->{mail_hdr_hash} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 8 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | sub header | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 1 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 1 | ▶ | $self->extract(@_) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | $self->fold | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 1 | ▶ | if $self->{mail_hdr_modify}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 1 | [ @{$self->{mail_hdr_list}} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | sub header_hashref | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 2 | ▶ | { my ($self, $hashref) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
header_hashref: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 2 | ▶ | while(my ($key, $value) = each %$hashref) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 2 | ▶ | { $self->add($key, $_) for ref $value ? @$value : $value; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | $self->fold | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 2 | ▶ | if $self->{mail_hdr_modify}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | defined wantarray # MO, added minimal optimization | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 2 | ▶ | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 3 | +{ map { ($_ => [$self->get($_)] ) } # MO: Eh? | |||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 1 | keys %{$self->{mail_hdr_hash}} | |||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | #------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | sub modify | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 3 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
modify: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 3 | my $old = $self->{mail_hdr_modify}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 3 | ▶ | $self->{mail_hdr_modify} = 0 + shift | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 3 | $old; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | sub mail_from | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 11 | ▶ | { my $thing = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mail_from: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 11 | my $choice = uc shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 11 | ▶ | $choice =~ /^(IGNORE|ERROR|COERCE|KEEP)$/ | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | or die "bad Mail-From choice: '$choice'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 11 | ▶ | if(ref $thing) { $thing->{mail_hdr_mail_from} = $choice } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | else { $MAIL_FROM = $choice } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 11 | $thing; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | sub fold_length | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 28 | ▶ | { my $thing = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fold_length: called CC=7 SCAR=24.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 28 | my $old; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 28 | ▶ | if(@_ == 2) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | { my $tag = _tag_case shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | my $len = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | my $hash = ref $thing ? $thing->{mail_hdr_lengths} : \%HDR_LENGTHS; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $old = $hash->{$tag}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | ▶ | $hash->{$tag} = $len > 20 ? $len : 20; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 28 | { my $self = $thing; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 28 | my $len = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 28 | $old = $self->{mail_hdr_foldlen}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 28 | ▶ | if(defined $len) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 3 | ▶ | { $self->{mail_hdr_foldlen} = $len > 20 ? $len : 20; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 3 | ▶ | $self->fold if $self->{mail_hdr_modify}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 28 | $old; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | #------------ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | sub fold | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 3 | ▶ | { my ($self, $maxlen) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fold: called CC=7 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 3 | ▶ | while(my ($tag, $list) = each %{$self->{mail_hdr_hash}}) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | { my $len = $maxlen | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | || $self->{mail_hdr_lengths}{$tag} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 9 | ▶ | || $HDR_LENGTHS{$tag} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%3/9
$maxlen || $self->{'mail_hdr_lengths'}{$tag} || $HDR_LENGTHS{$tag} || $self->fold_length
$maxlen or $self->{"mail_hdr_lengths"}{$tag} or $HDR_LENGTHS{$tag}
$maxlen or $self->{"mail_hdr_lengths"}{$tag}
MC/DC0%0/4
$maxlen || $self->{'mail_hdr_lengths'}{$tag} || $HDR_LENGTHS{$tag} || $self->fold_length
$maxlen
$self->{"mail_hdr_lengths"}{$tag}
$HDR_LENGTHS{$tag}
$self->fold_length
Truth table20%1/5
A or B or C || D
A= $maxlenB= $self->{"mail_hdr_lengths"}{$tag}C= $HDR_LENGTHS{$tag}D= $self->fold_length
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | || $self->fold_length; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 9 | foreach my $ln (@$list) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 18 | ▶ | { _fold_line $$ln, $len | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | if defined $ln; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 3 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | sub unfold | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 1 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unfold: called CC=10 SCAR=33.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 1 | ▶ | if(@_) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | { my $tag = _tag_case shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | my $list = $self->{mail_hdr_hash}{$tag} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | or return $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | foreach my $ln (@$list) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | { $$ln =~ s/\r?\n\s+/ /sog | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ln and defined $$ln
MC/DC0%0/2
defined $ln and defined $$ln
defined $ln
defined $$ln
Truth table0%0/3
A and B
A= defined $lnB= defined $$ln
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | if defined $ln && defined $$ln; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 1 | ▶ | while( my ($tag, $list) = each %{$self->{mail_hdr_hash}}) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 3 | { foreach my $ln (@$list) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 6 | ▶ | { $$ln =~ s/\r?\n\s+/ /sog | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $ln and defined $$ln
MC/DC0%0/2
defined $ln and defined $$ln
defined $ln
defined $$ln
Truth table33%1/3
A and B
A= defined $lnB= defined $$ln
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | if defined $ln && defined $$ln; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 1 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | sub add | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 6 | ▶ | { my ($self, $tag, $text, $where) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=4 SCAR=14.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 6 | ($tag, my $line) = _fmt_line $self, $tag, $text; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 6 | ▶ | defined $tag && defined $line | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $tag and defined $line
MC/DC0%0/2
defined $tag and defined $line
defined $tag
defined $line
Truth table33%1/3
A and B
A= defined $tagB= defined $line
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 6 | ▶ | defined $where | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | or $where = -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 6 | _insert $self, $tag, $line, $where; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 6 | $line =~ /^\S+\s(.*)/os; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 6 | $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | sub replace | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replace: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | ▶ | my $idx = @_ % 2 ? pop @_ : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | my ($tag, $line); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | TAG: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | while(@_) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | { ($tag,$line) = _fmt_line $self, splice(@_,0,2); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | defined $tag && defined $line | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $tag and defined $line
MC/DC0%0/2
defined $tag and defined $line
defined $tag
defined $line
Truth table0%0/3
A and B
A= defined $tagB= defined $line
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | my $field = $self->{mail_hdr_hash}{$tag}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | if($field && defined $field->[$idx]) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$field and defined $field->[$idx]
MC/DC0%0/2
$field and defined $field->[$idx]
$field
defined $field->[$idx]
Truth table0%0/3
A and B
A= $fieldB= defined $field->[$idx]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | { ${$field->[$idx]} = $line } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | else { _insert $self, $tag, $line, -1 } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | $line =~ /^\S+\s*(.*)/os; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | sub combine | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
combine: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | my $tag = _tag_case shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | my $with = shift || ' '; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || ' '
MC/DC0%0/1
shift() || ' '
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | $tag =~ /^From /io && $self->{mail_hdr_mail_from} ne 'KEEP' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$tag =~ /^From /io and $self->{"mail_hdr_mail_from"} ne "KEEP"
MC/DC0%0/2
$tag =~ /^From /io and $self->{"mail_hdr_mail_from"} ne "KEEP"
$tag =~ /^From /io
$self->{"mail_hdr_mail_from"} ne "KEEP"
Truth table0%0/3
A and B
A= $tag =~ /^From /ioB= $self->{"mail_hdr_mail_from"} ne "KEEP"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | and return _error "unadorned 'From ' ignored"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | my $def = $self->{mail_hdr_hash}{$tag} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | ▶ | return $def->[0] | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | if @$def <= 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | my @lines = $self->get($tag); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | chomp @lines; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | my $line = (_fmt_line $self, $tag, join($with,@lines), 1)[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | $self->{mail_hdr_hash}{$tag} = [ \$line ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | sub get | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 26 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 26 | my $tag = _tag_case shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 26 | my $idx = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 26 | ▶ | my $def = $self->{mail_hdr_hash}{$tag} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | or return (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 23 | my $l = length $tag; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 23 | ▶ | $l += 1 if $tag !~ / $/o; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 23 | ▶ | if(defined $idx || !wantarray) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $idx or not wantarray
MC/DC100%2/2
defined $idx or not wantarray
defined $idx
not wantarray
Truth table100%3/3
A or not(B)
A= defined $idxB= not wantarray
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 20 | ▶ | { $idx ||= 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$idx ||= 0
MC/DC100%1/1
$idx ||= 0
$idx
Truth table100%2/2
A
A= $idx
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 20 | ▶ | defined $def->[$idx] or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 20 | my $val = ${$def->[$idx]}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 20 | ▶ | defined $val or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 20 | $val = substr $val, $l; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 20 | $val =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 20 | return $val; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 3 | map { my $tmp = substr $$_,$l; $tmp =~ s/^\s+//; $tmp } @$def; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | sub count | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
count: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 0 | my $tag = _tag_case shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | my $def = $self->{mail_hdr_hash}{$tag}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | defined $def ? scalar(@$def) : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | sub delete | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=5 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 2 | my $tag = _tag_case shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 2 | my $idx = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 2 | my @val; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 2 | ▶ | if(my $def = $self->{mail_hdr_hash}{$tag}) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | { my $l = length $tag; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | ▶ | $l += 2 if $tag !~ / $/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | ▶ | if(defined $idx) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | ▶ | { if(defined $def->[$idx]) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 0 | { push @val, substr ${$def->[$idx]}, $l; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | undef ${$def->[$idx]}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | { @val = map {my $x = substr $$_,$l; undef $$_; $x } @$def; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | _tidy_header($self); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 2 | @val; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | sub print | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 1 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 1 | ▶ | my $fd = shift || \*STDOUT; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || \*STDOUT
MC/DC0%0/1
shift() || \*STDOUT
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 1 | foreach my $ln (@{$self->{mail_hdr_list}}) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 6 | ▶ | { defined $ln or next; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 6 | ▶ | print $fd $ln or return 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 6 | ▶ | sub as_string { join '', grep {defined} @{shift->{mail_hdr_list}} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | ▶ | sub tags { keys %{shift->{mail_hdr_hash}} } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tags: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | sub cleanup | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cleanup: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | my $deleted = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 0 | ▶ | foreach my $key (@_ ? @_ : keys %{$self->{mail_hdr_hash}}) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | { my $fields = $self->{mail_hdr_hash}{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | foreach my $field (@$fields) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | { next if $$field =~ /^\S+\s+\S/s; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | undef $$field; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | $deleted++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | ▶ | _tidy_header $self | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | if $deleted; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||