Message/Field.pm

filter: Statementstmt 90.4% 199 / 220 Branchbran 78.0% 89 / 114 Conditioncond 78.7% 26 / 33 MC/DCmcdc 61.9% 13 / 21 Subroutinesub 86.6% 39 / 45 Podpod 96.5% 28 / 29 totaltotal 85.2% 394 / 462 CC 74 SCAR 18.8
CC
74
Cov
86%
stringifyData
13.4
stripCFWS
12.0
_tz_offset
12.0
CRAP 6.6
« Message/Convert/MimeEntity.pm ↑ Summary Box/FastScalar.pm »
1 # Copyrights 2001-2022 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 distribution Mail-Message. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package Mail::Message::Field;
10 50 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 50 $VERSION = '3.012';
12  
13 50 ▶use base 'Mail::Reporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 50 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 50 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 50 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 50 ▶use Mail::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 50 ▶use Date::Format 'strftime';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 50 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 50 our %_structured; # not to be used directly: call isStructured!
24 50 my $default_wrap_length = 78;
25  
26  
27 use overload
28 396 ▶ qq("") => sub { $_[0]->unfoldedBody }
Subroutine __ANON__: called CC=1 SCAR=0.0
29 2 ▶ , '0+' => sub { $_[0]->toInt || 0 }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->toInt or 0 0 2 2
30 2337 ▶ , bool => sub {1}
Subroutine __ANON__: called CC=1 SCAR=0.0
31 149 ▶ , cmp => sub { $_[0]->unfoldedBody cmp "$_[1]" }
Subroutine __ANON__: called CC=1 SCAR=0.0
32 10 ▶ , '<=>' => sub { $_[2] ? $_[1] <=> $_[0]->toInt : $_[0]->toInt <=> $_[1] }
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 4 6 10
33 50 ▶ , fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 #------------------------------------------
36  
37  
38 sub new(@)
39 630 ▶{ my $class = shift;
Subroutine new: called CC=2 SCAR=6.9
Pod documented
40 630 ▶ if($class eq __PACKAGE__) # bootstrap
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) 494 136 630
41 494 { require Mail::Message::Field::Fast;
42 494 return Mail::Message::Field::Fast->new(@_);
43 }
44 136 $class->SUPER::new(@_);
45 }
46  
47  
48  
49 #------------------------------------------
50  
51  
52 163 ▶sub length { length shift->folded }
Subroutine length: called CC=1 SCAR=0.0
Pod documented
53  
54  
55 BEGIN {
56 50 ▶%_structured = map { (lc($_) => 1) }
Subroutine BEGIN: called CC=1 SCAR=0.0
57 qw/To Cc Bcc From Date Reply-To Sender
58 Resent-Date Resent-From Resent-Sender Resent-To Return-Path
59 List-Help List-Post List-Unsubscribe Mailing-List
60 Received References Message-ID In-Reply-To
61 Content-Type Content-Disposition Content-ID
62 Delivered-To
63 MIME-Version
64 Precedence
65 Status/;
66 }
67  
68 sub isStructured(;$)
69 718 ▶{ my $name = ref $_[0] ? shift->name : $_[1];
Subroutine isStructured: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 718 0 718
70 718 exists $_structured{lc $name};
71 }
72  
73  
74 sub print(;$)
75 21 ▶{ my $self = shift;
Subroutine print: called CC=2 SCAR=7.6
Pod documented
76 21 ▶ my $fh = shift || select;
Condition33%1/3
shift() || select()
l!l&&r!l&&!r
2100
MC/DC0%0/2
shift() || select()
shift() select()
Truth table33%1/3
A || B
A= shift()B= select()
ABresult
1X1
011
000
77 21 $fh->print(scalar $self->folded);
78 }
79  
80  
81 27 ▶sub toString(;$) {shift->string(@_)}
Subroutine toString: called CC=1 SCAR=0.0
Pod undocumented
82 sub string(;$)
83 93 ▶{ my $self = shift;
Subroutine string: called CC=4 SCAR=14.2
Pod documented
84 93 ▶ return $self->folded unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 88 5 93
85  
86 5 ▶ my $wrap = shift || $default_wrap_length;
Condition33%1/3
shift() || $default_wrap_length
l!l&&r!l&&!r
500
MC/DC0%0/2
shift() || $default_wrap_length
shift() $default_wrap_length
Truth table33%1/3
A || B
A= shift()B= $default_wrap_length
ABresult
1X1
011
000
87 5 my $name = $self->Name;
88 5 my @lines = $self->fold($name, $self->unfoldedBody, $wrap);
89 5 $lines[0] = $name . ':' . $lines[0];
90 5 ▶ wantarray ? @lines : join('', @lines);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 0 5
91 }
92  
93  
94 sub toDisclose()
95 0 ▶{ shift->name !~ m!^(?: (?:x-)?status
Subroutine toDisclose: not called CC=1 SCAR=6.9
Pod documented
96 | (?:resent-)?bcc
97 | Content-Length
98 | x-spam-
99 ) $!x;
100 }
101  
102  
103 124 ▶sub nrLines() { my @l = shift->foldedBody; scalar @l }
Subroutine nrLines: called CC=1 SCAR=0.0
Pod documented
104  
105  
106 50 *size = \&length;
107  
108 #------------------------------------------
109  
110  
111 # attempt to change the case of a tag to that required by RFC822. That
112 # being all characters are lowercase except the first of each
113 # word. Also if the word is an `acronym' then all characters are
114 # uppercase. We, rather arbitrarily, decide that a word is an acronym
115 # if it does not contain a vowel and isn't the well-known 'Cc' or
116 # 'Bcc' headers.
117  
118 50 my %wf_lookup
119 = qw/mime MIME ldap LDAP soap SOAP swe SWE
120 bcc Bcc cc Cc id ID/;
121  
122 sub wellformedName(;$)
123 27 ▶{ my $thing = shift;
Subroutine wellformedName: called CC=4 SCAR=13.9
Pod documented
124 27 ▶ my $name = @_ ? shift : $thing->name;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 9 18 27
125  
126 join '-',
127 27 ▶ map { $wf_lookup{lc $_} || ( /[aeiouyAEIOUY]/ ? ucfirst lc : uc ) }
Branch: 2 branches
BranchTrueFalseTotal
$wf_lookup{lc $_} or /[aeiouyAEIOUY]/ ? ucfirst lc $_ : uc $_ 39 3 42
/[aeiouyAEIOUY]/ ? : 37 2 39
128 split /\-/, $name, -1;
129 }
130  
131 #------------------------------------------
132  
133  
134 0 ▶sub folded { shift->notImplemented }
Subroutine folded: not called CC=1 SCAR=6.9
Pod documented
135  
136  
137 sub body()
138 686 ▶{ my $self = shift;
Subroutine body: called CC=2 SCAR=6.9
Pod documented
139 686 my $body = $self->unfoldedBody;
140 686 ▶ return $body unless $self->isStructured;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isStructured 205 481 686
141  
142 481 my ($first) = $body =~ m/^((?:"[^"]*"|'[^']*'|[^;])*)/;
143 481 $first =~ s/\s+$//;
144 481 $first;
145 }
146  
147  
148 0 ▶sub foldedBody { shift->notImplemented }
Subroutine foldedBody: not called CC=1 SCAR=6.9
Pod documented
149  
150  
151 0 ▶sub unfoldedBody { shift->notImplemented }
Subroutine unfoldedBody: not called CC=1 SCAR=6.9
Pod documented
152  
153  
154 sub stripCFWS($)
155 55 ▶{ my $thing = shift;
Subroutine stripCFWS: called CC=12 SCAR=24.8
Pod documented
156  
157 # get (folded) data
158 55 ▶ my $string = @_ ? shift : $thing->foldedBody;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 28 27 55
159  
160 # remove comments
161 55 my $r = '';
162 55 my $in_dquotes = 0;
163 55 my $open_paren = 0;
164  
165 55 my @s = split m/([()"])/, $string;
166 55 ▶ while(@s)
Branch: 1 branch
BranchTrueFalseTotal
if (@s) 472 55 527
167 472 { my $s = shift @s;
168  
169 472 ▶ if(CORE::length($r)&& substr($r, -1) eq "\\") { $r .= $s }
Branch: 5 branches
BranchTrueFalseTotal
if (CORE::length $r and substr($r, -1) eq '\\') { } 4 468 472
elsif ($s eq '"') { } 40 428 468
elsif ($s eq '(' and not $in_dquotes) { } 80 348 428
elsif ($s eq ')' and not $in_dquotes) { } 80 268 348
elsif ($open_paren) { } 112 156 268
Condition100%3/3
CORE::length $r and substr($r, -1) eq "\\"
!ll&&!rl&&r
873814
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 "\\"
ABresult
0X0
100
111
170 40 elsif($s eq '"') { $in_dquotes = not $in_dquotes; $r .= $s }
171 80 ▶ elsif($s eq '(' && !$in_dquotes) { $open_paren++ }
Condition100%3/3
$s eq "(" and not $in_dquotes
!ll&&!rl&&r
344480
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
ABresult
0X0
100
111
172 80 ▶ elsif($s eq ')' && !$in_dquotes) { $open_paren-- }
Condition100%3/3
$s eq ")" and not $in_dquotes
!ll&&!rl&&r
266280
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
ABresult
0X0
100
111
173 elsif($open_paren) {} # in comment
174 156 else { $r .= $s }
175 }
176  
177 # beautify and unfold at the same time
178 55 for($r)
179 55 { s/\s+/ /gs;
180 55 s/\s+$//;
181 55 s/^\s+//;
182 }
183  
184 55 $r;
185 }
186  
187 #------------------------------------------
188  
189  
190 sub comment(;$)
191 31 ▶{ my $self = shift;
Subroutine comment: called CC=6 SCAR=18.1
Pod documented
192 31 ▶ return undef unless $self->isStructured;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->isStructured 4 27 31
193  
194 27 my $body = $self->unfoldedBody;
195  
196 27 ▶ if(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 25 27
197 2 { my $comment = shift;
198 2 $body =~ s/\s*\;.*//;
199 2 ▶ $body .= "; $comment" if defined $comment && CORE::length($comment);
Branch: 1 branch
BranchTrueFalseTotal
if defined $comment and CORE::length $comment 2 0 2
Condition33%1/3
defined $comment and CORE::length $comment
!ll&&!rl&&r
002
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
ABresult
0X0
100
111
200 2 $self->unfoldedBody($body);
201 2 return $comment;
202 }
203
204 25 ▶ $body =~ s/.*?\;\s*// ? $body : '';
Branch: 1 branch
BranchTrueFalseTotal
$body =~ s/.*?\;\s*// ? : 14 11 25
205 }
206  
207 10 ▶sub content() { shift->unfoldedBody } # Compatibility
Subroutine content: called CC=1 SCAR=0.0
Pod documented
208  
209  
210 sub attribute($;$)
211 375 ▶{ my ($self, $attr) = (shift, shift);
Subroutine attribute: called CC=9 SCAR=22.9
Pod documented
212 375 my $body = $self->unfoldedBody;
213  
214 375 ▶ unless(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 261 114 375
215 { # only get a value
216 261 ▶ if($body =~ m/\b$attr\s*\=\s*
Branch: 1 branch
BranchTrueFalseTotal
if ($body =~ /\b$attr\s*\=\s* ( "( (?> [^\\"]+|\\. )* )" | ([^";\s]*) )/xi) 171 90 261
217 ( "( (?> [^\\"]+|\\. )* )"
218 | ([^";\s]*)
219 )/xi)
220 171 { (my $val = $+) =~ s/\\(.)/$1/g;
221 171 return $val;
222 }
223 90 return undef;
224 }
225  
226 # set the value
227 114 my $value = shift;
228 114 ▶ unless(defined $value) # remove attribute
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 114 114
229 0 { for($body)
230 0 ▶ { s/\b$attr\s*=\s*"(?>[^\\"]|\\.)*"//i
Branch: 1 branch
BranchTrueFalseTotal
s/\b$attr\s*=\s*"(?>[^\\"]|\\.)*"//i or s/\b$attr\s*=\s*[;\s]*//i 0 0 0
231 or s/\b$attr\s*=\s*[;\s]*//i;
232 }
233 0 $self->unfoldedBody($body);
234 0 return undef;
235 }
236  
237 114 (my $quoted = $value) =~ s/(["\\])/\\$1/g;
238  
239 114 for($body)
240 { s/\b$attr\s*=\s*"(?>[^\\"]|\\.){0,1000}"/$attr="$quoted"/i
241 or s/\b$attr\s*=\s*[^;\s]*/$attr="$quoted"/i
242 114 ▶ or do { $_ .= qq(; $attr="$quoted") }
Branch: 1 branch
BranchTrueFalseTotal
s/\b$attr\s*=\s*"(?>[^\\"]|\\.){0,1000}"/$attr="$quoted"/i or s/\b$attr\s*=\s*[^;\s]*/$attr="$quoted"/i or do { $_ .= qq[; $attr="$quoted"] } 89 25 114
Condition100%3/3
s/\b$attr\s*=\s*"(?>[^\\"]|\\.){0,1000}"/$attr="$quoted"/i or s/\b$attr\s*=\s*[^;\s]*/$attr="$quoted"/i
l!l&&r!l&&!r
24189
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
ABresult
1X1
011
000
243 }
244  
245 114 $self->unfoldedBody($body);
246 114 $value;
247 }
248  
249 #------------------------------------------
250  
251  
252 sub attributes()
253 1 ▶{ my $self = shift;
Subroutine attributes: called CC=2 SCAR=6.9
Pod documented
254 1 my $body = $self->unfoldedBody;
255  
256 1 my @attrs;
257 1 ▶ while($body =~ m/\b(\w+)\s*\=\s*
Branch: 1 branch
BranchTrueFalseTotal
if ($body =~ /\b(\w+)\s*\=\s* ( "( (?: [^"]|\\" )* )" | '( (?: [^']|\\' )* )' | ([^;\s]*) ) /gix) 3 1 4
258 ( "( (?: [^"]|\\" )* )"
259 | '( (?: [^']|\\' )* )'
260 | ([^;\s]*)
261 )
262 /xig)
263 3 { push @attrs, $1 => $+;
264 }
265  
266 1 @attrs;
267 }
268  
269 #------------------------------------------
270  
271  
272 sub toInt()
273 12 ▶{ my $self = shift;
Subroutine toInt: called CC=2 SCAR=9.2
Pod documented
274 12 ▶ return $1 if $self->body =~ m/^\s*(\d+)\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->body =~ /^\s*(\d+)\s*$/ 12 0 12
275  
276 0 $self->log(WARNING => "Field content is not numerical: ". $self->toString);
277  
278 0 return undef;
279 }
280  
281 #------------------------------------------
282  
283  
284 50 my @weekday = qw/Sun Mon Tue Wed Thu Fri Sat Sun/;
285 50 my @month = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
286  
287 sub toDate(@)
288 16 ▶{ my $class = shift;
Subroutine toDate: called CC=3 SCAR=12.3
Pod documented
289 16 ▶ my @time = @_== 0 ? localtime() : @_==1 ? localtime(shift) : @_;
Branch: 2 branches
BranchTrueFalseTotal
@_ == 0 ? : 16 0 16
@_ == 1 ? : 0 0 0
290 16 my $format = "$weekday[$time[6]], %d $month[$time[4]] %Y %H:%M:%S %z";
291 16 my $time = strftime $format, @time;
292  
293 # for C libs which do not (GNU compliantly) support %z
294 16 $time =~ s/ (\%z|[A-Za-z ]+)$/_tz_offset($1)/e;
295  
296 16 $time;
297 }
298  
299 sub _tz_offset($)
300 0 ▶{ my $zone = shift;
Subroutine _tz_offset: not called CC=3 SCAR=24.8
301 0 require Time::Zone;
302  
303 0 ▶ my $diff = $zone eq '%z' ? Time::Zone::tz_local_offset()
Branch: 1 branch
BranchTrueFalseTotal
$zone eq '%z' ? : 0 0 0
304 : Time::Zone::tz_offset($zone);
305 0 my $minutes = int((abs($diff)+0.01) / 60); # float rounding errors
306 0 my $hours = int(($minutes+0.01) / 60);
307 0 $minutes -= $hours * 60;
308 0 ▶ sprintf( ($diff < 0 ? " -%02d%02d" : " +%02d%02d"), $hours, $minutes);
Branch: 1 branch
BranchTrueFalseTotal
$diff < 0 ? : 0 0 0
309 }
310  
311 #------------------------------------------
312  
313  
314 18 ▶sub addresses() { Mail::Address->parse(shift->unfoldedBody) }
Subroutine addresses: called CC=1 SCAR=0.0
Pod documented
315  
316 #------------------------------------------
317  
318  
319 sub study()
320 73 ▶{ my $self = shift;
Subroutine study: called CC=1 SCAR=0.0
Pod documented
321 73 require Mail::Message::Field::Full;
322 73 Mail::Message::Field::Full->new(scalar $self->folded);
323 }
324  
325 #------------------------------------------
326  
327  
328 sub dateToTimestamp($)
329 1 ▶{ my $string = $_[0]->stripCFWS($_[1]);
Subroutine dateToTimestamp: called CC=1 SCAR=0.0
Pod documented
330  
331 # in RFC822, FWSes can appear within the time.
332 1 $string =~ s/(\d\d)\s*\:\s*(\d\d)\s*\:\s*(\d\d)/$1:$2:$3/;
333  
334 1 require Date::Parse;
335 1 Date::Parse::str2time($string, 'GMT');
336 }
337  
338  
339 #------------------------------------------
340  
341  
342 #=notice Empty field: $name
343 #Empty fields are not allowed, however sometimes found in messages constructed
344 #by broken applications. You probably want to ignore this message unless you
345 #wrote this broken application yourself.
346  
347 sub consume($;$)
348 803 ▶{ my $self = shift;
Subroutine consume: called CC=7 SCAR=19.6
Pod documented
349 803 ▶ my ($name, $body) = defined $_[1] ? @_ : split(/\s*\:\s*/, (shift), 2);
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 789 14 803
350  
351 803 ▶ Mail::Reporter->log(WARNING => "Illegal character in field name $name")
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /[^\041-\071\073-\176]/ 0 803 803
352 if $name =~ m/[^\041-\071\073-\176]/;
353  
354 #
355 # Compose the body.
356 #
357  
358 803 ▶ if(ref $body) # Objects or array
Branch: 2 branches
BranchTrueFalseTotal
if (ref $body) { } 28 775 803
elsif (not $body =~ s/\n+$/\n/g) { } 728 47 775
359 28 ▶ { my $flat = $self->stringifyData($body) or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $flat = $self->stringifyData($body) or return () 0 28 28
360 28 $body = $self->fold($name, $flat);
361 }
362 elsif($body !~ s/\n+$/\n/g) # Added by user...
363 728 { $body = $self->fold($name, $body);
364 }
365 else # Created by parser
366 { # correct erroneous wrap-seperators (dos files under UNIX)
367 47 $body =~ s/[\012\015]+/\n/g;
368 47 $body =~ s/^[ \t]*/ /; # start with one blank, folding kept unchanged
369  
370 47 ▶ $self->log(NOTICE => "Empty field: $name")
Branch: 1 branch
BranchTrueFalseTotal
if $body eq " \n" 0 47 47
371 if $body eq " \n";
372 }
373  
374 803 ($name, $body);
375 }
376  
377 #------------------------------------------
378  
379  
380 sub stringifyData($)
381 28 ▶{ my ($self, $arg) = (shift, shift);
Subroutine stringifyData: called CC=13 SCAR=25.9
Pod documented
382 28 my @addr;
383 28 ▶ foreach my $obj (ref $arg eq 'ARRAY' ? @$arg : ($arg))
Branch: 1 branch
BranchTrueFalseTotal
ref $arg eq 'ARRAY' ? : 14 14 28
384 33 ▶ { next unless defined $obj;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj 0 33 33
385  
386 33 ▶ if(!ref $obj) { push @addr, $obj; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $obj) 1 32 33
387 32 ▶ if($obj->isa('Mail::Address')) { push @addr, $obj->format; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->isa("Mail::Address")) 19 13 32
388  
389 13 ▶ if($obj->isa('Mail::Identity') || $obj->isa('User::Identity'))
Branch: 3 branches
BranchTrueFalseTotal
if ($obj->isa('Mail::Identity') or $obj->isa('User::Identity')) { } 7 6 13
elsif ($obj->isa('User::Identity::Collection::Emails')) { } 1 5 6
elsif ($obj->isa('Mail::Message::Field')) { } 5 0 5
Condition100%3/3
$obj->isa("Mail::Identity") or $obj->isa("User::Identity")
l!l&&r!l&&!r
616
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")
ABresult
1X1
011
000
390 7 { require Mail::Message::Field::Address;
391 7 push @addr, Mail::Message::Field::Address->coerce($obj)->string;
392 }
393 elsif($obj->isa('User::Identity::Collection::Emails'))
394 1 ▶ { my @roles = $obj->roles or next;
Branch: 1 branch
BranchTrueFalseTotal
my(@roles) = $obj->roles or next 0 1 1
395 1 require Mail::Message::Field::AddrGroup;
396 1 my $group = Mail::Message::Field::AddrGroup->coerce($obj);
397 1 ▶ push @addr, $group->string if $group;
Branch: 1 branch
BranchTrueFalseTotal
if $group 1 0 1
398 }
399 elsif($obj->isa('Mail::Message::Field'))
400 {
401 5 my $folded = join ' ', $obj->foldedBody;
402 5 $folded =~ s/^ //;
403 5 $folded =~ s/\n\z//;
404 5 push @addr, $folded;
405 }
406 else
407 0 { push @addr, "$obj"; # any other object is stringified
408 }
409 }
410  
411 28 ▶ @addr ? join(', ',@addr) : undef;
Branch: 1 branch
BranchTrueFalseTotal
@addr ? : 28 0 28
412 }
413  
414 #------------------------------------------
415  
416  
417 sub setWrapLength(;$)
418 353 ▶{ my $self = shift;
Subroutine setWrapLength: called CC=2 SCAR=6.9
Pod documented
419  
420 353 ▶ $self->foldedBody(scalar $self->fold($self->Name, $self->unfoldedBody, @_))
Branch: 1 branch
BranchTrueFalseTotal
if @_ 7 346 353
421 if @_;
422  
423 353 $self;
424 }
425  
426 #------------------------------------------
427  
428  
429 sub defaultWrapLength(;$)
430 0 ▶{ my $self = shift;
Subroutine defaultWrapLength: not called CC=2 SCAR=17.9
Pod documented
431 0 ▶ @_ ? ($default_wrap_length = shift) : $default_wrap_length;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
432 }
433  
434 #------------------------------------------
435  
436  
437 sub fold($$;$)
438 958 ▶{ my $thing = shift;
Subroutine fold: called CC=11 SCAR=24.0
Pod documented
439 958 my $name = shift;
440 958 my $line = shift;
441 958 ▶ my $wrap = shift || $default_wrap_length;
Condition66%2/3
shift() || $default_wrap_length
l!l&&r!l&&!r
129460
MC/DC0%0/2
shift() || $default_wrap_length
shift() $default_wrap_length
Truth table66%2/3
A || B
A= shift()B= $default_wrap_length
ABresult
1X1
011
000
442 958 ▶ defined $line or $line = '';
Branch: 1 branch
BranchTrueFalseTotal
defined $line or $line = "" 1 957 958
443  
444 958 $line =~ s/\n\s/ /gms; # Remove accidental folding
445 958 ▶ return " \n" unless CORE::length($line); # empty field
Branch: 1 branch
BranchTrueFalseTotal
unless CORE::length $line 3 955 958
446  
447 955 my @folded;
448 955 while(1)
449 1010 ▶ { my $max = $wrap - (@folded ? 1 : CORE::length($name) + 2);
Branch: 1 branch
BranchTrueFalseTotal
@folded ? : 55 955 1010
450 1010 my $min = $max >> 2;
451 1010 ▶ last if CORE::length($line) < $max;
Branch: 1 branch
BranchTrueFalseTotal
if CORE::length $line < $max 955 55 1010
452  
453 55 ▶ $line =~ s/^ ( .{$min,$max} # $max to 30 chars
Branch: 1 branch
BranchTrueFalseTotal
$line =~ s/^ ( .{$min,$max} # $max to 30 chars [;,] # followed at a ; or , )[ \t] # and then a WSP //x or $line =~ s/^ ( .{$min,$max} ) # $max to 30 chars [ \t] # followed by a WSP //x or $line =~ s/^ ( .{$max,}? ) # longer, but minimal chars [ \t] # followed by a WSP //x or $line =~ s/^ (.*) //x 3 52 55
Condition100%6/6
$line =~ s/^ ( .{$min,$max} # $max to 30 chars [;,] # followed at a ; or , )[ \t] # and then a WSP //x or $line =~ s/^ ( .{$min,$max} ) # $max to 30 chars [ \t] # followed by a WSP //x or $line =~ s/^ ( .{$max,}? ) # longer, but minimal chars [ \t] # followed by a WSP //x
l!l&&r!l&&!r
5113
$line =~ s/^ ( .{$min,$max} # $max to 30 chars [;,] # followed at a ; or , )[ \t] # and then a WSP //x or $line =~ s/^ ( .{$min,$max} ) # $max to 30 chars [ \t] # followed by a WSP //x
l!l&&r!l&&!r
21304
MC/DC100%3/3
$line =~ s/^ ( .{$min,$max} # $max to 30 chars [;,] # followed at a ; or , )[ \t] # and then a WSP //x or $line =~ s/^ ( .{$min,$max} ) # $max to 30 chars [ \t] # followed by a WSP //x or $line =~ s/^ ( .{$max,}? ) # longer, but minimal chars [ \t] # followed by a WSP //x
$line =~ s/^ ( .{$min,$max} # $max to 30 chars [;,] # followed at a ; or , )[ \t] # and then a WSP //x $line =~ s/^ ( .{$min,$max} ) # $max to 30 chars [ \t] # followed by 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} # $max to 30 chars [;,] # followed at a ; or , )[ \t] # and then a WSP //xB= $line =~ s/^ ( .{$min,$max} ) # $max to 30 chars [ \t] # followed by a WSP //xC= $line =~ s/^ ( .{$max,}? ) # longer, but minimal chars [ \t] # followed by a WSP //x
ABCresult
1XX1
01X1
0011
0000
454 [;,] # followed at a ; or ,
455 )[ \t] # and then a WSP
456 //x
457 || $line =~ s/^ ( .{$min,$max} ) # $max to 30 chars
458 [ \t] # followed by a WSP
459 //x
460 || $line =~ s/^ ( .{$max,}? ) # longer, but minimal chars
461 [ \t] # followed by a WSP
462 //x
463 || $line =~ s/^ (.*) //x; # everything
464  
465 55 push @folded, " $1\n";
466 }
467  
468 955 ▶ push @folded, " $line\n" if CORE::length($line);
Branch: 1 branch
BranchTrueFalseTotal
if CORE::length $line 952 3 955
469 955 ▶ wantarray ? @folded : join('', @folded);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 950 955
470 }
471  
472  
473 sub unfold($)
474 1696 ▶{ my $string = $_[1];
Subroutine unfold: called CC=2 SCAR=6.9
Pod documented
475 1696 for($string)
476 1696 { s/\r?\n\s?/ /gs; # remove FWS
477 1696 s/^ +//;
478 1696 s/ +$//;
479 }
480 1696 $string;
481 }
482  
483 #------------------------------------------
484  
485  
486 50 1;
« Message/Convert/MimeEntity.pm ↑ Summary Box/FastScalar.pm »