Message/Construct/Forward.pm

filter: Statementstmt 93.1% 108 / 116 Branchbran 58.9% 46 / 78 Conditioncond 47.6% 20 / 42 MC/DCmcdc 19.2% 5 / 26 Subroutinesub 100% 15 / 15 Podpod 100% 8 / 8 totaltotal 70.8% 202 / 285 SCAR 47.0
CC
55
Cov
74%
forward
29.2
forwardInline
26.0
forwardNo
19.8
CRAP 109.8
« Message/Head/FieldGroup.pm ↑ Summary Message/Body/File.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 3 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 $VERSION = '3.013';
12  
13  
14 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 ▶use Mail::Message::Body::Multipart;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use Mail::Message::Body::Nested;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 # tests in t/57forw1f.t
23  
24 sub forward(@)
25 3 ▶{ my $self = shift;
Subroutine forward: called CC=8 SCAR=33.8
Pod documented
26 3 my %args = @_;
27  
28 return $self->forwardNo(@_)
29 3 ▶ if exists $args{body};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"body"} 0 3 3
30  
31 3 ▶ my $include = $args{include} || 'INLINE';
Condition50%1/2
$args{'include'} || 'INLINE'
l!l
03
MC/DC0%0/1
$args{'include'} || 'INLINE'
$args{'include'}
Truth table50%1/2
A
A= $args{'include'}
Aresult
11
00
32 3 ▶ return $self->forwardInline(@_) if $include eq 'INLINE';
Branch: 1 branch
BranchTrueFalseTotal
if $include eq "INLINE" 3 0 3
33  
34 0 my $preamble = $args{preamble};
35 0 ▶ push @_, preamble => Mail::Message::Body->new(data => $preamble)
Branch: 1 branch
BranchTrueFalseTotal
if defined $preamble and not ref $preamble 0 0 0
Condition0%0/3
defined $preamble and not ref $preamble
!ll&&!rl&&r
000
MC/DC0%0/2
defined $preamble and not ref $preamble
defined $preamble not ref $preamble
Truth table0%0/3
A and not(B)
A= defined $preambleB= not ref $preamble
ABresult
0X0
100
111
36 if defined $preamble && ! ref $preamble;
37  
38 0 ▶ return $self->forwardAttach(@_) if $include eq 'ATTACH';
Branch: 1 branch
BranchTrueFalseTotal
if $include eq "ATTACH" 0 0 0
39 0 ▶ return $self->forwardEncapsulate(@_) if $include eq 'ENCAPSULATE';
Branch: 1 branch
BranchTrueFalseTotal
if $include eq "ENCAPSULATE" 0 0 0
40  
41 0 $self->log(ERROR => 'Cannot include forward source as $include.');
42 0 undef;
43 }
44  
45 #------------------------------------------
46  
47  
48 sub forwardNo(@)
49 7 ▶{ my ($self, %args) = @_;
Subroutine forwardNo: called CC=15 SCAR=29.9
Pod documented
50  
51 7 my $body = $args{body};
52 7 ▶ $self->log(INTERNAL => "No body supplied for forwardNo()")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $body 0 7 7
53 unless defined $body;
54  
55 #
56 # Collect header info
57 #
58  
59 7 my $mainhead = $self->toplevel->head;
60  
61 # Where it comes from
62 7 my $from = $args{From};
63 7 ▶ unless(defined $from)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $from) 7 0 7
64 7 { my @from = $self->to;
65 7 ▶ $from = \@from if @from;
Branch: 1 branch
BranchTrueFalseTotal
if @from 7 0 7
66 }
67  
68 # To whom to send
69 7 my $to = $args{To};
70 7 ▶ $self->log(ERROR => "No address to create forwarded to."), return
Branch: 1 branch
BranchTrueFalseTotal
unless $to 0 7 7
71 unless $to;
72  
73 # Create a subject
74 7 my $srcsub = $args{Subject};
75 7 ▶ my $subject
Branch: 2 branches
BranchTrueFalseTotal
!defined($srcsub) ? : 7 0 7
ref $srcsub ? : 0 0 0
76 = ! defined $srcsub ? $self->forwardSubject($self->subject)
77 : ref $srcsub ? $srcsub->($self->subject)
78 : $srcsub;
79  
80 # Create a nice message-id
81 7 ▶ my $msgid = $args{'Message-ID'} || $mainhead->createMessageId;
Condition33%1/3
$args{'Message-ID'} || $mainhead->createMessageId
l!l&&r!l&&!r
070
MC/DC0%0/2
$args{'Message-ID'} || $mainhead->createMessageId
$args{'Message-ID'} $mainhead->createMessageId
Truth table33%1/3
A || B
A= $args{'Message-ID'}B= $mainhead->createMessageId
ABresult
1X1
011
000
82 7 ▶ $msgid = "<$msgid>" if $msgid && $msgid !~ /^\s*\<.*\>\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $msgid and not $msgid =~ /^\s*\<.*\>\s*$/ 7 0 7
Condition33%1/3
$msgid and not $msgid =~ /^\s*\<.*\>\s*$/
!ll&&!rl&&r
007
MC/DC0%0/2
$msgid and not $msgid =~ /^\s*\<.*\>\s*$/
$msgid not $msgid =~ /^\s*\<.*\>\s*$/
Truth table33%1/3
A and not(B)
A= $msgidB= not $msgid =~ /^\s*\<.*\>\s*$/
ABresult
0X0
100
111
83  
84 # Thread information
85 7 my $origid = '<'.$self->messageId.'>';
86 7 my $refs = $mainhead->get('references');
87  
88 7 ▶ my $forward = Mail::Message->buildFromBody
Branch: 1 branch
BranchTrueFalseTotal
$refs ? : 0 7 7
Condition50%1/2
$from || '(undisclosed)'
l!l
70
MC/DC0%0/1
$from || '(undisclosed)'
$from
Truth table50%1/2
A
A= $from
Aresult
11
00
89 ( $body
90 , From => ($from || '(undisclosed)')
91 , To => $to
92 , Subject => $subject
93 , References => ($refs ? "$refs $origid" : $origid)
94 );
95  
96 7 my $newhead = $forward->head;
97 7 ▶ $newhead->set(Cc => $args{Cc} ) if $args{Cc};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"Cc"} 1 6 7
98 7 ▶ $newhead->set(Bcc => $args{Bcc} ) if $args{Bcc};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"Bcc"} 1 6 7
99 7 ▶ $newhead->set(Date => $args{Date}) if $args{Date};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"Date"} 0 7 7
100  
101 # Ready
102  
103 7 $self->label(passed => 1);
104 7 $self->log(PROGRESS => "Forward created from $origid");
105 7 $forward;
106 }
107  
108 #------------------------------------------
109  
110  
111 sub forwardInline(@)
112 4 ▶{ my ($self, %args) = @_;
Subroutine forwardInline: called CC=20 SCAR=32.6
Pod documented
113  
114 4 my $body = $self->body;
115  
116 4 while(1) # simplify
117 4 ▶ { if($body->isMultipart && $body->parts==1)
Branch: 2 branches
BranchTrueFalseTotal
if ($body->isMultipart and $body->parts == 1) { } 0 4 4
elsif ($body->isNested) { } 0 4 4
Condition33%1/3
$body->isMultipart and $body->parts == 1
!ll&&!rl&&r
400
MC/DC0%0/2
$body->isMultipart and $body->parts == 1
$body->isMultipart $body->parts == 1
Truth table33%1/3
A and B
A= $body->isMultipartB= $body->parts == 1
ABresult
0X0
100
111
118 0 { $body = $body->part(0)->body }
119 0 elsif($body->isNested) { $body = $body->nested->body }
120 4 else { last }
121 }
122  
123 # Prelude must be a real body, otherwise concatenate will not work
124 my $prelude = exists $args{prelude} ? $args{prelude}
125 4 ▶ : $self->forwardPrelude;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'prelude'} ? : 3 1 4
126  
127 4 ▶ $prelude = Mail::Message::Body->new(data => $prelude)
Branch: 1 branch
BranchTrueFalseTotal
if defined $prelude and not builtin::blessed($prelude) 3 1 4
Condition66%2/3
defined $prelude and not builtin::blessed($prelude)
!ll&&!rl&&r
103
MC/DC50%1/2
defined $prelude and not builtin::blessed($prelude)
defined $prelude not builtin::blessed($prelude)
Truth table66%2/3
A and not(B)
A= defined $preludeB= not builtin::blessed($prelude)
ABresult
0X0
100
111
128 if defined $prelude && ! blessed $prelude;
129
130 # Postlude
131 my $postlude = exists $args{postlude} ? $args{postlude}
132 4 ▶ : $self->forwardPostlude;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'postlude'} ? : 3 1 4
133
134 # Binary bodies cannot be inlined, therefore they will be rewritten
135 # into a forwardAttach... preamble must replace prelude and postlude.
136  
137 4 ▶ if($body->isMultipart || $body->isBinary)
Branch: 1 branch
BranchTrueFalseTotal
if ($body->isMultipart or $body->isBinary) 1 3 4
Condition66%2/3
$body->isMultipart or $body->isBinary
l!l&&r!l&&!r
013
MC/DC50%1/2
$body->isMultipart or $body->isBinary
$body->isMultipart $body->isBinary
Truth table66%2/3
A or B
A= $body->isMultipartB= $body->isBinary
ABresult
1X1
011
000
138 { $args{preamble} ||= $prelude->concatenate
139 ( $prelude
140 1 ▶ , ($args{is_attached} || "[The forwarded message is attached]\n")
Condition40%2/5
$args{"preamble"} ||= $prelude->concatenate($prelude, $args{"is_attached"} || "[The forwarded message is attached]\n", $postlude)
l!l&&r!l&&!r
010
$args{'is_attached'} || "[The forwarded message is attached]\n"
l!l
01
MC/DC0%0/2
$args{"preamble"} ||= $prelude->concatenate($prelude, $args{"is_attached"} || "[The forwarded message is attached]\n", $postlude)
$args{"preamble"} $prelude->concatenate($prelude, $args{"is_attached"} || "[The forwarded message is attached]\n", $postlude)
MC/DC0%0/1
$args{'is_attached'} || "[The forwarded message is attached]\n"
$args{'is_attached'}
Truth table33%1/3
A ||= B
A= $args{"preamble"}B= $prelude->concatenate($prelude, $args{"is_attached"} || "[The forwarded message is attached]\n", $postlude)
ABresult
1X1
011
000
Truth table50%1/2
A
A= $args{'is_attached'}
Aresult
11
00
141 , $postlude
142 );
143 1 return $self->forwardAttach(%args);
144 }
145
146 3 $body = $body->decoded;
147 my $strip = (!exists $args{strip_signature} || $args{strip_signature})
148 3 ▶ && !$body->isNested;
Condition66%4/6
(!exists $args{'strip_signature'} || $args{'strip_signature'}) && !$body->isNested
!ll&&!rl&&r
102
not exists $args{"strip_signature"} or $args{"strip_signature"}
l!l&&r!l&&!r
201
MC/DC33%1/3
(!exists $args{'strip_signature'} || $args{'strip_signature'}) && !$body->isNested
not exists $args{"strip_signature"} $args{"strip_signature"} !$body->isNested
Truth table40%2/5
not(A) or B && not(C)
A= not exists $args{"strip_signature"}B= $args{"strip_signature"}C= !$body->isNested
ABCresult
00X0
1X00
0100
1X11
0111
149  
150 $body = $body->stripSignature
151 ( pattern => $args{strip_signature}
152 , max_lines => $args{max_signature}
153 3 ▶ ) if $strip;
Branch: 1 branch
BranchTrueFalseTotal
if $strip 2 1 3
154  
155 3 ▶ if(defined(my $quote = $args{quote}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $quote = $args{"quote"})) 2 1 3
156 2 ▶ { my $quoting = ref $quote ? $quote : sub {$quote . $_};
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
ref $quote ? : 1 1 2
157 2 $body = $body->foreachLine($quoting);
158 }
159  
160 #
161 # Create the message.
162 #
163  
164 3 my $signature = $args{signature};
165 3 ▶ $signature = $signature->body
Branch: 1 branch
BranchTrueFalseTotal
if defined $signature and $signature->isa("Mail::Message") 0 3 3
Condition33%1/3
defined $signature and $signature->isa("Mail::Message")
!ll&&!rl&&r
300
MC/DC0%0/2
defined $signature and $signature->isa("Mail::Message")
defined $signature $signature->isa("Mail::Message")
Truth table33%1/3
A and B
A= defined $signatureB= $signature->isa("Mail::Message")
ABresult
0X0
100
111
166 if defined $signature && $signature->isa('Mail::Message');
167  
168 3 ▶ my $composed = $body->concatenate
Branch: 1 branch
BranchTrueFalseTotal
defined $signature ? : 0 3 3
169 ( $prelude, $body, $postlude
170 , (defined $signature ? "-- \n" : undef), $signature
171 );
172  
173 3 $self->forwardNo(%args, body => $composed);
174 }
175  
176 #------------------------------------------
177  
178  
179 sub forwardAttach(@)
180 3 ▶{ my ($self, %args) = @_;
Subroutine forwardAttach: called CC=7 SCAR=20.4
Pod documented
181  
182 3 my $body = $self->body;
183 3 ▶ my $strip = !exists $args{strip_signature} || $args{strip_signature};
Condition33%1/3
!exists $args{'strip_signature'} || $args{'strip_signature'}
l!l&&r!l&&!r
300
MC/DC0%0/2
!exists $args{'strip_signature'} || $args{'strip_signature'}
!exists $args{'strip_signature'} $args{'strip_signature'}
Truth table33%1/3
not(A) || B
A= !exists $args{'strip_signature'}B= $args{'strip_signature'}
ABresult
1X1
011
000
184  
185 3 ▶ if($body->isMultipart)
Branch: 1 branch
BranchTrueFalseTotal
if ($body->isMultipart) 1 2 3
186 1 ▶ { $body = $body->stripSignature if $strip;
Branch: 1 branch
BranchTrueFalseTotal
if $strip 1 0 1
187 1 ▶ $body = $body->part(0)->body if $body->parts == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $body->parts == 1 1 0 1
188 }
189  
190 3 my $preamble = $args{preamble};
191 3 ▶ $self->log(ERROR => 'Method forwardAttach requires a preamble'), return
Branch: 1 branch
BranchTrueFalseTotal
unless ref $preamble 0 3 3
192 unless ref $preamble;
193  
194 3 my @parts = ($preamble, $body);
195 3 ▶ push @parts, $args{signature} if defined $args{signature};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"signature"} 0 3 3
196 3 my $multi = Mail::Message::Body::Multipart->new(parts => \@parts);
197  
198 3 $self->forwardNo(%args, body => $multi);
199 }
200  
201 #------------------------------------------
202  
203  
204 sub forwardEncapsulate(@)
205 1 ▶{ my ($self, %args) = @_;
Subroutine forwardEncapsulate: called CC=3 SCAR=11.1
Pod documented
206  
207 1 my $preamble = $args{preamble};
208 1 ▶ $self->log(ERROR => 'Method forwardEncapsulate requires a preamble'), return
Branch: 1 branch
BranchTrueFalseTotal
unless ref $preamble 0 1 1
209 unless ref $preamble;
210  
211 1 my $nested= Mail::Message::Body::Nested->new(nested => $self->clone);
212 1 my @parts = ($preamble, $nested);
213 1 ▶ push @parts, $args{signature} if defined $args{signature};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"signature"} 0 1 1
214  
215 1 my $multi = Mail::Message::Body::Multipart->new(parts => \@parts);
216  
217 1 $self->forwardNo(%args, body => $multi);
218 }
219  
220 #------------------------------------------
221  
222  
223 # tests in t/57forw0s.t
224  
225 sub forwardSubject($)
226 14 ▶{ my ($self, $subject) = @_;
Subroutine forwardSubject: called CC=3 SCAR=11.0
Pod documented
227 14 ▶ defined $subject && length $subject ? "Forw: $subject" : "Forwarded";
Branch: 1 branch
BranchTrueFalseTotal
defined $subject && length $subject ? : 8 6 14
Condition100%3/3
defined $subject and length $subject
!ll&&!rl&&r
158
MC/DC100%2/2
defined $subject and length $subject
defined $subject length $subject
Truth table100%3/3
A and B
A= defined $subjectB= length $subject
ABresult
0X0
100
111
228 }
229  
230 #------------------------------------------
231  
232  
233 sub forwardPrelude()
234 1 ▶{ my $head = shift->head;
Subroutine forwardPrelude: called CC=5 SCAR=16.5
Pod documented
235  
236 1 my @lines = "---- BEGIN forwarded message\n";
237 1 my $from = $head->get('from');
238 1 my $to = $head->get('to');
239 1 my $cc = $head->get('cc');
240 1 my $date = $head->get('date');
241  
242 1 ▶ push @lines, $from->string if defined $from;
Branch: 1 branch
BranchTrueFalseTotal
if defined $from 1 0 1
243 1 ▶ push @lines, $to->string if defined $to;
Branch: 1 branch
BranchTrueFalseTotal
if defined $to 1 0 1
244 1 ▶ push @lines, $cc->string if defined $cc;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cc 1 0 1
245 1 ▶ push @lines, $date->string if defined $date;
Branch: 1 branch
BranchTrueFalseTotal
if defined $date 1 0 1
246 1 push @lines, "\n";
247  
248 1 \@lines;
249 }
250  
251 #------------------------------------------
252  
253  
254 sub forwardPostlude()
255 1 ▶{ my $self = shift;
Subroutine forwardPostlude: called CC=1 SCAR=0.0
Pod documented
256 1 my @lines = ("---- END forwarded message\n");
257 1 \@lines;
258 }
259  
260 #------------------------------------------
261  
262  
263 #------------------------------------------
264
265 3 1;
« Message/Head/FieldGroup.pm ↑ Summary Message/Body/File.pm »