Message.pm

filter: Statementstmt 62.1% 192 / 309 Branchbran 34.0% 68 / 200 Conditioncond 32.5% 28 / 86 MC/DCmcdc 12.0% 6 / 50 Subroutinesub 67.6% 44 / 65 Podpod 92.3% 48 / 52 totaltotal 50.6% 386 / 762 SCAR 78.8
CC
135
Cov
48%
coerce
212.6
labelsToStatus
90.0
shortSize
56.0
CRAP 2638.4
« Message/Replace/MailInternet.pm ↑ Summary Message/Replace/MailHeader.pm »
1 # Copyrights 2001-2023 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;
10 34 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 34 $VERSION = '3.013';
12  
13 34 ▶use base 'Mail::Reporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 34 ▶use Mail::Message::Part ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 34 ▶use Mail::Message::Head::Complete ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 34 ▶use Mail::Message::Construct ();
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 34 ▶use Mail::Message::Body::Lines ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 34 ▶use Mail::Message::Body::Multipart ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 34 ▶use Mail::Message::Body::Nested ();
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 34 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 34 ▶use Scalar::Util qw(weaken blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 BEGIN {
30 34 ▶ unless($ENV{HARNESS_ACTIVE}) { # no tests during upgrade
Subroutine BEGIN: called CC=4 SCAR=25.5
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"HARNESS_ACTIVE"}) 0 34 34
31 # v3 splits Mail::Box in a few distributions
32 0 eval { require Mail::Box };
33 0 ▶ my $v = $Mail::Box::VERSION || 3;
Condition0%0/2
$Mail::Box::VERSION || 3
l!l
00
MC/DC0%0/1
$Mail::Box::VERSION || 3
$Mail::Box::VERSION
Truth table0%0/2
A
A= $Mail::Box::VERSION
Aresult
11
00
34 0 ▶ $v >= 3 or die "You need to upgrade the Mail::Box module";
Branch: 1 branch
BranchTrueFalseTotal
$v >= 3 or die "You need to upgrade the Mail::Box module" 0 0 0
35 }
36 }
37  
38  
39 34 our $crlf_platform = $^O =~ m/win32/i;
40  
41 #------------------------------------------
42  
43  
44 sub init($)
45 130 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=13 SCAR=28.0
Pod undocumented
46 130 $self->SUPER::init($args);
47  
48 # Field initializations also in coerce()
49 130 ▶ $self->{MM_modified} = $args->{modified} || 0;
Condition50%1/2
$args->{'modified'} || 0
l!l
0130
MC/DC0%0/1
$args->{'modified'} || 0
$args->{'modified'}
Truth table50%1/2
A
A= $args->{'modified'}
Aresult
11
00
50 130 ▶ $self->{MM_trusted} = $args->{trusted} || 0;
Condition50%1/2
$args->{'trusted'} || 0
l!l
0130
MC/DC0%0/1
$args->{'trusted'} || 0
$args->{'trusted'}
Truth table50%1/2
A
A= $args->{'trusted'}
Aresult
11
00
51  
52 # Set the header
53  
54 130 my $head;
55 130 ▶ if(defined($head = $args->{head})) { $self->head($head) }
Branch: 2 branches
BranchTrueFalseTotal
if (defined($head = $args->{'head'})) { } 118 12 130
elsif (my $msgid = $args->{'messageId'} || $args->{'messageID'}) { } 0 12 12
56 ▶ elsif(my $msgid = $args->{messageId} || $args->{messageID})
Condition33%1/3
$args->{'messageId'} || $args->{'messageID'}
l!l&&r!l&&!r
0012
MC/DC0%0/2
$args->{'messageId'} || $args->{'messageID'}
$args->{'messageId'} $args->{'messageID'}
Truth table33%1/3
A || B
A= $args->{'messageId'}B= $args->{'messageID'}
ABresult
1X1
011
000
57 0 { $self->takeMessageId($msgid);
58 }
59  
60 # Set the body
61 130 ▶ if(my $body = $args->{body})
Branch: 1 branch
BranchTrueFalseTotal
if (my $body = $args->{"body"}) 14 116 130
62 14 { $self->{MM_body} = $body;
63 14 $body->message($self);
64 }
65  
66 $self->{MM_body_type} = $args->{body_type}
67 130 ▶ if defined $args->{body_type};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"body_type"} 0 130 130
68  
69 $self->{MM_head_type} = $args->{head_type}
70 130 ▶ if defined $args->{head_type};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"head_type"} 0 130 130
71  
72 $self->{MM_field_type} = $args->{field_type}
73 130 ▶ if defined $args->{field_type};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args->{"field_type"} 0 130 130
74  
75 130 ▶ my $labels = $args->{labels} || [];
Condition50%1/2
$args->{'labels'} || []
l!l
0130
MC/DC0%0/1
$args->{'labels'} || []
$args->{'labels'}
Truth table50%1/2
A
A= $args->{'labels'}
Aresult
11
00
76 130 ▶ my @labels = ref $labels eq 'ARRAY' ? @$labels : %$labels;
Branch: 1 branch
BranchTrueFalseTotal
ref $labels eq 'ARRAY' ? : 130 0 130
77 130 ▶ push @labels, deleted => $args->{deleted} if exists $args->{deleted};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{"deleted"} 0 130 130
78 130 $self->{MM_labels} = { @labels };
79  
80 130 $self;
81 }
82  
83  
84 sub clone(@)
85 13 ▶{ my ($self, %args) = @_;
Subroutine clone: called CC=5 SCAR=17.1
Pod documented
86  
87 # First clone body, which may trigger head load as well. If head is
88 # triggered first, then it may be decided to be lazy on the body at
89 # moment. And then the body would be triggered.
90  
91 13 my ($head, $body) = ($self->head, $self->body);
92 $head = $head->clone
93 13 ▶ unless $args{shallow} || $args{shallow_head};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"shallow"} or $args{"shallow_head"} 13 0 13
Condition33%1/3
$args{"shallow"} or $args{"shallow_head"}
l!l&&r!l&&!r
0013
MC/DC0%0/2
$args{"shallow"} or $args{"shallow_head"}
$args{"shallow"} $args{"shallow_head"}
Truth table33%1/3
A or B
A= $args{"shallow"}B= $args{"shallow_head"}
ABresult
1X1
011
000
94  
95 $body = $body->clone
96 13 ▶ unless $args{shallow} || $args{shallow_body};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"shallow"} or $args{"shallow_body"} 13 0 13
Condition33%1/3
$args{"shallow"} or $args{"shallow_body"}
l!l&&r!l&&!r
0013
MC/DC0%0/2
$args{"shallow"} or $args{"shallow_body"}
$args{"shallow"} $args{"shallow_body"}
Truth table33%1/3
A or B
A= $args{"shallow"}B= $args{"shallow_body"}
ABresult
1X1
011
000
97  
98 13 my $clone = Mail::Message->new
99 ( head => $head
100 , body => $body
101 , $self->logSettings
102 );
103  
104 13 my $labels = $self->labels;
105 13 my %labels = %$labels;
106 13 delete $labels{deleted};
107  
108 13 $clone->{MM_labels} = \%labels;
109  
110 13 $clone->{MM_cloned} = $self;
111 13 weaken($clone->{MM_cloned});
112  
113 13 $clone;
114 }
115  
116 #------------------------------------------
117  
118  
119 44 ▶sub messageId() { $_[0]->{MM_message_id} || $_[0]->takeMessageId}
Subroutine messageId: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"MM_message_id"} or $_[0]->takeMessageId 0 44 44
120 0 ▶sub messageID() {shift->messageId} # compatibility
Subroutine messageID: not called CC=1 SCAR=6.9
Pod undocumented
121  
122  
123 sub container() { undef } # overridden by Mail::Message::Part
124  
125  
126 sub isPart() { 0 } # overridden by Mail::Message::Part
127  
128  
129 sub partNumber()
130 5 ▶{ my $self = shift;
Subroutine partNumber: called CC=2 SCAR=7.1
Pod documented
131 5 my $cont = $self->container;
132 5 ▶ $cont ? $cont->partNumber : undef;
Branch: 1 branch
BranchTrueFalseTotal
$cont ? : 0 5 5
133 }
134  
135  
136 10 ▶sub toplevel() { shift } # overridden by Mail::Message::Part
Subroutine toplevel: called CC=1 SCAR=0.0
Pod documented
137  
138  
139 sub isDummy() { 0 }
140  
141  
142 sub print(;$)
143 31 ▶{ my $self = shift;
Subroutine print: called CC=3 SCAR=11.6
Pod documented
144 31 ▶ my $out = shift || select;
Condition33%1/3
shift() || select()
l!l&&r!l&&!r
3100
MC/DC0%0/2
shift() || select()
shift() select()
Truth table33%1/3
A || B
A= shift()B= select()
ABresult
1X1
011
000
145  
146 31 $self->head->print($out);
147 31 my $body = $self->body;
148 31 ▶ $body->print($out) if $body;
Branch: 1 branch
BranchTrueFalseTotal
if $body 31 0 31
149 31 $self;
150 }
151  
152  
153 sub write(;$)
154 0 ▶{ my $self = shift;
Subroutine write: not called CC=2 SCAR=17.9
Pod documented
155 0 ▶ my $out = shift || select;
Condition0%0/3
shift() || select()
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || select()
shift() select()
Truth table0%0/3
A || B
A= shift()B= select()
ABresult
1X1
011
000
156  
157 0 $self->head->print($out);
158 0 $self->body->print($out);
159 0 $self;
160 }
161  
162  
163 34 my $default_mailer;
164  
165 sub send(@)
166 0 ▶{ my $self = shift;
Subroutine send: not called CC=6 SCAR=37.4
Pod documented
167  
168 # Loosely coupled module
169 0 require Mail::Transport::Send;
170  
171 0 my $mailer;
172 0 ▶ $default_mailer = $mailer = shift
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] and $_[0]->isa("Mail::Transport::Send") 0 0 0
Condition0%0/3
ref $_[0] and $_[0]->isa("Mail::Transport::Send")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[0] and $_[0]->isa("Mail::Transport::Send")
ref $_[0] $_[0]->isa("Mail::Transport::Send")
Truth table0%0/3
A and B
A= ref $_[0]B= $_[0]->isa("Mail::Transport::Send")
ABresult
0X0
100
111
173 if ref $_[0] && $_[0]->isa('Mail::Transport::Send');
174  
175 0 my %args = @_;
176 0 ▶ if( ! $args{via} && defined $default_mailer )
Branch: 1 branch
BranchTrueFalseTotal
if (not $args{'via'} and defined $default_mailer) { } 0 0 0
Condition0%0/3
not $args{"via"} and defined $default_mailer
!ll&&!rl&&r
000
MC/DC0%0/2
not $args{"via"} and defined $default_mailer
not $args{"via"} defined $default_mailer
Truth table0%0/3
not(A) and B
A= not $args{"via"}B= defined $default_mailer
ABresult
0X0
100
111
177 0 { $mailer = $default_mailer;
178 }
179 else
180 0 ▶ { my $via = delete $args{via} || 'sendmail';
Condition0%0/2
delete $args{'via'} || 'sendmail'
l!l
00
MC/DC0%0/1
delete $args{'via'} || 'sendmail'
delete $args{'via'}
Truth table0%0/2
A
A= delete $args{'via'}
Aresult
11
00
181 0 $default_mailer = $mailer = Mail::Transport->new(via => $via, %args);
182 }
183  
184 0 $mailer->send($self, %args);
185 }
186  
187  
188 sub size()
189 62 ▶{ my $self = shift;
Subroutine size: called CC=1 SCAR=0.0
Pod documented
190 62 $self->head->size + $self->body->size;
191 }
192  
193 #------------------------------------------
194  
195  
196 sub head(;$)
197 1081 ▶{ my $self = shift;
Subroutine head: called CC=8 SCAR=24.7
Pod documented
198 1081 ▶ return $self->{MM_head} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 937 144 1081
199  
200 144 my $head = shift;
201 144 ▶ unless(defined $head)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $head) 0 144 144
202 0 { delete $self->{MM_head};
203 0 return undef;
204 }
205  
206 144 ▶ $self->log(INTERNAL => "wrong type of head ($head) for message $self")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $head and $head->isa("Mail::Message::Head") 0 144 144
Condition33%1/3
ref $head and $head->isa("Mail::Message::Head")
!ll&&!rl&&r
00144
MC/DC0%0/2
ref $head and $head->isa("Mail::Message::Head")
ref $head $head->isa("Mail::Message::Head")
Truth table33%1/3
A and B
A= ref $headB= $head->isa("Mail::Message::Head")
ABresult
0X0
100
111
207 unless ref $head && $head->isa('Mail::Message::Head');
208  
209 144 $head->message($self);
210  
211 144 ▶ if(my $old = $self->{MM_head})
Branch: 1 branch
BranchTrueFalseTotal
if (my $old = $self->{"MM_head"}) 0 144 144
212 0 ▶ { $self->{MM_modified}++ unless $old->isDelayed;
Branch: 1 branch
BranchTrueFalseTotal
unless $old->isDelayed 0 0 0
213 }
214  
215 144 $self->{MM_head} = $head;
216  
217 144 ▶ $self->takeMessageId unless $head->isDelayed;
Branch: 1 branch
BranchTrueFalseTotal
unless $head->isDelayed 144 0 144
218  
219 144 $head;
220 }
221  
222  
223 sub get($)
224 194 ▶{ my $self = shift;
Subroutine get: called CC=2 SCAR=6.9
Pod documented
225 194 ▶ my $field = $self->head->get(shift) || return undef;
Condition100%2/2
$self->head->get(shift()) || (return undef)
l!l
71123
MC/DC100%1/1
$self->head->get(shift()) || (return undef)
$self->head->get(shift())
Truth table100%2/2
A
A= $self->head->get(shift())
Aresult
11
00
226 71 $field->body;
227 }
228  
229  
230 sub study($)
231 0 ▶{ my $head = shift->head or return;
Subroutine study: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $head = (shift())->head or return 0 0 0
232 0 scalar $head->study(@_); # return only last
233 }
234  
235  
236 sub from()
237 0 ▶{ my @from = shift->head->get('From') or return ();
Subroutine from: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my(@from) = (shift())->head->get("From") or return () 0 0 0
238 0 map $_->addresses, @from;
239 }
240  
241  
242 sub sender()
243 0 ▶{ my $self = shift;
Subroutine sender: not called CC=3 SCAR=24.8
Pod documented
244 0 ▶ my $sender = $self->head->get('Sender') || $self->head->get('From')
Condition0%0/5
$self->head->get('Sender') || $self->head->get('From') || (return ())
l!l
00
$self->head->get("Sender") or $self->head->get("From")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->head->get('Sender') || $self->head->get('From') || (return ())
$self->head->get("Sender") $self->head->get("From")
Truth table0%0/3
A or B
A= $self->head->get("Sender")B= $self->head->get("From")
ABresult
1X1
011
000
245 || return ();
246  
247 0 ($sender->addresses)[0]; # first specified address
248 }
249  
250  
251 10 ▶sub to() { map $_->addresses, shift->head->get('To') }
Subroutine to: called CC=1 SCAR=0.0
Pod documented
252  
253  
254 2 ▶sub cc() { map $_->addresses, shift->head->get('Cc') }
Subroutine cc: called CC=1 SCAR=0.0
Pod documented
255  
256  
257 0 ▶sub bcc() { map $_->addresses, shift->head->get('Bcc') }
Subroutine bcc: not called CC=1 SCAR=6.9
Pod documented
258  
259  
260 sub destinations()
261 0 ▶{ my $self = shift;
Subroutine destinations: not called CC=1 SCAR=6.9
Pod documented
262 0 my %to = map +(lc($_->address) => $_), $self->to, $self->cc, $self->bcc;
263 0 values %to;
264 }
265  
266  
267 sub subject()
268 16 ▶{ my $subject = shift->get('subject');
Subroutine subject: called CC=2 SCAR=6.9
Pod documented
269 16 ▶ defined $subject ? $subject : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $subject ? : 12 4 16
270 }
271  
272  
273 0 ▶sub guessTimestamp() {shift->head->guessTimestamp}
Subroutine guessTimestamp: not called CC=1 SCAR=6.9
Pod documented
274  
275  
276 sub timestamp()
277 2 ▶{ my $head = shift->head;
Subroutine timestamp: called CC=2 SCAR=7.2
Pod documented
278 2 ▶ $head->recvstamp || $head->timestamp;
Branch: 1 branch
BranchTrueFalseTotal
$head->recvstamp or $head->timestamp 2 0 2
279 }
280  
281  
282 sub nrLines()
283 46 ▶{ my $self = shift;
Subroutine nrLines: called CC=1 SCAR=0.0
Pod documented
284 46 $self->head->nrLines + $self->body->nrLines;
285 }
286  
287 #-------------------------------------------
288  
289
290 sub body(;$@)
291 566 ▶{ my $self = shift;
Subroutine body: called CC=11 SCAR=28.1
Pod documented
292 566 ▶ return $self->{MM_body} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 476 90 566
293  
294 90 my $head = $self->head;
295 90 ▶ $head->removeContentInfo if defined $head;
Branch: 1 branch
BranchTrueFalseTotal
if defined $head 90 0 90
296  
297 90 my ($rawbody, %args) = @_;
298 90 ▶ unless(defined $rawbody)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rawbody) 0 90 90
299 { # Disconnect body from message.
300 0 my $body = delete $self->{MM_body};
301 0 ▶ $body->message(undef) if defined $body;
Branch: 1 branch
BranchTrueFalseTotal
if defined $body 0 0 0
302 0 return $body;
303 }
304  
305 90 ▶ ref $rawbody && $rawbody->isa('Mail::Message::Body')
Branch: 1 branch
BranchTrueFalseTotal
ref $rawbody and $rawbody->isa("Mail::Message::Body") or $self->log("INTERNAL", "wrong type of body for message $rawbody") 0 90 90
Condition33%1/3
ref $rawbody and $rawbody->isa("Mail::Message::Body")
!ll&&!rl&&r
0090
MC/DC0%0/2
ref $rawbody and $rawbody->isa("Mail::Message::Body")
ref $rawbody $rawbody->isa("Mail::Message::Body")
Truth table33%1/3
A and B
A= ref $rawbodyB= $rawbody->isa("Mail::Message::Body")
ABresult
0X0
100
111
306 or $self->log(INTERNAL => "wrong type of body for message $rawbody");
307  
308 # Bodies of real messages must be encoded for safe transmission.
309 # Message parts will get encoded on the moment the whole multipart
310 # is transformed into a real message.
311  
312 90 ▶ my $body = $self->isPart ? $rawbody : $rawbody->encoded;
Branch: 1 branch
BranchTrueFalseTotal
$self->isPart ? : 49 41 90
313 90 $body->contentInfoTo($self->head);
314  
315 90 my $oldbody = $self->{MM_body};
316 90 ▶ return $body if defined $oldbody && $body==$oldbody;
Branch: 1 branch
BranchTrueFalseTotal
if defined $oldbody and $body == $oldbody 0 90 90
Condition33%1/3
defined $oldbody and $body == $oldbody
!ll&&!rl&&r
9000
MC/DC0%0/2
defined $oldbody and $body == $oldbody
defined $oldbody $body == $oldbody
Truth table33%1/3
A and B
A= defined $oldbodyB= $body == $oldbody
ABresult
0X0
100
111
317  
318 90 $body->message($self);
319 90 ▶ $body->modified(1) if defined $oldbody;
Branch: 1 branch
BranchTrueFalseTotal
if defined $oldbody 0 90 90
320  
321 90 $self->{MM_body} = $body;
322 }
323  
324  
325 sub decoded(@)
326 2 ▶{ my $body = shift->body->load;
Subroutine decoded: called CC=2 SCAR=7.2
Pod documented
327 2 ▶ $body ? $body->decoded(@_) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$body ? : 2 0 2
328 }
329  
330  
331 sub encode(@)
332 0 ▶{ my $body = shift->body->load;
Subroutine encode: not called CC=2 SCAR=17.9
Pod documented
333 0 ▶ $body ? $body->encode(@_) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$body ? : 0 0 0
334 }
335  
336  
337 131 ▶sub isMultipart() {shift->head->isMultipart}
Subroutine isMultipart: called CC=1 SCAR=0.0
Pod documented
338  
339  
340 61 ▶sub isNested() {shift->body->isNested}
Subroutine isNested: called CC=1 SCAR=0.0
Pod documented
341  
342  
343 sub contentType()
344 1 ▶{ my $head = shift->head;
Subroutine contentType: called CC=4 SCAR=14.9
Pod documented
345 1 ▶ my $ct = (defined $head ? $head->get('Content-Type', 0) : undef) || '';
Branch: 1 branch
BranchTrueFalseTotal
defined $head ? : 1 0 1
Condition50%1/2
(defined $head ? $head->get('Content-Type', 0) : undef) || ''
l!l
10
MC/DC0%0/1
(defined $head ? $head->get('Content-Type', 0) : undef) || ''
(defined $head ? $head->get('Content-Type', 0) : undef)
Truth table50%1/2
A
A= (defined $head ? $head->get('Content-Type', 0) : undef)
Aresult
11
00
346 1 $ct =~ s/\s*\;.*//;
347 1 ▶ length $ct ? $ct : 'text/plain';
Branch: 1 branch
BranchTrueFalseTotal
length $ct ? : 1 0 1
348 }
349  
350  
351 sub parts(;$)
352 27 ▶{ my $self = shift;
Subroutine parts: called CC=11 SCAR=30.7
Pod documented
353 27 ▶ my $what = shift || 'ACTIVE';
Condition100%2/2
shift() || 'ACTIVE'
l!l
189
MC/DC100%1/1
shift() || 'ACTIVE'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
354  
355 27 my $body = $self->body;
356 27 ▶ my $recurse = $what eq 'RECURSE' || ref $what;
Condition33%1/3
$what eq 'RECURSE' || ref $what
l!l&&r!l&&!r
0027
MC/DC0%0/2
$what eq 'RECURSE' || ref $what
$what eq 'RECURSE' ref $what
Truth table33%1/3
A || B
A= $what eq 'RECURSE'B= ref $what
ABresult
1X1
011
000
357  
358 my @parts
359 27 ▶ = $body->isNested ? $body->nested->parts($what)
Branch: 3 branches
BranchTrueFalseTotal
$body->isNested ? : 2 25 27
$body->isMultipart ? : 25 0 25
$recurse ? : 0 25 25
360 : $body->isMultipart ? $body->parts($recurse ? 'RECURSE' : ())
361 : $self;
362  
363 27 ▶ ref $what eq 'CODE' ? (grep $what->($_), @parts)
Branch: 5 branches
BranchTrueFalseTotal
ref $what eq 'CODE' ? : 0 27 27
$what eq 'ACTIVE' ? : 27 0 27
$what eq 'DELETED' ? : 0 0 0
$what eq 'ALL' ? : 0 0 0
$recurse ? : 0 0 0
364 : $what eq 'ACTIVE' ? (grep !$_->isDeleted, @parts)
365 : $what eq 'DELETED' ? (grep $_->isDeleted, @parts)
366 : $what eq 'ALL' ? @parts
367 : $recurse ? @parts
368 : confess "Select parts via $what?";
369 }
370  
371 #------------------------------------------
372  
373  
374 sub modified(;$)
375 0 ▶{ my $self = shift;
Subroutine modified: not called CC=4 SCAR=30.0
Pod documented
376  
377 0 ▶ return $self->isModified unless @_; # compatibility 2.036
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
378  
379 0 my $flag = shift;
380 0 $self->{MM_modified} = $flag;
381 0 my $head = $self->head;
382 0 ▶ $head->modified($flag) if $head;
Branch: 1 branch
BranchTrueFalseTotal
if $head 0 0 0
383 0 my $body = $self->body;
384 0 ▶ $body->modified($flag) if $body;
Branch: 1 branch
BranchTrueFalseTotal
if $body 0 0 0
385  
386 0 $flag;
387 }
388  
389  
390 sub isModified()
391 0 ▶{ my $self = shift;
Subroutine isModified: not called CC=6 SCAR=37.4
Pod documented
392 0 ▶ return 1 if $self->{MM_modified};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MM_modified"} 0 0 0
393  
394 0 my $head = $self->head;
395 0 ▶ if($head && $head->isModified)
Branch: 1 branch
BranchTrueFalseTotal
if ($head and $head->isModified) 0 0 0
Condition0%0/3
$head and $head->isModified
!ll&&!rl&&r
000
MC/DC0%0/2
$head and $head->isModified
$head $head->isModified
Truth table0%0/3
A and B
A= $headB= $head->isModified
ABresult
0X0
100
111
396 0 { $self->{MM_modified}++;
397 0 return 1;
398 }
399  
400 0 my $body = $self->body;
401 0 ▶ if($body && $body->isModified)
Branch: 1 branch
BranchTrueFalseTotal
if ($body and $body->isModified) 0 0 0
Condition0%0/3
$body and $body->isModified
!ll&&!rl&&r
000
MC/DC0%0/2
$body and $body->isModified
$body $body->isModified
Truth table0%0/3
A and B
A= $bodyB= $body->isModified
ABresult
0X0
100
111
402 0 { $self->{MM_modified}++;
403 0 return 1;
404 }
405  
406 0 0;
407 }
408  
409  
410 sub label($;$@)
411 291 ▶{ my $self = shift;
Subroutine label: called CC=2 SCAR=6.9
Pod documented
412 291 ▶ return $self->{MM_labels}{$_[0]} unless @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 1 274 17 291
413 17 my $return = $_[1];
414  
415 17 my %labels = @_;
416 17 @{$self->{MM_labels}}{keys %labels} = values %labels;
417 17 $return;
418 }
419  
420  
421 sub labels()
422 13 ▶{ my $self = shift;
Subroutine labels: called CC=2 SCAR=8.1
Pod documented
423 13 ▶ wantarray ? keys %{$self->{MM_labels}} : $self->{MM_labels};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 13 13
424 }
425  
426  
427 264 ▶sub isDeleted() { shift->label('deleted') }
Subroutine isDeleted: called CC=1 SCAR=0.0
Pod documented
428  
429  
430 sub delete()
431 4 ▶{ my $self = shift;
Subroutine delete: called CC=2 SCAR=7.1
Pod documented
432 4 my $old = $self->label('deleted');
433 4 ▶ $old || $self->label(deleted => time);
Branch: 1 branch
BranchTrueFalseTotal
$old or $self->label("deleted", time) 4 0 4
434 }
435  
436  
437 sub deleted(;$)
438 2 ▶{ my $self = shift;
Subroutine deleted: called CC=2 SCAR=7.2
Pod documented
439  
440 2 ▶ @_ ? $self->label(deleted => shift)
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 0 2
441 : $self->label('deleted') # compat 2.036
442 }
443  
444  
445 sub labelsToStatus()
446 0 ▶{ my $self = shift;
Subroutine labelsToStatus: not called CC=9 SCAR=45.0
Pod documented
447 0 my $head = $self->head;
448 0 my $labels = $self->labels;
449  
450 0 ▶ my $status = $head->get('status') || '';
Condition0%0/2
$head->get('status') || ''
l!l
00
MC/DC0%0/1
$head->get('status') || ''
$head->get('status')
Truth table0%0/2
A
A= $head->get('status')
Aresult
11
00
451 my $newstatus
452 = $labels->{seen} ? 'RO'
453 0 ▶ : $labels->{old} ? 'O'
Branch: 2 branches
BranchTrueFalseTotal
$labels->{'seen'} ? : 0 0 0
$labels->{'old'} ? : 0 0 0
454 : '';
455  
456 0 ▶ $head->set(Status => $newstatus)
Branch: 1 branch
BranchTrueFalseTotal
if $newstatus ne $status 0 0 0
457 if $newstatus ne $status;
458  
459 0 ▶ my $xstatus = $head->get('x-status') || '';
Condition0%0/2
$head->get('x-status') || ''
l!l
00
MC/DC0%0/1
$head->get('x-status') || ''
$head->get('x-status')
Truth table0%0/2
A
A= $head->get('x-status')
Aresult
11
00
460 my $newxstatus
461 = ($labels->{replied} ? 'A' : '')
462 0 ▶ . ($labels->{flagged} ? 'F' : '');
Branch: 2 branches
BranchTrueFalseTotal
$labels->{'replied'} ? : 0 0 0
$labels->{'flagged'} ? : 0 0 0
463  
464 0 ▶ $head->set('X-Status' => $newxstatus)
Branch: 1 branch
BranchTrueFalseTotal
if $newxstatus ne $xstatus 0 0 0
465 if $newxstatus ne $xstatus;
466  
467 0 $self;
468 }
469  
470  
471 sub statusToLabels()
472 0 ▶{ my $self = shift;
Subroutine statusToLabels: not called CC=3 SCAR=24.8
Pod documented
473 0 my $head = $self->head;
474  
475 0 ▶ if(my $status = $head->get('status'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $status = $head->get("status")) 0 0 0
476 0 { $status = $status->foldedBody;
477 0 $self->label
478 ( seen => (index($status, 'R') >= 0)
479 , old => (index($status, 'O') >= 0)
480 );
481 }
482  
483 0 ▶ if(my $xstatus = $head->get('x-status'))
Branch: 1 branch
BranchTrueFalseTotal
if (my $xstatus = $head->get("x-status")) 0 0 0
484 0 { $xstatus = $xstatus->foldedBody;
485 0 $self->label
486 ( replied => (index($xstatus, 'A') >= 0)
487 , flagged => (index($xstatus, 'F') >= 0)
488 );
489 }
490  
491 0 $self;
492 }
493  
494 #------------------------------------------
495  
496  
497 my $mail_internet_converter;
498 34 my $mime_entity_converter;
499 34 my $email_simple_converter;
500  
501 sub coerce($@)
502 13 ▶{ my ($class, $message) = @_;
Subroutine coerce: called CC=18 SCAR=53.6
Pod documented
503  
504 13 ▶ blessed $message
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($message) or die "coercion starts with some object" 0 13 13
505 or die "coercion starts with some object";
506  
507 13 ▶ return $message
Branch: 1 branch
BranchTrueFalseTotal
if ref $message eq $class 0 13 13
508 if ref $message eq $class;
509  
510 13 ▶ if($message->isa(__PACKAGE__)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($message->isa(__PACKAGE__)) 13 0 13
511 13 $message->head->modified(1);
512 13 $message->body->modified(1);
513 13 return bless $message, $class;
514 }
515  
516 0 ▶ if($message->isa('MIME::Entity'))
Branch: 4 branches
BranchTrueFalseTotal
if ($message->isa('MIME::Entity')) { } 0 0 0
elsif ($message->isa('Mail::Internet')) { } 0 0 0
elsif ($message->isa('Email::Simple')) { } 0 0 0
elsif ($message->isa('Email::Abstract')) { } 0 0 0
517 0 ▶ { unless($mime_entity_converter)
Branch: 1 branch
BranchTrueFalseTotal
unless ($mime_entity_converter) 0 0 0
518 0 { eval {require Mail::Message::Convert::MimeEntity};
519 0 ▶ confess "Install MIME::Entity" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
520 0 $mime_entity_converter = Mail::Message::Convert::MimeEntity->new;
521 }
522  
523 0 ▶ $message = $mime_entity_converter->from($message)
Branch: 1 branch
BranchTrueFalseTotal
$message = $mime_entity_converter->from($message) or return 0 0 0
524 or return;
525 }
526  
527 elsif($message->isa('Mail::Internet'))
528 0 ▶ { unless($mail_internet_converter)
Branch: 1 branch
BranchTrueFalseTotal
unless ($mail_internet_converter) 0 0 0
529 0 { eval {require Mail::Message::Convert::MailInternet};
530 0 ▶ confess "Install Mail::Internet" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
531 0 $mail_internet_converter = Mail::Message::Convert::MailInternet->new;
532 }
533  
534 0 ▶ $message = $mail_internet_converter->from($message)
Branch: 1 branch
BranchTrueFalseTotal
$message = $mail_internet_converter->from($message) or return 0 0 0
535 or return;
536 }
537  
538 elsif($message->isa('Email::Simple'))
539 0 ▶ { unless($email_simple_converter)
Branch: 1 branch
BranchTrueFalseTotal
unless ($email_simple_converter) 0 0 0
540 0 { eval {require Mail::Message::Convert::EmailSimple};
541 0 ▶ confess "Install Email::Simple" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
542 0 $email_simple_converter = Mail::Message::Convert::EmailSimple->new;
543 }
544  
545 0 ▶ $message = $email_simple_converter->from($message)
Branch: 1 branch
BranchTrueFalseTotal
$message = $email_simple_converter->from($message) or return 0 0 0
546 or return;
547 }
548  
549 elsif($message->isa('Email::Abstract'))
550 0 { return $class->coerce($message->object);
551 }
552  
553 else
554 0 { $class->log(INTERNAL => "Cannot coerce a ". ref($message)
555 . " object into a ". __PACKAGE__." object");
556 }
557  
558 0 ▶ $message->{MM_modified} ||= 0;
Condition0%0/2
$message->{"MM_modified"} ||= 0
l!l
00
MC/DC0%0/1
$message->{"MM_modified"} ||= 0
$message->{"MM_modified"}
Truth table0%0/2
A
A= $message->{"MM_modified"}
Aresult
11
00
559 0 bless $message, $class;
560 }
561  
562  
563 0 ▶sub clonedFrom() { shift->{MM_cloned} }
Subroutine clonedFrom: not called CC=1 SCAR=6.9
Pod documented
564  
565 #------------------------------------------
566 # All next routines try to create compatibility with release < 2.0
567 0 ▶sub isParsed() { not shift->isDelayed }
Subroutine isParsed: not called CC=1 SCAR=6.9
Pod undocumented
568 0 ▶sub headIsRead() { not shift->head->isDelayed }
Subroutine headIsRead: not called CC=1 SCAR=6.9
Pod undocumented
569  
570  
571 sub readFromParser($;$)
572 12 ▶{ my ($self, $parser, $bodytype) = @_;
Subroutine readFromParser: called CC=3 SCAR=11.6
Pod documented
573  
574 my $head = $self->readHead($parser)
575 || Mail::Message::Head::Complete->new
576 ( message => $self
577 , field_type => $self->{MM_field_type}
578 12 ▶ , $self->logSettings
Condition33%1/3
$self->readHead($parser) || 'Mail::Message::Head::Complete'->new('message', $self, 'field_type', $self->{'MM_field_type'}, $self->logSettings)
l!l&&r!l&&!r
1200
MC/DC0%0/2
$self->readHead($parser) || 'Mail::Message::Head::Complete'->new('message', $self, 'field_type', $self->{'MM_field_type'}, $self->logSettings)
$self->readHead($parser) 'Mail::Message::Head::Complete'->new('message', $self, 'field_type', $self->{'MM_field_type'}, $self->logSettings)
Truth table33%1/3
A || B
A= $self->readHead($parser)B= 'Mail::Message::Head::Complete'->new('message', $self, 'field_type', $self->{'MM_field_type'}, $self->logSettings)
ABresult
1X1
011
000
579 );
580  
581 12 ▶ my $body = $self->readBody($parser, $head, $bodytype)
Branch: 1 branch
BranchTrueFalseTotal
my $body = $self->readBody($parser, $head, $bodytype) or return 0 12 12
582 or return;
583  
584 12 $self->head($head);
585 12 $self->storeBody($body);
586 12 $self;
587 }
588  
589  
590 sub readHead($;$)
591 26 ▶{ my ($self, $parser) = (shift, shift);
Subroutine readHead: called CC=3 SCAR=12.5
Pod documented
592  
593 my $headtype = shift
594 26 ▶ || $self->{MM_head_type} || 'Mail::Message::Head::Complete';
Condition40%2/5
shift() || $self->{'MM_head_type'} || 'Mail::Message::Head::Complete'
l!l
026
shift() or $self->{"MM_head_type"}
l!l&&r!l&&!r
0026
MC/DC0%0/2
shift() || $self->{'MM_head_type'} || 'Mail::Message::Head::Complete'
shift() $self->{"MM_head_type"}
Truth table33%1/3
A or B
A= shift()B= $self->{"MM_head_type"}
ABresult
1X1
011
000
595  
596 $headtype->new
597 ( message => $self
598 , field_type => $self->{MM_field_type}
599 26 , $self->logSettings
600 )->read($parser);
601 }
602  
603  
604 sub readBody($$;$$)
605 26 ▶{ my ($self, $parser, $head, $getbodytype) = @_;
Subroutine readBody: called CC=13 SCAR=26.9
Pod documented
606  
607 my $bodytype
608 26 ▶ = ! $getbodytype ? ($self->{MM_body_type} || 'Mail::Message::Body::Lines')
Branch: 2 branches
BranchTrueFalseTotal
!$getbodytype ? : 26 0 26
ref $getbodytype ? : 0 0 0
Condition50%1/2
$self->{"MM_body_type"} or "Mail::Message::Body::Lines"
l!l
026
MC/DC0%0/1
$self->{"MM_body_type"} or "Mail::Message::Body::Lines"
$self->{"MM_body_type"}
Truth table50%1/2
A
A= $self->{"MM_body_type"}
Aresult
11
00
609 : ref $getbodytype ? $getbodytype->($self, $head)
610 : $getbodytype;
611  
612 26 my $body;
613 26 ▶ if($bodytype->isDelayed)
Branch: 1 branch
BranchTrueFalseTotal
if ($bodytype->isDelayed) { } 0 26 26
614 0 { $body = $bodytype->new
615 ( message => $self
616 , charset => undef # we do not know, autodetect after transfer decode
617 , $self->logSettings
618 );
619 }
620 else
621 26 { my $ct = $head->get('Content-Type', 0);
622 26 ▶ my $type = defined $ct ? lc($ct->body) : 'text/plain';
Branch: 1 branch
BranchTrueFalseTotal
defined $ct ? : 20 6 26
623  
624 # Be sure you have acceptable bodies for multiparts and nested.
625 26 ▶ if(substr($type, 0, 10) eq 'multipart/' && !$bodytype->isMultipart)
Branch: 2 branches
BranchTrueFalseTotal
if (substr($type, 0, 10) eq 'multipart/' and not $bodytype->isMultipart) { } 7 19 26
elsif ($type eq 'message/rfc822') { } 2 17 19
Condition66%2/3
substr($type, 0, 10) eq "multipart/" and not $bodytype->isMultipart
!ll&&!rl&&r
1907
MC/DC50%1/2
substr($type, 0, 10) eq "multipart/" and not $bodytype->isMultipart
substr($type, 0, 10) eq "multipart/" not $bodytype->isMultipart
Truth table66%2/3
A and not(B)
A= substr($type, 0, 10) eq "multipart/"B= not $bodytype->isMultipart
ABresult
0X0
100
111
626 7 { $bodytype = 'Mail::Message::Body::Multipart';
627 }
628 elsif($type eq 'message/rfc822')
629 2 ▶ { my $enc = $head->get('Content-Transfer-Encoding') || 'none';
Condition100%2/2
$head->get('Content-Transfer-Encoding') || 'none'
l!l
11
MC/DC100%1/1
$head->get('Content-Transfer-Encoding') || 'none'
$head->get('Content-Transfer-Encoding')
Truth table100%2/2
A
A= $head->get('Content-Transfer-Encoding')
Aresult
11
00
630 2 ▶ $bodytype = 'Mail::Message::Body::Nested'
Branch: 1 branch
BranchTrueFalseTotal
if lc $enc eq "none" and not $bodytype->isNested 1 1 2
Condition66%2/3
lc $enc eq "none" and not $bodytype->isNested
!ll&&!rl&&r
101
MC/DC50%1/2
lc $enc eq "none" and not $bodytype->isNested
lc $enc eq "none" not $bodytype->isNested
Truth table66%2/3
A and not(B)
A= lc $enc eq "none"B= not $bodytype->isNested
ABresult
0X0
100
111
631 if lc($enc) eq 'none' && ! $bodytype->isNested;
632 }
633  
634 $body = $bodytype->new
635 ( message => $self
636 , checked => $self->{MM_trusted}
637 26 , charset => undef
638 , $self->logSettings
639 );
640  
641 26 $body->contentInfoFrom($head);
642 }
643  
644 26 my $lines = $head->get('Lines'); # usually off-by-one
645 26 my $size = $head->guessBodySize;
646  
647 26 ▶ $body->read
Branch: 1 branch
BranchTrueFalseTotal
defined $lines ? : 0 26 26
648 ( $parser, $head, $getbodytype,
649 , $size, (defined $lines ? $lines : undef)
650 );
651 }
652  
653  
654 sub storeBody($)
655 26 ▶{ my ($self, $body) = @_;
Subroutine storeBody: called CC=1 SCAR=0.0
Pod documented
656 26 $self->{MM_body} = $body;
657 26 $body->message($self);
658 26 $body;
659 }
660  
661  
662 sub isDelayed()
663 0 ▶{ my $body = shift->body;
Subroutine isDelayed: not called CC=2 SCAR=17.9
Pod documented
664 0 ▶ !$body || $body->isDelayed;
Branch: 1 branch
BranchTrueFalseTotal
not $body or $body->isDelayed 0 0 0
665 }
666  
667  
668 sub takeMessageId(;$)
669 158 ▶{ my $self = shift;
Subroutine takeMessageId: called CC=5 SCAR=16.1
Pod documented
670 158 ▶ my $msgid = (@_ ? shift : $self->get('Message-ID')) || '';
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 158 158
Condition100%2/2
(@_ ? shift() : $self->get('Message-ID')) || ''
l!l
45113
MC/DC100%1/1
(@_ ? shift() : $self->get('Message-ID')) || ''
(@_ ? shift() : $self->get('Message-ID'))
Truth table100%2/2
A
A= (@_ ? shift() : $self->get('Message-ID'))
Aresult
11
00
671  
672 158 ▶ if($msgid =~ m/\<([^>]*)\>/s)
Branch: 1 branch
BranchTrueFalseTotal
if ($msgid =~ /\<([^>]*)\>/s) 45 113 158
673 45 { $msgid = $1;
674 45 $msgid =~ s/\s//gs;
675 }
676
677 158 ▶ $msgid = $self->head->createMessageId
Branch: 1 branch
BranchTrueFalseTotal
unless length $msgid 113 45 158
678 unless length $msgid;
679  
680 158 $self->{MM_message_id} = $msgid;
681 }
682  
683 #------------------------------------------
684  
685  
686 sub shortSize(;$)
687 0 ▶{ my $self = shift;
Subroutine shortSize: not called CC=7 SCAR=40.3
Pod documented
688 0 my $size = shift;
689 0 ▶ $size = $self->head->guessBodySize unless defined $size;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size 0 0 0
690  
691 0 ▶ !defined $size ? '?'
Branch: 5 branches
BranchTrueFalseTotal
!defined($size) ? : 0 0 0
$size < 1000 ? : 0 0 0
$size < 10000 ? : 0 0 0
$size < 1000000 ? : 0 0 0
$size < 10000000 ? : 0 0 0
692 : $size < 1_000 ? sprintf "%3d " , $size
693 : $size < 10_000 ? sprintf "%3.1fK", $size/1024
694 : $size < 1_000_000 ? sprintf "%3.0fK", $size/1024
695 : $size < 10_000_000 ? sprintf "%3.1fM", $size/(1024*1024)
696 : sprintf "%3.0fM", $size/(1024*1024);
697 }
698  
699  
700 sub shortString()
701 0 ▶{ my $self = shift;
Subroutine shortString: not called CC=1 SCAR=6.9
Pod documented
702 0 sprintf "%4s %-30.30s", $self->shortSize, $self->subject;
703 }
704  
705 #------------------------------------------
706  
707  
708 0 ▶sub destruct() { $_[0] = undef }
Subroutine destruct: not called CC=1 SCAR=6.9
Pod documented
709  
710 #------------------------------------------
711  
712  
713 34 1;
« Message/Replace/MailInternet.pm ↑ Summary Message/Replace/MailHeader.pm »