| 1 | # This code is part of Perl distribution Mail-Message version 4.05. | ||||||||||||||||||||||||||||||||||||||||||||
| 2 | # The POD got stripped from this file by OODoc version 3.06. | ||||||||||||||||||||||||||||||||||||||||||||
| 3 | # For contributors see file ChangeLog. | ||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||
| 5 | # This software is copyright (c) 2001-2026 by Mark Overmeer. | ||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||||
| 9 | # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later | ||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | package Mail::Message::Field;{ | ||||||||||||||||||||||||||||||||||||||||||||
| 13 | 57 | our $VERSION = '4.05'; | |||||||||||||||||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 57 | ▶ | use parent 'Mail::Reporter'; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | 57 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 19 | 57 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 57 | ▶ | use Log::Report 'mail-message', import => [ qw/__x error info panic warning/ ]; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | 57 | ▶ | use Mail::Address (); | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 24 | 57 | ▶ | use IO::Handle (); | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 25 | 57 | ▶ | use Date::Format qw/strftime/; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 57 | ▶ | use Scalar::Util qw/blessed/; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 27 | 57 | ▶ | use Hash::Case::Preserve (); | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 57 | our %_structured; # not to be used directly: call isStructured! | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 57 | my $default_wrap_length = 78; | |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | use overload | ||||||||||||||||||||||||||||||||||||||||||||
| 34 | 883 | ▶ | qq("") => sub { $_[0]->unfoldedBody }, | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 15 | ▶ | '0+' => sub { $_[0]->toInt || 0 }, | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1303 | ▶ | bool => sub {1}, | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 238 | ▶ | cmp => sub { $_[0]->unfoldedBody cmp "$_[1]" }, | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 10 | ▶ | '<=>' => sub { $_[2] ? $_[1] <=> $_[0]->toInt : $_[0]->toInt <=> $_[1] }, | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 57 | fallback => 1; | |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | sub new(@) | ||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1078 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1078 | ▶ | if($class eq __PACKAGE__) # bootstrap | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 46 | 895 | { require Mail::Message::Field::Fast; | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 895 | return Mail::Message::Field::Fast->new(@_); | |||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 49 | 183 | $class->SUPER::new(@_); | |||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | # attempt to change the case of a tag to that required by RFC822. That | ||||||||||||||||||||||||||||||||||||||||||||
| 56 | # being all characters are lowercase except the first of each | ||||||||||||||||||||||||||||||||||||||||||||
| 57 | # word. Also if the word is an `acronym' then all characters are | ||||||||||||||||||||||||||||||||||||||||||||
| 58 | # uppercase. We, rather arbitrarily, decide that a word is an acronym | ||||||||||||||||||||||||||||||||||||||||||||
| 59 | # if it does not contain a vowel and isn't the well-known 'Cc' or | ||||||||||||||||||||||||||||||||||||||||||||
| 60 | # 'Bcc' headers. | ||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | 57 | my %wf_lookup = qw/mime MIME ldap LDAP soap SOAP swe SWE bcc Bcc cc Cc id ID/; | |||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | sub wellformedName(;$) | ||||||||||||||||||||||||||||||||||||||||||||
| 65 | 27 | ▶ | { my $thing = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wellformedName: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 27 | ▶ | my $name = @_ ? shift : $thing->name; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | join '-', | ||||||||||||||||||||||||||||||||||||||||||||
| 69 | 27 | ▶ | map { $wf_lookup{lc $_} || ( /[aeiouyAEIOUY]/ ? ucfirst lc : uc ) } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$wf_lookup{lc $_} || (/[aeiouyAEIOUY]/ ? ucfirst lc $_ : uc $_)
MC/DC0%0/2
$wf_lookup{lc $_} || (/[aeiouyAEIOUY]/ ? ucfirst lc $_ : uc $_)
$wf_lookup{lc $_}
(/[aeiouyAEIOUY]/ ? ucfirst lc $_ : uc $_)
Truth table66%2/3
A || B
A= $wf_lookup{lc $_}B= (/[aeiouyAEIOUY]/ ? ucfirst lc $_ : uc $_)
| |||||||||||||||||||||||||||||||||||||||||||||
| 70 | split /\-/, $name, -1; | ||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub folded { $_[0]->notImplemented } | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
folded: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | sub body() | ||||||||||||||||||||||||||||||||||||||||||||
| 78 | 786 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
body: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 786 | my $body = $self->unfoldedBody; | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 786 | ▶ | $self->isStructured or return $body; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 565 | my ($first) = $body =~ m/^((?:"[^"]*"|'[^']*'|[^;])*)/; | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 565 | $first =~ s/\s+$//r; | |||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub foldedBody { $_[0]->notImplemented } | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
foldedBody: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub unfoldedBody { $_[0]->notImplemented } | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unfoldedBody: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 172 | ▶ | sub length { length $_[0]->folded } | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
length: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 57 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 57 | %_structured = map +(lc($_) => 1), qw/ | |||||||||||||||||||||||||||||||||||||||||||
| 99 | To Cc Bcc From Date Reply-To Sender | ||||||||||||||||||||||||||||||||||||||||||||
| 100 | Resent-Date Resent-From Resent-Sender Resent-To Return-Path | ||||||||||||||||||||||||||||||||||||||||||||
| 101 | List-Help List-Post List-Unsubscribe Mailing-List | ||||||||||||||||||||||||||||||||||||||||||||
| 102 | Received References Message-ID In-Reply-To Delivered-To | ||||||||||||||||||||||||||||||||||||||||||||
| 103 | Content-Type Content-Disposition Content-ID | ||||||||||||||||||||||||||||||||||||||||||||
| 104 | MIME-Version Precedence Status | ||||||||||||||||||||||||||||||||||||||||||||
| 105 | /; | ||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | sub isStructured(;$) | ||||||||||||||||||||||||||||||||||||||||||||
| 109 | 828 | ▶ | { my $name = $_[1] // (blessed $_[0] ? $_[0]->name : panic); | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isStructured: called CC=3 SCAR=13.1
Pod
documented
Branch: 1 branch
Condition33%1/3
$_[1] // (builtin::blessed($_[0]) ? $_[0]->name : &panic())
MC/DC0%0/2
$_[1] // (builtin::blessed($_[0]) ? $_[0]->name : &panic())
$_[1]
(builtin::blessed($_[0]) ? $_[0]->name : &panic())
Truth table33%1/3
A // B
A= $_[1]B= (builtin::blessed($_[0]) ? $_[0]->name : &panic())
| |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 828 | exists $_structured{lc $name}; | |||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | sub print(;$) | ||||||||||||||||||||||||||||||||||||||||||||
| 115 | 21 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 116 | 21 | ▶ | my $fh = shift || select; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || select()
MC/DC0%0/2
shift() || select()
shift()
select()
Truth table33%1/3
A || B
A= shift()B= select()
| |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 21 | $fh->print(scalar $self->folded); | |||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | 27 | ▶ | sub toString(;$) { shift->string(@_) } | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
toString: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | sub string(;$) | ||||||||||||||||||||||||||||||||||||||||||||
| 124 | 93 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
string: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 125 | 93 | ▶ | return $self->folded unless @_; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 5 | ▶ | my $wrap = shift || $default_wrap_length; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || $default_wrap_length
MC/DC0%0/2
shift() || $default_wrap_length
shift()
$default_wrap_length
Truth table33%1/3
A || B
A= shift()B= $default_wrap_length
| |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 5 | my $name = $self->Name; | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 5 | my @lines = $self->fold($name, $self->unfoldedBody, $wrap); | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 5 | $lines[0] = $name . ':' . $lines[0]; | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 5 | ▶ | wantarray ? @lines : join('', @lines); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | sub toDisclose() | ||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | { $_[0]->name !~ m! ^ | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
toDisclose: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 137 | (?: (?:x-)?status | ||||||||||||||||||||||||||||||||||||||||||||
| 138 | | (?:resent-)?bcc | ||||||||||||||||||||||||||||||||||||||||||||
| 139 | | content-length | ||||||||||||||||||||||||||||||||||||||||||||
| 140 | | x-spam- | ||||||||||||||||||||||||||||||||||||||||||||
| 141 | ) $ !x; | ||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | 135 | ▶ | sub nrLines() { my @l = $_[0]->foldedBody; scalar @l } | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nrLines: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | 57 | *size = \&length; | |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | sub stripCFWS($) | ||||||||||||||||||||||||||||||||||||||||||||
| 153 | 55 | ▶ | { my $thing = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stripCFWS: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | # get (folded) data | ||||||||||||||||||||||||||||||||||||||||||||
| 156 | 55 | ▶ | my $string = @_ ? shift : $thing->foldedBody; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | # remove comments | ||||||||||||||||||||||||||||||||||||||||||||
| 159 | 55 | my $r = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 55 | my $in_dquotes = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 55 | my $open_paren = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | 55 | my @s = split m/([()"])/, $string; | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 55 | ▶ | while(@s) | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 165 | 472 | { my $s = shift @s; | |||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | 472 | ▶ | if(CORE::length($r)&& substr($r, -1) eq "\\") { $r .= $s } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition100%3/3
CORE::length $r and substr($r, -1) eq "\\"
MC/DC100%2/2
CORE::length $r and substr($r, -1) eq "\\"
CORE::length $r
substr($r, -1) eq "\\"
Truth table100%3/3
A and B
A= CORE::length $rB= substr($r, -1) eq "\\"
| |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 40 | elsif($s eq '"') { $in_dquotes = not $in_dquotes; $r .= $s } | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 80 | ▶ | elsif($s eq '(' && !$in_dquotes) { $open_paren++ } | ||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$s eq "(" and not $in_dquotes
MC/DC100%2/2
$s eq "(" and not $in_dquotes
$s eq "("
not $in_dquotes
Truth table100%3/3
A and not(B)
A= $s eq "("B= not $in_dquotes
| |||||||||||||||||||||||||||||||||||||||||||||
| 170 | 80 | ▶ | elsif($s eq ')' && !$in_dquotes) { $open_paren-- } | ||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$s eq ")" and not $in_dquotes
MC/DC100%2/2
$s eq ")" and not $in_dquotes
$s eq ")"
not $in_dquotes
Truth table100%3/3
A and not(B)
A= $s eq ")"B= not $in_dquotes
| |||||||||||||||||||||||||||||||||||||||||||||
| 171 | elsif($open_paren) {} # in comment | ||||||||||||||||||||||||||||||||||||||||||||
| 172 | 156 | else { $r .= $s } | |||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | # beautify and unfold at the same time | ||||||||||||||||||||||||||||||||||||||||||||
| 176 | 55 | $r =~ s/\s+/ /grs =~ s/\s+$//r =~ s/^\s+//r; | |||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | sub comment(;$) | ||||||||||||||||||||||||||||||||||||||||||||
| 181 | 41 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
comment: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 182 | 41 | ▶ | $self->isStructured or return undef; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | 37 | my $body = $self->unfoldedBody; | |||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | 37 | ▶ | if(@_) | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 2 | { my $comment = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | $body =~ s/\s*\;.*//; | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | ▶ | $body .= "; $comment" if defined $comment && CORE::length($comment); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $comment and CORE::length $comment
MC/DC0%0/2
defined $comment and CORE::length $comment
defined $comment
CORE::length $comment
Truth table33%1/3
A and B
A= defined $commentB= CORE::length $comment
| |||||||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | $self->unfoldedBody($body); | |||||||||||||||||||||||||||||||||||||||||||
| 191 | 2 | return $comment; | |||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | 35 | ▶ | $body =~ s/.*?\;\s*// ? $body : ''; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | 10 | ▶ | sub content() { shift->unfoldedBody } # Compatibility | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||
| 200 | sub attribute($;$) | ||||||||||||||||||||||||||||||||||||||||||||
| 201 | 477 | ▶ | { my ($self, $attr) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attribute: called CC=8 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | # Although each attribute can appear only once, some (intentionally) | ||||||||||||||||||||||||||||||||||||||||||||
| 204 | # broken messages do repeat them. See github issue 20. Apple Mail and | ||||||||||||||||||||||||||||||||||||||||||||
| 205 | # Outlook will take the last of the repeated in such case, so we do that | ||||||||||||||||||||||||||||||||||||||||||||
| 206 | # as well. | ||||||||||||||||||||||||||||||||||||||||||||
| 207 | 477 | tie my %attrs, 'Hash::Case::Preserve', [ $self->attributes ]; | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 477 | ▶ | @_ or return $attrs{$attr}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | # set the value | ||||||||||||||||||||||||||||||||||||||||||||
| 211 | 153 | my $value = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 153 | my $body = $self->unfoldedBody; | |||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | 153 | ▶ | unless(defined $value) # remove attribute | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | { for($body) | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | { s/\b$attr\s*=\s*"(?>[^\\"]|\\.)*"//i or s/\b$attr\s*=\s*[;\s]*//i; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $self->unfoldedBody($body); | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||
| 222 | 153 | my $quoted = $value =~ s/(["\\])/\\$1/gr; | |||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | 153 | for($body) | |||||||||||||||||||||||||||||||||||||||||||
| 225 | { s/\b$attr\s*=\s*"(?>[^\\"]|\\.){0,1000}"/$attr="$quoted"/i | ||||||||||||||||||||||||||||||||||||||||||||
| 226 | or s/\b$attr\s*=\s*[^;\s]*/$attr="$quoted"/i | ||||||||||||||||||||||||||||||||||||||||||||
| 227 | 153 | ▶ | or do { $_ .= qq(; $attr="$quoted") } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
s/\b$attr\s*=\s*"(?>[^\\"]|\\.){0,1000}"/$attr="$quoted"/i or s/\b$attr\s*=\s*[^;\s]*/$attr="$quoted"/i
MC/DC100%2/2
s/\b$attr\s*=\s*"(?>[^\\"]|\\.){0,1000}"/$attr="$quoted"/i or s/\b$attr\s*=\s*[^;\s]*/$attr="$quoted"/i
s/\b$attr\s*=\s*"(?>[^\\"]|\\.){0,1000}"/$attr="$quoted"/i
s/\b$attr\s*=\s*[^;\s]*/$attr="$quoted"/i
Truth table100%3/3
A or B
A= s/\b$attr\s*=\s*"(?>[^\\"]|\\.){0,1000}"/$attr="$quoted"/iB= s/\b$attr\s*=\s*[^;\s]*/$attr="$quoted"/i
| |||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | 153 | $self->unfoldedBody($body); | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 153 | $value; | |||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | sub attributes() | ||||||||||||||||||||||||||||||||||||||||||||
| 236 | 479 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attributes: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 237 | 479 | my $body = $self->unfoldedBody; | |||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||
| 239 | 479 | my @attrs; | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 479 | ▶ | while($body =~ m/ \b(\w+)\s*\=\s* ( "( (?: [^"]|\\" )* )" | '( (?: [^']|\\' )* )' | ([^;\s]*) ) /xig) | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 241 | 246 | { push @attrs, $1 => $+; | |||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | 479 | @attrs; | |||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||
| 248 | sub toInt() | ||||||||||||||||||||||||||||||||||||||||||||
| 249 | 25 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
toInt: called CC=2 SCAR=9.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 250 | 25 | ▶ | $self->body =~ m/^\s*(\d+)\s*$/ | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 251 | and return $1; | ||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | warning __x"field content is not numerical: {content}", content => $self->toString; | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | undef; | |||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | 57 | my @weekday = qw/Sun Mon Tue Wed Thu Fri Sat Sun/; | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 57 | my @month = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/; | |||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||
| 261 | sub toDate(@) | ||||||||||||||||||||||||||||||||||||||||||||
| 262 | 16 | ▶ | { my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
toDate: called CC=3 SCAR=12.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 263 | 16 | ▶ | my @time = @_== 0 ? localtime() : @_==1 ? localtime(shift) : @_; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 264 | 16 | my $format = "$weekday[$time[6]], %d $month[$time[4]] %Y %H:%M:%S %z"; | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 16 | my $time = strftime $format, @time; | |||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | # for C libs which do not (GNU compliantly) support %z | ||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $time =~ s/ (\%z|[A-Za-z ]+)$/_tz_offset($1)/re; | |||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | sub _tz_offset($) | ||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | { my $zone = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tz_offset: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | require Time::Zone; | |||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | my $diff = $zone eq '%z' ? Time::Zone::tz_local_offset() : Time::Zone::tz_offset($zone); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | my $minutes = int((abs($diff)+0.01) / 60); # float rounding errors | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | my $hours = int(($minutes+0.01) / 60); | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $minutes -= $hours * 60; | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | sprintf +($diff < 0 ? " -%02d%02d" : " +%02d%02d"), $hours, $minutes; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||
| 283 | 18 | ▶ | sub addresses() { Mail::Address->parse(shift->unfoldedBody) } | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addresses: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||
| 286 | sub study() | ||||||||||||||||||||||||||||||||||||||||||||
| 287 | 93 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
study: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 288 | 93 | require Mail::Message::Field::Full; | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 93 | Mail::Message::Field::Full->new(scalar $self->folded); | |||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||
| 293 | sub dateToTimestamp($) | ||||||||||||||||||||||||||||||||||||||||||||
| 294 | 1 | ▶ | { my $string = $_[0]->stripCFWS($_[1]); | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dateToTimestamp: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||
| 296 | # in RFC822, FWSes can appear within the time. | ||||||||||||||||||||||||||||||||||||||||||||
| 297 | 1 | $string =~ s/(\d\d)\s*\:\s*(\d\d)\s*\:\s*(\d\d)/$1:$2:$3/; | |||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||
| 299 | 1 | require Date::Parse; | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | Date::Parse::str2time($string, 'GMT'); | |||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||
| 305 | sub consume($;$) | ||||||||||||||||||||||||||||||||||||||||||||
| 306 | 1977 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
consume: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1977 | ▶ | my ($name, $body) = defined $_[1] ? @_ : split(/\s*\:\s*/, (shift), 2); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||
| 309 | 1977 | ▶ | $name !~ m/[^\041-\071\073-\176]/ | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 310 | or warning __x"illegal character in field name '{name}'.", name => $name; | ||||||||||||||||||||||||||||||||||||||||||||
| 311 | 1977 | ▶ | panic $name if $name =~ m/[^\041-\071\073-\176]/; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | # | ||||||||||||||||||||||||||||||||||||||||||||
| 314 | # Compose the body. | ||||||||||||||||||||||||||||||||||||||||||||
| 315 | # | ||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1977 | ▶ | if(ref $body) # Objects or array | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 318 | 28 | ▶ | { my $flat = $self->stringifyData($body) // return (); | ||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->stringifyData($body) // (return ())
MC/DC0%0/1
$self->stringifyData($body) // (return ())
$self->stringifyData($body)
Truth table50%1/2
A
A= $self->stringifyData($body)
| |||||||||||||||||||||||||||||||||||||||||||||
| 319 | 28 | $body = $self->fold($name, $flat); | |||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 321 | elsif($body !~ s/\n+$/\n/g) # Added by user... | ||||||||||||||||||||||||||||||||||||||||||||
| 322 | 1144 | { $body = $self->fold($name, $body); | |||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 324 | else # Created by parser | ||||||||||||||||||||||||||||||||||||||||||||
| 325 | { # correct erroneous wrap-seperators (dos files under UNIX) | ||||||||||||||||||||||||||||||||||||||||||||
| 326 | 805 | $body =~ s/[\012\015]+/\n/g; | |||||||||||||||||||||||||||||||||||||||||||
| 327 | 805 | $body =~ s/^[ \t]*/ /; # start with one blank, folding kept unchanged | |||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1977 | ($name, $body); | |||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||
| 334 | sub stringifyData($) | ||||||||||||||||||||||||||||||||||||||||||||
| 335 | 28 | ▶ | { my ($self, $arg) = (shift, shift); | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringifyData: called CC=13 SCAR=26.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 336 | 28 | my @addr; | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 28 | ▶ | foreach my $obj (ref $arg eq 'ARRAY' ? @$arg : ($arg)) | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 338 | 33 | ▶ | { defined $obj or next; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | 33 | ▶ | if(!ref $obj) { push @addr, $obj; next } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 341 | 32 | ▶ | if($obj->isa('Mail::Address')) { push @addr, $obj->format; next } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||
| 343 | 13 | ▶ | if($obj->isa('Mail::Identity') || $obj->isa('User::Identity')) | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$obj->isa("Mail::Identity") or $obj->isa("User::Identity")
MC/DC100%2/2
$obj->isa("Mail::Identity") or $obj->isa("User::Identity")
$obj->isa("Mail::Identity")
$obj->isa("User::Identity")
Truth table100%3/3
A or B
A= $obj->isa("Mail::Identity")B= $obj->isa("User::Identity")
| |||||||||||||||||||||||||||||||||||||||||||||
| 344 | 7 | { require Mail::Message::Field::Address; | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 7 | push @addr, Mail::Message::Field::Address->coerce($obj)->string; | |||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 347 | elsif($obj->isa('User::Identity::Collection::Emails')) | ||||||||||||||||||||||||||||||||||||||||||||
| 348 | 1 | ▶ | { my @roles = $obj->roles or next; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 349 | 1 | require Mail::Message::Field::AddrGroup; | |||||||||||||||||||||||||||||||||||||||||||
| 350 | 1 | my $group = Mail::Message::Field::AddrGroup->coerce($obj); | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 1 | ▶ | push @addr, $group->string if $group; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 353 | elsif($obj->isa('Mail::Message::Field')) | ||||||||||||||||||||||||||||||||||||||||||||
| 354 | 5 | { my $folded = join ' ', $obj->foldedBody; | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 5 | push @addr, $folded =~ s/^ //r =~ s/\n\z//r; | |||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 357 | else | ||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | { push @addr, "$obj"; # any other object is stringified | |||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||
| 362 | 28 | ▶ | @addr ? join(', ',@addr) : undef; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||
| 366 | sub setWrapLength(;$) | ||||||||||||||||||||||||||||||||||||||||||||
| 367 | 368 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setWrapLength: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||
| 369 | 368 | ▶ | $self->foldedBody(scalar $self->fold($self->Name, $self->unfoldedBody, $_[0])) | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 370 | if @_; | ||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||
| 372 | 368 | $self; | |||||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||
| 376 | sub defaultWrapLength(;$) | ||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
defaultWrapLength: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | @_ ? ($default_wrap_length = shift) : $default_wrap_length; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||
| 382 | sub fold($$;$) | ||||||||||||||||||||||||||||||||||||||||||||
| 383 | 1443 | ▶ | { my $thing = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fold: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 384 | 1443 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 1443 | my $line = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 1443 | ▶ | my $wrap = shift || $default_wrap_length; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
shift() || $default_wrap_length
MC/DC0%0/2
shift() || $default_wrap_length
shift()
$default_wrap_length
Truth table66%2/3
A || B
A= shift()B= $default_wrap_length
| |||||||||||||||||||||||||||||||||||||||||||||
| 387 | 1443 | ▶ | $line //= ''; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$line //= ""
MC/DC100%1/1
$line //= ""
$line
Truth table100%2/2
A
A= $line
| |||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||
| 389 | 1443 | $line =~ s/\n(\s?)/$1/gms; # Remove accidental folding | |||||||||||||||||||||||||||||||||||||||||||
| 390 | 1443 | ▶ | CORE::length($line) or return " \n"; # empty field | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||
| 392 | 1440 | my $lname = CORE::length($name); | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 1440 | ▶ | $lname <= $wrap -5 # Cannot find a real limit in the spec | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 394 | or error __x"field name too long (max {count}), in '{name}'.", count => $wrap - 5, name => $name; | ||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||
| 396 | 1440 | my @folded; | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 1440 | while(1) | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 1495 | ▶ | { my $max = $wrap - (@folded ? 1 : $lname + 2); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 399 | 1495 | my $min = $max >> 2; | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 1495 | ▶ | last if CORE::length($line) < $max; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||
| 402 | # First, with try to get a block which ends on a ; or , to keep attributes | ||||||||||||||||||||||||||||||||||||||||||||
| 403 | # on the same line. Only then we fold on any blank. | ||||||||||||||||||||||||||||||||||||||||||||
| 404 | 55 | ▶ | $line =~ s/^ ( .{$min,$max} # some text | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$line =~ s/^ ( .{$min,$max} # some text
[;,] # followed at a ; or ,
)[ \t] # and then a WSP
//x or $line =~ s/^ ( .{$min,$max} # some text
)[ \t] # and then a WSP
//x or $line =~ s/^ ( .{$max,}? ) # longer, but minimal chars
[ \t] # followed by a WSP
//x
$line =~ s/^ ( .{$min,$max} # some text
[;,] # followed at a ; or ,
)[ \t] # and then a WSP
//x or $line =~ s/^ ( .{$min,$max} # some text
)[ \t] # and then a WSP
//x
MC/DC100%3/3
$line =~ s/^ ( .{$min,$max} # some text
[;,] # followed at a ; or ,
)[ \t] # and then a WSP
//x or $line =~ s/^ ( .{$min,$max} # some text
)[ \t] # and then a WSP
//x or $line =~ s/^ ( .{$max,}? ) # longer, but minimal chars
[ \t] # followed by a WSP
//x
$line =~ s/^ ( .{$min,$max} # some text
[;,] # followed at a ; or ,
)[ \t] # and then a WSP
//x
$line =~ s/^ ( .{$min,$max} # some text
)[ \t] # and then a WSP
//x
$line =~ s/^ ( .{$max,}? ) # longer, but minimal chars
[ \t] # followed by a WSP
//x
Truth table100%4/4
A or B or C
A= $line =~ s/^ ( .{$min,$max} # some text
[;,] # followed at a ; or ,
)[ \t] # and then a WSP
//xB= $line =~ s/^ ( .{$min,$max} # some text
)[ \t] # and then a WSP
//xC= $line =~ s/^ ( .{$max,}? ) # longer, but minimal chars
[ \t] # followed by a WSP
//x
| |||||||||||||||||||||||||||||||||||||||||||||
| 405 | [;,] # followed at a ; or , | ||||||||||||||||||||||||||||||||||||||||||||
| 406 | )[ \t] # and then a WSP | ||||||||||||||||||||||||||||||||||||||||||||
| 407 | //x | ||||||||||||||||||||||||||||||||||||||||||||
| 408 | || $line =~ s/^ ( .{$min,$max} # some text | ||||||||||||||||||||||||||||||||||||||||||||
| 409 | )[ \t] # and then a WSP | ||||||||||||||||||||||||||||||||||||||||||||
| 410 | //x | ||||||||||||||||||||||||||||||||||||||||||||
| 411 | || $line =~ s/^ ( .{$max,}? ) # longer, but minimal chars | ||||||||||||||||||||||||||||||||||||||||||||
| 412 | [ \t] # followed by a WSP | ||||||||||||||||||||||||||||||||||||||||||||
| 413 | //x | ||||||||||||||||||||||||||||||||||||||||||||
| 414 | || $line =~ s/^ (.*) //sx; # everything | ||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||
| 416 | 55 | push @folded, " $1\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1440 | ▶ | push @folded, " $line\n" if CORE::length($line); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1440 | ▶ | wantarray ? @folded : join('', @folded); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||
| 424 | sub unfold($) | ||||||||||||||||||||||||||||||||||||||||||||
| 425 | 2897 | ▶ | { my $string = $_[1]; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unfold: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 426 | 2897 | for($string) | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 2897 | { s/\r?\n(\s)/$1/gs; # remove FWS | |||||||||||||||||||||||||||||||||||||||||||
| 428 | 2897 | s/\r?\n/ /gs; | |||||||||||||||||||||||||||||||||||||||||||
| 429 | 2897 | s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||
| 430 | 2897 | s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 432 | 2897 | $string; | |||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||
| 435 | #-------------------- | ||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||
| 437 | 57 | 1; | |||||||||||||||||||||||||||||||||||||||||||