Message/Construct/Forward.pm

filter: Statementstmt 93.6% 103 / 110 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.6% 197 / 279 CC 55 SCAR 28.2
CC
55
Cov
73%
forward
28.1
forwardInline
26.0
forwardNo
20.4
CRAP 16.8
« Box/Parser/Lines.pm ↑ Summary Message/Construct/Bounce.pm »
1 # This code is part of Perl distribution Mail-Message version 4.05.
2 # The POD got stripped from this file by OODoc version 3.06.
3 # For contributors see file ChangeLog.
4  
5 # This software is copyright (c) 2001-2026 by Mark Overmeer.
6  
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10  
11  
12 package Mail::Message;{
13 3 our $VERSION = '4.05';
14 }
15  
16  
17 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 3 ▶use Log::Report 'mail-message', import => [ qw/__x error info trace/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 3 ▶use Mail::Message::Body::Multipart ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 ▶use Mail::Message::Body::Nested ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 3 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 #--------------------
28  
29 # tests in t/57forw1f.t
30  
31 sub forward(@)
32 3 ▶{ my $self = shift;
Subroutine forward: called CC=8 SCAR=33.4
Pod documented
33 3 my %args = @_;
34  
35 return $self->forwardNo(@_)
36 3 ▶ if exists $args{body};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"body"} 0 3 3
37  
38 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
39 3 ▶ return $self->forwardInline(@_) if $include eq 'INLINE';
Branch: 1 branch
BranchTrueFalseTotal
if $include eq "INLINE" 3 0 3
40  
41 0 my $preamble = $args{preamble};
42 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
43 if defined $preamble && ! ref $preamble;
44  
45 0 ▶ return $self->forwardAttach(@_) if $include eq 'ATTACH';
Branch: 1 branch
BranchTrueFalseTotal
if $include eq "ATTACH" 0 0 0
46 0 ▶ return $self->forwardEncapsulate(@_) if $include eq 'ENCAPSULATE';
Branch: 1 branch
BranchTrueFalseTotal
if $include eq "ENCAPSULATE" 0 0 0
47  
48 0 error __x"cannot include forward source as {kind UNKNOWN}.", kind => $include;
49 }
50  
51  
52 sub forwardNo(@)
53 7 ▶{ my ($self, %args) = @_;
Subroutine forwardNo: called CC=15 SCAR=30.2
Pod documented
54 7 ▶ my $body = $args{body} or error __x"method forwardNo requires a body.";
Branch: 1 branch
BranchTrueFalseTotal
my $body = $args{"body"} or &error(&__x("method forwardNo requires a body.")) 7 0 7
55 7 ▶ my $to = $args{To} or error __x"method forwardNo requires a To.";
Branch: 1 branch
BranchTrueFalseTotal
my $to = $args{"To"} or &error(&__x("method forwardNo requires a To.")) 7 0 7
56  
57 #
58 # Collect header info
59 #
60  
61 7 my $mainhead = $self->toplevel->head;
62  
63 # Where it comes from
64 7 my $from = $args{From};
65 7 ▶ unless(defined $from)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $from) 7 0 7
66 7 { my @from = $self->to;
67 7 ▶ $from = \@from if @from;
Branch: 1 branch
BranchTrueFalseTotal
if @from 7 0 7
68 }
69  
70 # Create a subject
71 7 my $srcsub = $args{Subject};
72 7 ▶ my $subject
Branch: 2 branches
BranchTrueFalseTotal
!defined($srcsub) ? : 7 0 7
ref $srcsub ? : 0 0 0
73 = ! defined $srcsub ? $self->forwardSubject($self->subject)
74 : ref $srcsub ? $srcsub->($self->subject)
75 : $srcsub;
76  
77 # Create a nice message-id
78 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
79 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
80  
81 # Thread information
82 7 my $origid = '<'.$self->messageId.'>';
83 7 my $refs = $mainhead->get('references');
84  
85 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
86 $body,
87 From => ($from || '(undisclosed)'),
88 To => $to,
89 Subject => $subject,
90 References => ($refs ? "$refs $origid" : $origid),
91 );
92  
93 7 my $newhead = $forward->head;
94 7 ▶ $newhead->set(Cc => $args{Cc} ) if $args{Cc};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"Cc"} 1 6 7
95 7 ▶ $newhead->set(Bcc => $args{Bcc} ) if $args{Bcc};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"Bcc"} 1 6 7
96 7 ▶ $newhead->set(Date => $args{Date}) if $args{Date};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"Date"} 0 7 7
97  
98 # Ready
99  
100 7 $self->label(passed => 1);
101 7 trace "Forward created from $origid";
102 7 $forward;
103 }
104  
105  
106 sub forwardInline(@)
107 4 ▶{ my ($self, %args) = @_;
Subroutine forwardInline: called CC=20 SCAR=32.6
Pod documented
108  
109 4 my $body = $self->body;
110  
111 4 while(1) # simplify
112 0 ▶ { if($body->isMultipart && $body->parts==1) { $body = $body->part(0)->body }
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
113 0 elsif($body->isNested) { $body = $body->nested->body }
114 4 else { last }
115 }
116  
117 # Prelude must be a real body, otherwise concatenate will not work
118 4 ▶ my $prelude = exists $args{prelude} ? $args{prelude} : $self->forwardPrelude;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'prelude'} ? : 3 1 4
119  
120 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
121 if defined $prelude && ! blessed $prelude;
122  
123 # Postlude
124 4 ▶ my $postlude = exists $args{postlude} ? $args{postlude} : $self->forwardPostlude;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'postlude'} ? : 3 1 4
125  
126 # Binary bodies cannot be inlined, therefore they will be rewritten
127 # into a forwardAttach... preamble must replace prelude and postlude.
128  
129 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
130 { $args{preamble} ||= $prelude->concatenate(
131 $prelude,
132 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
133 $postlude,
134 );
135 1 return $self->forwardAttach(%args);
136 }
137  
138 3 $body = $body->decoded;
139 3 ▶ if((!exists $args{strip_signature} || $args{strip_signature}) && !$body->isNested)
Branch: 1 branch
BranchTrueFalseTotal
if (!exists $args{"strip_signature"} || $args{"strip_signature"} and not $body->isNested) 2 1 3
Condition66%4/6
!exists $args{"strip_signature"} || $args{"strip_signature"} and not $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"} and not $body->isNested
not exists $args{"strip_signature"} $args{"strip_signature"} not $body->isNested
Truth table40%2/5
not(A) or B and not(C)
A= not exists $args{"strip_signature"}B= $args{"strip_signature"}C= not $body->isNested
ABCresult
00X0
1X00
0100
1X11
0111
140 2 { $body = $body->stripSignature(pattern => $args{strip_signature}, max_lines => $args{max_signature});
141 }
142  
143 3 ▶ if(defined(my $quote = $args{quote}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $quote = $args{"quote"})) 2 1 3
144 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
145 2 $body = $body->foreachLine($quoting);
146 }
147  
148 #
149 # Create the message.
150 #
151  
152 3 my $signature = $args{signature};
153 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
154 if defined $signature && $signature->isa('Mail::Message');
155  
156 3 ▶ my $composed = $body->concatenate(
Branch: 1 branch
BranchTrueFalseTotal
defined $signature ? : 0 3 3
157 $prelude, $body, $postlude,
158 (defined $signature ? "-- \n" : undef), $signature
159 );
160  
161 3 $self->forwardNo(%args, body => $composed);
162 }
163  
164  
165 sub forwardAttach(@)
166 3 ▶{ my ($self, %args) = @_;
Subroutine forwardAttach: called CC=7 SCAR=20.6
Pod documented
167  
168 3 my $body = $self->body;
169 3 ▶ if($body->isMultipart)
Branch: 1 branch
BranchTrueFalseTotal
if ($body->isMultipart) 1 2 3
170 { $body = $body->stripSignature(pattern => $args{strip_signature}, max_lines => $args{max_signature})
171 1 ▶ if !exists $args{strip_signature} || $args{strip_signature};
Branch: 1 branch
BranchTrueFalseTotal
if not exists $args{"strip_signature"} or $args{"strip_signature"} 1 0 1
Condition33%1/3
not exists $args{"strip_signature"} or $args{"strip_signature"}
l!l&&r!l&&!r
100
MC/DC0%0/2
not exists $args{"strip_signature"} or $args{"strip_signature"}
not exists $args{"strip_signature"} $args{"strip_signature"}
Truth table33%1/3
not(A) or B
A= not exists $args{"strip_signature"}B= $args{"strip_signature"}
ABresult
1X1
011
000
172 1 ▶ $body = $body->part(0)->body if $body->parts == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $body->parts == 1 1 0 1
173 }
174  
175 my $preamble = $args{preamble}
176 3 ▶ or error __x"method forwardAttach requires a preamble.";
Branch: 1 branch
BranchTrueFalseTotal
my $preamble = $args{"preamble"} or &error(&__x("method forwardAttach requires a preamble.")) 3 0 3
177  
178 3 my @parts = ($preamble, $body);
179 3 ▶ push @parts, $args{signature} if defined $args{signature};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"signature"} 0 3 3
180 3 my $multi = Mail::Message::Body::Multipart->new(parts => \@parts);
181  
182 3 $self->forwardNo(%args, body => $multi);
183 }
184  
185  
186 sub forwardEncapsulate(@)
187 1 ▶{ my ($self, %args) = @_;
Subroutine forwardEncapsulate: called CC=3 SCAR=11.2
Pod documented
188  
189 my $preamble = $args{preamble}
190 1 ▶ or error __x"method forwardEncapsulate requires a preamble.";
Branch: 1 branch
BranchTrueFalseTotal
my $preamble = $args{"preamble"} or &error(&__x("method forwardEncapsulate requires a preamble.")) 1 0 1
191  
192 1 my $nested = Mail::Message::Body::Nested->new(nested => $self->clone);
193 1 my @parts = ($preamble, $nested);
194 1 ▶ push @parts, $args{signature} if defined $args{signature};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"signature"} 0 1 1
195  
196 1 my $multi = Mail::Message::Body::Multipart->new(parts => \@parts);
197 1 $self->forwardNo(%args, body => $multi);
198 }
199  
200  
201 # tests in t/57forw0s.t
202  
203 sub forwardSubject($)
204 14 ▶{ my ($self, $subject) = @_;
Subroutine forwardSubject: called CC=3 SCAR=11.0
Pod documented
205 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
206 }
207  
208  
209 sub forwardPrelude()
210 1 ▶{ my $head = shift->head;
Subroutine forwardPrelude: called CC=5 SCAR=16.5
Pod documented
211  
212 1 my @lines = "---- BEGIN forwarded message\n";
213 1 my $from = $head->get('from');
214 1 my $to = $head->get('to');
215 1 my $cc = $head->get('cc');
216 1 my $date = $head->get('date');
217  
218 1 ▶ push @lines, $from->string if defined $from;
Branch: 1 branch
BranchTrueFalseTotal
if defined $from 1 0 1
219 1 ▶ push @lines, $to->string if defined $to;
Branch: 1 branch
BranchTrueFalseTotal
if defined $to 1 0 1
220 1 ▶ push @lines, $cc->string if defined $cc;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cc 1 0 1
221 1 ▶ push @lines, $date->string if defined $date;
Branch: 1 branch
BranchTrueFalseTotal
if defined $date 1 0 1
222 1 push @lines, "\n";
223  
224 1 \@lines;
225 }
226  
227  
228 sub forwardPostlude()
229 1 ▶{ my $self = shift;
Subroutine forwardPostlude: called CC=1 SCAR=0.0
Pod documented
230 1 [ "---- END forwarded message\n" ];
231 }
232  
233 #--------------------
234  
235 3 1;
« Box/Parser/Lines.pm ↑ Summary Message/Construct/Bounce.pm »