Message/Head/Complete.pm

filter: Statementstmt 70.8% 182 / 257 Branchbran 52.5% 61 / 116 Conditioncond 33.9% 20 / 59 MC/DCmcdc 8.3% 3 / 36 Subroutinesub 69.3% 34 / 49 Podpod 94.7% 36 / 38 totaltotal 60.5% 336 / 555 CC 88 SCAR 23.7
CC
88
Cov
61%
printSelected
56.0
messageIdPrefix
21.2
spamGroups
20.0
CRAP 10.7
« Message/Replace/MailHeader.pm ↑ Summary Message/Body/Multipart.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::Head::Complete;
10 35 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 35 $VERSION = '3.012';
12  
13 35 ▶use base 'Mail::Message::Head';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 35 ▶use Mail::Box::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 35 ▶use Mail::Message::Head::Partial;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 35 ▶use Scalar::Util qw/weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 35 ▶use List::Util qw/sum/;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 35 ▶use Sys::Hostname qw/hostname/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25  
26 sub clone(;@)
27 50 ▶{ my $self = shift;
Subroutine clone: called CC=2 SCAR=6.9
Pod documented
28 50 my $copy = ref($self)->new($self->logSettings);
29  
30 50 $copy->addNoRealize($_->clone) for $self->grepNames(@_);
31 50 $copy->modified(1);
32 50 $copy;
33 }
34  
35  
36 sub build(@)
37 4 ▶{ my $class = shift;
Subroutine build: called CC=7 SCAR=22.7
Pod documented
38 4 my $self = $class->new;
39 4 ▶ while(@_)
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 25 4 29
40 25 { my $name = shift;
41 25 ▶ defined $name or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $name or next 0 25 25
42  
43 25 ▶ if($name->isa('Mail::Message::Field'))
Branch: 1 branch
BranchTrueFalseTotal
if ($name->isa("Mail::Message::Field")) 0 25 25
44 0 { $self->add($name);
45 0 next;
46 }
47  
48 25 my $content = shift;
49 25 ▶ defined $content or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $content or next 0 25 25
50  
51 25 ▶ if(ref $content && $content->isa('Mail::Message::Field'))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $content and $content->isa("Mail::Message::Field")) 0 25 25
Condition33%1/3
ref $content and $content->isa("Mail::Message::Field")
!ll&&!rl&&r
2500
MC/DC0%0/2
ref $content and $content->isa("Mail::Message::Field")
ref $content $content->isa("Mail::Message::Field")
Truth table33%1/3
A and B
A= ref $contentB= $content->isa("Mail::Message::Field")
ABresult
0X0
100
111
52 0 { $self->log(WARNING => "Field objects have an implied name ($name)");
53 0 $self->add($content);
54 0 next;
55 }
56  
57 25 $self->add($name, $content);
58 }
59  
60 4 $self;
61 }
62  
63 #------------------------------------------
64  
65  
66 sub isDelayed() {0}
67  
68  
69 44 ▶sub nrLines() { sum 1, map $_->nrLines, shift->orderedFields }
Subroutine nrLines: called CC=1 SCAR=0.0
Pod documented
70 57 ▶sub size() { sum 1, map $_->size, shift->orderedFields }
Subroutine size: called CC=1 SCAR=0.0
Pod documented
71  
72  
73 sub wrap($)
74 0 ▶{ my ($self, $length) = @_;
Subroutine wrap: not called CC=2 SCAR=17.9
Pod documented
75 0 $_->setWrapLength($length) for $self->orderedFields;
76 }
77  
78 #------------------------------------------
79  
80  
81 sub add(@)
82 176 ▶{ my $self = shift;
Subroutine add: called CC=7 SCAR=19.8
Pod documented
83  
84 # Create object for this field.
85  
86 my $field
87 = @_==1 && ref $_[0] ? shift # A fully qualified field is added.
88 176 ▶ : ($self->{MMH_field_type} || 'Mail::Message::Field::Fast')->new(@_);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] ? : 0 176 176
Condition40%2/5
@_ == 1 and ref $_[0]
!ll&&!rl&&r
17600
$self->{'MMH_field_type'} || 'Mail::Message::Field::Fast'
l!l
0176
MC/DC0%0/2
@_ == 1 and ref $_[0]
@_ == 1 ref $_[0]
MC/DC0%0/1
$self->{'MMH_field_type'} || 'Mail::Message::Field::Fast'
$self->{'MMH_field_type'}
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0]
ABresult
0X0
100
111
Truth table50%1/2
A
A= $self->{'MMH_field_type'}
Aresult
11
00
89  
90 176 ▶ return if !defined $field;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 176 176
91  
92 176 $field->setWrapLength;
93  
94 # Put it in place.
95  
96 176 my $known = $self->{MMH_fields};
97 176 my $name = $field->name; # is already lower-cased
98  
99 176 $self->addOrderedFields($field);
100  
101 176 ▶ if(defined $known->{$name})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $known->{$name}) { } 3 173 176
102 3 ▶ { if(ref $known->{$name} eq 'ARRAY') { push @{$known->{$name}}, $field }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $known->{$name} eq 'ARRAY') { } 1 2 3
103 2 else { $known->{$name} = [ $known->{$name}, $field ] }
104 }
105 else
106 173 { $known->{$name} = $field;
107 }
108  
109 176 $self->{MMH_modified}++;
110 176 $field;
111 }
112  
113  
114 sub count($)
115 0 ▶{ my $known = shift->{MMH_fields};
Subroutine count: not called CC=3 SCAR=24.8
Pod documented
116 0 my $value = $known->{lc shift};
117  
118 0 ▶ ! defined $value ? 0
Branch: 2 branches
BranchTrueFalseTotal
!defined($value) ? : 0 0 0
ref $value ? : 0 0 0
119 : ref $value ? @$value
120 : 1;
121 }
122  
123  
124 10 ▶sub names() {shift->knownNames}
Subroutine names: called CC=1 SCAR=0.0
Pod documented
125  
126  
127 sub grepNames(@)
128 56 ▶{ my $self = shift;
Subroutine grepNames: called CC=6 SCAR=19.4
Pod documented
129 56 my @take;
130 56 ▶ push @take, (ref $_ eq 'ARRAY' ? @$_ : $_) foreach @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 0 6 6
131  
132 56 ▶ return $self->orderedFields unless @take;
Branch: 1 branch
BranchTrueFalseTotal
unless @take 50 6 56
133  
134 6 my $take;
135 6 ▶ if(@take==1 && ref $take[0] eq 'Regexp')
Branch: 1 branch
BranchTrueFalseTotal
if (@take == 1 and ref $take[0] eq 'Regexp') { } 6 0 6
Condition33%1/3
@take == 1 and ref $take[0] eq "Regexp"
!ll&&!rl&&r
006
MC/DC0%0/2
@take == 1 and ref $take[0] eq "Regexp"
@take == 1 ref $take[0] eq "Regexp"
Truth table33%1/3
A and B
A= @take == 1B= ref $take[0] eq "Regexp"
ABresult
0X0
100
111
136 6 { $take = $take[0]; # one regexp prepared already
137 }
138 else
139 { # I love this trick:
140 0 local $" = ')|(?:';
141 0 $take = qr/^(?:(?:@take))/i;
142 }
143  
144 6 grep {$_->name =~ $take} $self->orderedFields;
145 }
146  
147  
148 35 my @skip_none = qw/content-transfer-encoding content-disposition
149 content-description content-id/;
150  
151 35 my %skip_none = map { ($_ => 1) } @skip_none;
152  
153 sub set(@)
154 469 ▶{ my $self = shift;
Subroutine set: called CC=6 SCAR=17.9
Pod documented
155 469 ▶ my $type = $self->{MMH_field_type} || 'Mail::Message::Field::Fast';
Condition50%1/2
$self->{'MMH_field_type'} || 'Mail::Message::Field::Fast'
l!l
0469
MC/DC0%0/1
$self->{'MMH_field_type'} || 'Mail::Message::Field::Fast'
$self->{'MMH_field_type'}
Truth table50%1/2
A
A= $self->{'MMH_field_type'}
Aresult
11
00
156 469 $self->{MMH_modified}++;
157  
158 # Create object for this field.
159 469 ▶ my $field = @_==1 && ref $_[0] ? shift->clone : $type->new(@_);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 && ref $_[0] ? : 457 12 469
Condition66%2/3
@_ == 1 and ref $_[0]
!ll&&!rl&&r
120457
MC/DC50%1/2
@_ == 1 and ref $_[0]
@_ == 1 ref $_[0]
Truth table66%2/3
A and B
A= @_ == 1B= ref $_[0]
ABresult
0X0
100
111
160  
161 469 my $name = $field->name; # is already lower-cased
162 469 my $known = $self->{MMH_fields};
163  
164 # Internally, non-existing content-info are in the body stored as 'none'
165 # The header will not contain these lines.
166  
167 469 ▶ if($skip_none{$name} && $field->body eq 'none')
Branch: 1 branch
BranchTrueFalseTotal
if ($skip_none{$name} and $field->body eq "none") 301 168 469
Condition100%3/3
$skip_none{$name} and $field->body eq "none"
!ll&&!rl&&r
12543301
MC/DC100%2/2
$skip_none{$name} and $field->body eq "none"
$skip_none{$name} $field->body eq "none"
Truth table100%3/3
A and B
A= $skip_none{$name}B= $field->body eq "none"
ABresult
0X0
100
111
168 301 { delete $known->{$name};
169 301 return $field;
170 }
171  
172 168 $field->setWrapLength;
173 168 $known->{$name} = $field;
174  
175 168 $self->addOrderedFields($field);
176 168 $field;
177 }
178  
179  
180 sub reset($@)
181 8 ▶{ my ($self, $name) = (shift, lc shift);
Subroutine reset: called CC=4 SCAR=13.9
Pod documented
182  
183 8 my $known = $self->{MMH_fields};
184  
185 8 ▶ if(@_==0)
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 0) 7 1 8
186 7 ▶ { $self->{MMH_modified}++ if delete $known->{$name};
Branch: 1 branch
BranchTrueFalseTotal
if delete $known->{$name} 1 6 7
187 7 return ();
188 }
189  
190 1 $self->{MMH_modified}++;
191  
192 # Cloning required, otherwise double registrations will not be
193 # removed from the ordered list: that's controled by 'weaken'
194  
195 1 my @fields = map $_->clone, @_;
196  
197 1 ▶ if(@_==1) { $known->{$name} = $fields[0] }
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 1 1
198 1 else { $known->{$name} = [@fields] }
199  
200 1 $self->addOrderedFields(@fields);
201 1 $self;
202 }
203  
204  
205 6 ▶sub delete($) { $_[0]->reset($_[1]) }
Subroutine delete: called CC=1 SCAR=0.0
Pod documented
206  
207  
208 sub removeField($)
209 8 ▶{ my ($self, $field) = @_;
Subroutine removeField: called CC=6 SCAR=19.2
Pod documented
210 8 my $name = $field->name;
211 8 my $known = $self->{MMH_fields};
212  
213 8 ▶ if(!defined $known->{$name})
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $known->{$name}) { } 0 8 8
elsif (ref $known->{$name} eq 'ARRAY') { } 2 6 8
elsif ($known->{$name} eq $field) { } 6 0 6
214 { ; } # complain
215 elsif(ref $known->{$name} eq 'ARRAY')
216 2 ▶ { for(my $i=0; $i < @{$known->{$name}}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$known->{$name};}) 2 0 2
217 {
218 2 return splice @{$known->{$name}}, $i, 1
219 2 ▶ if $known->{$name}[$i] eq $field;
Branch: 1 branch
BranchTrueFalseTotal
if $known->{$name}[$i] eq $field 2 0 2
220 }
221 }
222 elsif($known->{$name} eq $field)
223 6 { return delete $known->{$name};
224 }
225  
226 0 $self->log(WARNING => "Cannot remove field $name from header: not found.");
227  
228 0 return;
229 }
230  
231  
232 sub removeFields(@)
233 48 ▶{ my $self = shift;
Subroutine removeFields: called CC=1 SCAR=0.0
Pod documented
234 48 (bless $self, 'Mail::Message::Head::Partial')->removeFields(@_);
235 }
236  
237  
238 sub removeFieldsExcept(@)
239 0 ▶{ my $self = shift;
Subroutine removeFieldsExcept: not called CC=1 SCAR=6.9
Pod documented
240 0 (bless $self, 'Mail::Message::Head::Partial')->removeFieldsExcept(@_);
241 }
242  
243  
244 86 ▶sub removeContentInfo() { shift->removeFields(qr/^Content-/, 'Lines') }
Subroutine removeContentInfo: called CC=1 SCAR=0.0
Pod documented
245  
246  
247 sub removeResentGroups(@)
248 0 ▶{ my $self = shift;
Subroutine removeResentGroups: not called CC=1 SCAR=6.9
Pod documented
249 0 (bless $self, 'Mail::Message::Head::Partial')->removeResentGroups(@_);
250 }
251  
252  
253 sub removeListGroup(@)
254 0 ▶{ my $self = shift;
Subroutine removeListGroup: not called CC=1 SCAR=6.9
Pod documented
255 0 (bless $self, 'Mail::Message::Head::Partial')->removeListGroup(@_);
256 }
257  
258  
259 sub removeSpamGroups(@)
260 0 ▶{ my $self = shift;
Subroutine removeSpamGroups: not called CC=1 SCAR=6.9
Pod documented
261 0 (bless $self, 'Mail::Message::Head::Partial')->removeSpamGroups(@_);
262 }
263  
264  
265 sub spamDetected()
266 0 ▶{ my $self = shift;
Subroutine spamDetected: not called CC=2 SCAR=17.9
Pod documented
267 0 ▶ my @sgs = $self->spamGroups or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my(@sgs) = $self->spamGroups or return undef 0 0 0
268 0 grep { $_->spamDetected } @sgs;
269 }
270  
271  
272 sub print(;$)
273 35 ▶{ my $self = shift;
Subroutine print: called CC=4 SCAR=15.2
Pod documented
274 35 ▶ my $fh = shift || select;
Condition33%1/3
shift() || select()
l!l&&r!l&&!r
3500
MC/DC0%0/2
shift() || select()
shift() select()
Truth table33%1/3
A || B
A= shift()B= select()
ABresult
1X1
011
000
275  
276 $_->print($fh)
277 35 foreach $self->orderedFields;
278  
279 35 ▶ if(ref $fh eq 'GLOB') { print $fh "\n" }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fh eq 'GLOB') { } 0 35 35
280 35 else { $fh->print("\n") }
281  
282 35 $self;
283 }
284  
285  
286 sub printUndisclosed($)
287 0 ▶{ my ($self, $fh) = @_;
Subroutine printUndisclosed: not called CC=3 SCAR=24.8
Pod documented
288  
289 $_->print($fh)
290 0 foreach grep {$_->toDisclose} $self->orderedFields;
291  
292 0 ▶ if(ref $fh eq 'GLOB') { print $fh "\n" }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fh eq 'GLOB') { } 0 0 0
293 0 else { $fh->print("\n") }
294  
295 0 $self;
296 }
297  
298  
299 sub printSelected($@)
300 0 ▶{ my ($self, $fh) = (shift, shift);
Subroutine printSelected: not called CC=7 SCAR=40.3
Pod documented
301  
302 0 foreach my $field ($self->orderedFields)
303 0 { my $Name = $field->Name;
304 0 my $name = $field->name;
305  
306 0 my $found;
307 0 foreach my $pattern (@_)
308 0 ▶ { $found = ref $pattern?($Name =~ $pattern):($name eq lc $pattern);
Branch: 1 branch
BranchTrueFalseTotal
ref $pattern ? : 0 0 0
309 0 ▶ last if $found;
Branch: 1 branch
BranchTrueFalseTotal
if $found 0 0 0
310 }
311  
312 0 ▶ if(!$found) { ; }
Branch: 2 branches
BranchTrueFalseTotal
if (not $found) { } 0 0 0
elsif (ref $fh eq 'GLOB') { } 0 0 0
313 0 elsif(ref $fh eq 'GLOB') { print $fh "\n" }
314 0 else { $fh->print("\n") }
315 }
316  
317 0 $self;
318 }
319  
320  
321 1 ▶sub toString() {shift->string}
Subroutine toString: called CC=1 SCAR=0.0
Pod undocumented
322 sub string()
323 6 ▶{ my $self = shift;
Subroutine string: called CC=2 SCAR=7.0
Pod documented
324  
325 6 my @lines = map {$_->string} $self->orderedFields;
326 6 push @lines, "\n";
327  
328 6 ▶ wantarray ? @lines : join('', @lines);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 6 6
329 }
330  
331  
332 sub resentGroups()
333 3 ▶{ my $self = shift;
Subroutine resentGroups: called CC=1 SCAR=0.0
Pod documented
334 3 require Mail::Message::Head::ResentGroup;
335 3 Mail::Message::Head::ResentGroup->from($self);
336 }
337  
338  
339 sub addResentGroup(@)
340 3 ▶{ my $self = shift;
Subroutine addResentGroup: called CC=8 SCAR=20.9
Pod documented
341  
342 3 require Mail::Message::Head::ResentGroup;
343 3 ▶ my $rg = @_==1 ? (shift) : Mail::Message::Head::ResentGroup->new(@_);
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 2 1 3
344  
345 3 my @fields = $rg->orderedFields;
346 3 my $order = $self->{MMH_order};
347  
348 # Look for the first line which relates to resent groups
349 3 my $i;
350 3 ▶ for($i=0; $i < @$order; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$order) 13 2 15
351 13 ▶ { next unless defined $order->[$i];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $order->[$i] 0 13 13
352 13 ▶ last if $rg->isResentGroupFieldName($order->[$i]->name);
Branch: 1 branch
BranchTrueFalseTotal
if $rg->isResentGroupFieldName($order->[$i]->name) 1 12 13
353 }
354  
355 3 my $known = $self->{MMH_fields};
356 3 ▶ while(@fields)
Branch: 1 branch
BranchTrueFalseTotal
if (@fields) 15 3 18
357 15 { my $f = pop @fields;
358  
359 # Add to the order of fields
360 15 splice @$order, $i, 0, $f;
361 15 weaken( $order->[$i] );
362 15 my $name = $f->name;
363  
364 # Adds *before* in the list for get().
365 15 ▶ if(!defined $known->{$name}) {$known->{$name} = $f}
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $known->{$name}) { } 13 2 15
elsif (ref $known->{$name} eq 'ARRAY') { } 0 2 2
366 0 elsif(ref $known->{$name} eq 'ARRAY'){unshift @{$known->{$name}},$f}
367 2 else {$known->{$name} = [$f, $known->{$name}]}
368 }
369  
370 3 $rg->messageHead($self);
371  
372 # Oh, the header has changed!
373 3 $self->modified(1);
374  
375 3 $rg;
376 }
377  
378  
379 sub listGroup()
380 0 ▶{ my $self = shift;
Subroutine listGroup: not called CC=1 SCAR=6.9
Pod documented
381 0 eval "require 'Mail::Message::Head::ListGroup'";
382 0 Mail::Message::Head::ListGroup->from($self);
383 }
384  
385  
386 sub addListGroup($)
387 0 ▶{ my ($self, $lg) = @_;
Subroutine addListGroup: not called CC=1 SCAR=6.9
Pod documented
388 0 $lg->attach($self);
389 }
390  
391  
392 sub spamGroups(@)
393 0 ▶{ my $self = shift;
Subroutine spamGroups: not called CC=4 SCAR=30.0
Pod documented
394 0 require Mail::Message::Head::SpamGroup;
395 0 ▶ my @types = @_ ? (types => \@_) : ();
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
396 0 my @sgs = Mail::Message::Head::SpamGroup->from($self, @types);
397 0 ▶ wantarray || @_ != 1 ? @sgs : $sgs[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray || @_ != 1 ? : 0 0 0
Condition0%0/3
wantarray or @_ != 1
l!l&&r!l&&!r
000
MC/DC0%0/2
wantarray or @_ != 1
wantarray @_ != 1
Truth table0%0/3
A or B
A= wantarrayB= @_ != 1
ABresult
1X1
011
000
398 }
399  
400  
401 sub addSpamGroup($)
402 0 ▶{ my ($self, $sg) = @_;
Subroutine addSpamGroup: not called CC=1 SCAR=6.9
Pod documented
403 0 $sg->attach($self);
404 }
405  
406 #------------------------------------------
407  
408  
409 2 ▶sub timestamp() {shift->guessTimestamp || time}
Subroutine timestamp: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
(shift())->guessTimestamp or time 0 2 2
410  
411  
412 sub recvstamp()
413 2 ▶{ my $self = shift;
Subroutine recvstamp: called CC=5 SCAR=22.7
Pod documented
414  
415 2 ▶ return $self->{MMH_recvstamp} if exists $self->{MMH_recvstamp};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"MMH_recvstamp"} 1 1 2
416  
417 my $recvd = $self->get('received', 0) or
418 1 ▶ return $self->{MMH_recvstamp} = undef;
Branch: 1 branch
BranchTrueFalseTotal
my $recvd = $self->get("received", 0) or return $self->{"MMH_recvstamp"} = undef 1 0 1
419  
420 0 my $stamp = Mail::Message::Field->dateToTimestamp($recvd->comment);
421  
422 0 ▶ $self->{MMH_recvstamp} = defined $stamp && $stamp > 0 ? $stamp : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $stamp && $stamp > 0 ? : 0 0 0
Condition0%0/3
defined $stamp and $stamp > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $stamp and $stamp > 0
defined $stamp $stamp > 0
Truth table0%0/3
A and B
A= defined $stampB= $stamp > 0
ABresult
0X0
100
111
423 }
424  
425  
426 sub guessTimestamp()
427 2 ▶{ my $self = shift;
Subroutine guessTimestamp: called CC=8 SCAR=25.8
Pod undocumented
428 2 ▶ return $self->{MMH_timestamp} if exists $self->{MMH_timestamp};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"MMH_timestamp"} 1 1 2
429  
430 1 my $stamp;
431 1 ▶ if(my $date = $self->get('date'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $date = $self->get("date")) 1 0 1
432 1 { $stamp = Mail::Message::Field->dateToTimestamp($date);
433 }
434  
435 1 ▶ unless($stamp)
Branch: 1 branch
BranchTrueFalseTotal
unless ($stamp) 0 1 1
436 0 { foreach (reverse $self->get('received'))
437 0 { $stamp = Mail::Message::Field->dateToTimestamp($_->comment);
438 0 ▶ last if $stamp;
Branch: 1 branch
BranchTrueFalseTotal
if $stamp 0 0 0
439 }
440 }
441  
442 1 ▶ $self->{MMH_timestamp} = defined $stamp && $stamp > 0 ? $stamp : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $stamp && $stamp > 0 ? : 1 0 1
Condition33%1/3
defined $stamp and $stamp > 0
!ll&&!rl&&r
001
MC/DC0%0/2
defined $stamp and $stamp > 0
defined $stamp $stamp > 0
Truth table33%1/3
A and B
A= defined $stampB= $stamp > 0
ABresult
0X0
100
111
443 }
444  
445 sub guessBodySize()
446 12 ▶{ my $self = shift;
Subroutine guessBodySize: called CC=5 SCAR=18.4
Pod documented
447  
448 12 my $cl = $self->get('Content-Length');
449 12 ▶ return $1 if defined $cl && $cl =~ m/(\d+)/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cl and $cl =~ /(\d+)/ 0 12 12
Condition33%1/3
defined $cl and $cl =~ /(\d+)/
!ll&&!rl&&r
1200
MC/DC0%0/2
defined $cl and $cl =~ /(\d+)/
defined $cl $cl =~ /(\d+)/
Truth table33%1/3
A and B
A= defined $clB= $cl =~ /(\d+)/
ABresult
0X0
100
111
450  
451 12 my $lines = $self->get('Lines'); # 40 chars per lines
452 12 ▶ return $1 * 40 if defined $lines && $lines =~ m/(\d+)/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $lines and $lines =~ /(\d+)/ 0 12 12
Condition33%1/3
defined $lines and $lines =~ /(\d+)/
!ll&&!rl&&r
1200
MC/DC0%0/2
defined $lines and $lines =~ /(\d+)/
defined $lines $lines =~ /(\d+)/
Truth table33%1/3
A and B
A= defined $linesB= $lines =~ /(\d+)/
ABresult
0X0
100
111
453  
454 12 undef;
455 }
456  
457 #------------------------------------------
458  
459  
460 sub createFromLine()
461 0 ▶{ my $self = shift;
Subroutine createFromLine: not called CC=4 SCAR=30.0
Pod documented
462 0 my $sender = $self->message->sender;
463 0 ▶ my $stamp = $self->recvstamp || $self->timestamp || time;
Condition0%0/6
$self->recvstamp || $self->timestamp || time
l!l&&r!l&&!r
000
$self->recvstamp or $self->timestamp
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->recvstamp || $self->timestamp || time
$self->recvstamp $self->timestamp time
Truth table0%0/4
A or B || C
A= $self->recvstampB= $self->timestampC= time
ABCresult
1XX1
01X1
0011
0000
464 0 ▶ my $addr = defined $sender ? $sender->address : 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
defined $sender ? : 0 0 0
465 0 "From $addr ".(gmtime $stamp)."\n"
466 }
467  
468  
469 35 my $msgid_creator;
470  
471 sub createMessageId()
472 93 ▶{ $msgid_creator ||= $_[0]->messageIdPrefix;
Subroutine createMessageId: called CC=2 SCAR=7.1
Pod documented
Condition66%2/3
$msgid_creator ||= $_[0]->messageIdPrefix
l!l&&r!l&&!r
83100
MC/DC0%0/2
$msgid_creator ||= $_[0]->messageIdPrefix
$msgid_creator $_[0]->messageIdPrefix
Truth table66%2/3
A ||= B
A= $msgid_creatorB= $_[0]->messageIdPrefix
ABresult
1X1
011
000
473 93 $msgid_creator->(@_);
474 }
475  
476  
477 sub messageIdPrefix(;$$)
478 10 ▶{ my $thing = shift;
Subroutine messageIdPrefix: called CC=11 SCAR=30.6
Pod documented
479 10 ▶ return $msgid_creator
Branch: 1 branch
BranchTrueFalseTotal
unless @_ or not defined $msgid_creator 0 10 10
Condition33%1/3
@_ or not defined $msgid_creator
l!l&&r!l&&!r
0100
MC/DC0%0/2
@_ or not defined $msgid_creator
@_ not defined $msgid_creator
Truth table33%1/3
A or not(B)
A= @_B= not defined $msgid_creator
ABresult
1X1
011
000
480 unless @_ || !defined $msgid_creator;
481  
482 10 ▶ return $msgid_creator = shift
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 and ref $_[0] eq "CODE" 0 10 10
Condition33%1/3
@_ == 1 and ref $_[0] eq "CODE"
!ll&&!rl&&r
1000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "CODE"
@_ == 1 ref $_[0] eq "CODE"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "CODE"
ABresult
0X0
100
111
483 if @_==1 && ref $_[0] eq 'CODE';
484  
485 10 ▶ my $prefix = shift || "mailbox-$$";
Condition50%1/2
shift() || "mailbox-${$}"
l!l
010
MC/DC0%0/1
shift() || "mailbox-${$}"
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
486  
487 10 my $hostname = shift;
488 10 ▶ if(!defined $hostname)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $hostname) 10 0 10
489 10 { eval "require Net::Domain";
490 10 ▶ $@ or $hostname = Net::Domain::hostfqdn();
Branch: 1 branch
BranchTrueFalseTotal
$@ or $hostname = Net::Domain::hostfqdn() 10 0 10
491 }
492 10 ▶ $hostname ||= hostname || 'localhost';
Condition20%1/5
$hostname ||= hostname() || "localhost"
l!l&&r!l&&!r
1000
hostname() || 'localhost'
l!l
00
MC/DC0%0/2
$hostname ||= hostname() || "localhost"
$hostname hostname()
Truth table33%1/3
A ||= B
A= $hostnameB= hostname()
ABresult
1X1
011
000
493  
494 10 eval "require Time::HiRes";
495 10 ▶ if(Time::HiRes->can('gettimeofday'))
Branch: 1 branch
BranchTrueFalseTotal
if ("Time::HiRes"->can("gettimeofday")) 10 0 10
496 {
497 return $msgid_creator
498 93 ▶ = sub { my ($sec, $micro) = Time::HiRes::gettimeofday();
Subroutine __ANON__: called CC=1 SCAR=0.0
499 93 "$prefix-$sec-$micro\@$hostname";
500 10 };
501 }
502  
503 0 my $unique_id = time;
504 $msgid_creator
505 0 ▶ = sub { $unique_id++;
Subroutine __ANON__: not called CC=1 SCAR=6.9
506 0 "$prefix-$unique_id\@$hostname";
507 0 };
508 }
509  
510 35 1;
« Message/Replace/MailHeader.pm ↑ Summary Message/Body/Multipart.pm »