line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2001-2022 by [Mark Overmeer ]. |
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
|
|
|
3
|
|
1994
|
use vars '$VERSION'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
147
|
|
11
|
|
|
|
|
|
|
$VERSION = '3.012'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
|
16
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
55
|
|
15
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
64
|
|
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
3
|
|
429
|
use Mail::Message::Body::Multipart; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
100
|
|
18
|
3
|
|
|
3
|
|
17
|
use Mail::Message::Body::Nested; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
85
|
|
19
|
3
|
|
|
3
|
|
13
|
use Scalar::Util 'blessed'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
3500
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# tests in t/57forw1f.t |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub forward(@) |
25
|
3
|
|
|
3
|
1
|
1014
|
{ my $self = shift; |
26
|
3
|
|
|
|
|
16
|
my %args = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return $self->forwardNo(@_) |
29
|
3
|
50
|
|
|
|
12
|
if exists $args{body}; |
30
|
|
|
|
|
|
|
|
31
|
3
|
|
50
|
|
|
16
|
my $include = $args{include} || 'INLINE'; |
32
|
3
|
50
|
|
|
|
17
|
return $self->forwardInline(@_) if $include eq 'INLINE'; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
0
|
my $preamble = $args{preamble}; |
35
|
0
|
0
|
0
|
|
|
0
|
push @_, preamble => Mail::Message::Body->new(data => $preamble) |
36
|
|
|
|
|
|
|
if defined $preamble && ! ref $preamble; |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
0
|
return $self->forwardAttach(@_) if $include eq 'ATTACH'; |
39
|
0
|
0
|
|
|
|
0
|
return $self->forwardEncapsulate(@_) if $include eq 'ENCAPSULATE'; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
0
|
$self->log(ERROR => 'Cannot include forward source as $include.'); |
42
|
0
|
|
|
|
|
0
|
undef; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#------------------------------------------ |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub forwardNo(@) |
49
|
7
|
|
|
7
|
1
|
51
|
{ my ($self, %args) = @_; |
50
|
|
|
|
|
|
|
|
51
|
7
|
|
|
|
|
19
|
my $body = $args{body}; |
52
|
7
|
50
|
|
|
|
22
|
$self->log(INTERNAL => "No body supplied for forwardNo()") |
53
|
|
|
|
|
|
|
unless defined $body; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# |
56
|
|
|
|
|
|
|
# Collect header info |
57
|
|
|
|
|
|
|
# |
58
|
|
|
|
|
|
|
|
59
|
7
|
|
|
|
|
30
|
my $mainhead = $self->toplevel->head; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Where it comes from |
62
|
7
|
|
|
|
|
24
|
my $from = $args{From}; |
63
|
7
|
50
|
|
|
|
22
|
unless(defined $from) |
64
|
7
|
|
|
|
|
31
|
{ my @from = $self->to; |
65
|
7
|
50
|
|
|
|
1178
|
$from = \@from if @from; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# To whom to send |
69
|
7
|
|
|
|
|
17
|
my $to = $args{To}; |
70
|
7
|
50
|
|
|
|
19
|
$self->log(ERROR => "No address to create forwarded to."), return |
71
|
|
|
|
|
|
|
unless $to; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Create a subject |
74
|
7
|
|
|
|
|
14
|
my $srcsub = $args{Subject}; |
75
|
7
|
0
|
|
|
|
36
|
my $subject |
|
|
50
|
|
|
|
|
|
76
|
|
|
|
|
|
|
= ! defined $srcsub ? $self->forwardSubject($self->subject) |
77
|
|
|
|
|
|
|
: ref $srcsub ? $srcsub->($self->subject) |
78
|
|
|
|
|
|
|
: $srcsub; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Create a nice message-id |
81
|
7
|
|
33
|
|
|
44
|
my $msgid = $args{'Message-ID'} || $mainhead->createMessageId; |
82
|
7
|
50
|
33
|
|
|
50
|
$msgid = "<$msgid>" if $msgid && $msgid !~ /^\s*\<.*\>\s*$/; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Thread information |
85
|
7
|
|
|
|
|
41
|
my $origid = '<'.$self->messageId.'>'; |
86
|
7
|
|
|
|
|
24
|
my $refs = $mainhead->get('references'); |
87
|
|
|
|
|
|
|
|
88
|
7
|
50
|
50
|
|
|
56
|
my $forward = Mail::Message->buildFromBody |
89
|
|
|
|
|
|
|
( $body |
90
|
|
|
|
|
|
|
, From => ($from || '(undisclosed)') |
91
|
|
|
|
|
|
|
, To => $to |
92
|
|
|
|
|
|
|
, Subject => $subject |
93
|
|
|
|
|
|
|
, References => ($refs ? "$refs $origid" : $origid) |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
|
96
|
7
|
|
|
|
|
79
|
my $newhead = $forward->head; |
97
|
7
|
100
|
|
|
|
32
|
$newhead->set(Cc => $args{Cc} ) if $args{Cc}; |
98
|
7
|
100
|
|
|
|
25
|
$newhead->set(Bcc => $args{Bcc} ) if $args{Bcc}; |
99
|
7
|
50
|
|
|
|
30
|
$newhead->set(Date => $args{Date}) if $args{Date}; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Ready |
102
|
|
|
|
|
|
|
|
103
|
7
|
|
|
|
|
31
|
$self->label(passed => 1); |
104
|
7
|
|
|
|
|
48
|
$self->log(PROGRESS => "Forward created from $origid"); |
105
|
7
|
|
|
|
|
68
|
$forward; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
#------------------------------------------ |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub forwardInline(@) |
112
|
4
|
|
|
4
|
1
|
24
|
{ my ($self, %args) = @_; |
113
|
|
|
|
|
|
|
|
114
|
4
|
|
|
|
|
15
|
my $body = $self->body; |
115
|
|
|
|
|
|
|
|
116
|
4
|
|
|
|
|
9
|
while(1) # simplify |
117
|
4
|
50
|
33
|
|
|
36
|
{ if($body->isMultipart && $body->parts==1) |
|
|
50
|
|
|
|
|
|
118
|
0
|
|
|
|
|
0
|
{ $body = $body->part(0)->body } |
119
|
0
|
|
|
|
|
0
|
elsif($body->isNested) { $body = $body->nested->body } |
120
|
4
|
|
|
|
|
8
|
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
|
100
|
|
|
|
15
|
: $self->forwardPrelude; |
126
|
|
|
|
|
|
|
|
127
|
4
|
100
|
66
|
|
|
35
|
$prelude = Mail::Message::Body->new(data => $prelude) |
128
|
|
|
|
|
|
|
if defined $prelude && ! blessed $prelude; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# Postlude |
131
|
|
|
|
|
|
|
my $postlude = exists $args{postlude} ? $args{postlude} |
132
|
4
|
100
|
|
|
|
18
|
: $self->forwardPostlude; |
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
|
100
|
66
|
|
|
31
|
if($body->isMultipart || $body->isBinary) |
138
|
|
|
|
|
|
|
{ $args{preamble} ||= $prelude->concatenate |
139
|
|
|
|
|
|
|
( $prelude |
140
|
1
|
|
50
|
|
|
18
|
, ($args{is_attached} || "[The forwarded message is attached]\n") |
|
|
|
33
|
|
|
|
|
141
|
|
|
|
|
|
|
, $postlude |
142
|
|
|
|
|
|
|
); |
143
|
1
|
|
|
|
|
7
|
return $self->forwardAttach(%args); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
3
|
|
|
|
|
31
|
$body = $body->decoded; |
147
|
|
|
|
|
|
|
my $strip = (!exists $args{strip_signature} || $args{strip_signature}) |
148
|
3
|
|
66
|
|
|
34
|
&& !$body->isNested; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
$body = $body->stripSignature |
151
|
|
|
|
|
|
|
( pattern => $args{strip_signature} |
152
|
|
|
|
|
|
|
, max_lines => $args{max_signature} |
153
|
3
|
100
|
|
|
|
21
|
) if $strip; |
154
|
|
|
|
|
|
|
|
155
|
3
|
100
|
|
|
|
12
|
if(defined(my $quote = $args{quote})) |
156
|
2
|
100
|
|
2
|
|
12
|
{ my $quoting = ref $quote ? $quote : sub {$quote . $_}; |
|
2
|
|
|
|
|
6
|
|
157
|
2
|
|
|
|
|
13
|
$body = $body->foreachLine($quoting); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# |
161
|
|
|
|
|
|
|
# Create the message. |
162
|
|
|
|
|
|
|
# |
163
|
|
|
|
|
|
|
|
164
|
3
|
|
|
|
|
8
|
my $signature = $args{signature}; |
165
|
3
|
50
|
33
|
|
|
11
|
$signature = $signature->body |
166
|
|
|
|
|
|
|
if defined $signature && $signature->isa('Mail::Message'); |
167
|
|
|
|
|
|
|
|
168
|
3
|
50
|
|
|
|
23
|
my $composed = $body->concatenate |
169
|
|
|
|
|
|
|
( $prelude, $body, $postlude |
170
|
|
|
|
|
|
|
, (defined $signature ? "-- \n" : undef), $signature |
171
|
|
|
|
|
|
|
); |
172
|
|
|
|
|
|
|
|
173
|
3
|
|
|
|
|
22
|
$self->forwardNo(%args, body => $composed); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
#------------------------------------------ |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub forwardAttach(@) |
180
|
3
|
|
|
3
|
1
|
492
|
{ my ($self, %args) = @_; |
181
|
|
|
|
|
|
|
|
182
|
3
|
|
|
|
|
12
|
my $body = $self->body; |
183
|
3
|
|
33
|
|
|
13
|
my $strip = !exists $args{strip_signature} || $args{strip_signature}; |
184
|
|
|
|
|
|
|
|
185
|
3
|
100
|
|
|
|
14
|
if($body->isMultipart) |
186
|
1
|
50
|
|
|
|
7
|
{ $body = $body->stripSignature if $strip; |
187
|
1
|
50
|
|
|
|
5
|
$body = $body->part(0)->body if $body->parts == 1; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
3
|
|
|
|
|
7
|
my $preamble = $args{preamble}; |
191
|
3
|
50
|
|
|
|
21
|
$self->log(ERROR => 'Method forwardAttach requires a preamble'), return |
192
|
|
|
|
|
|
|
unless ref $preamble; |
193
|
|
|
|
|
|
|
|
194
|
3
|
|
|
|
|
8
|
my @parts = ($preamble, $body); |
195
|
3
|
50
|
|
|
|
9
|
push @parts, $args{signature} if defined $args{signature}; |
196
|
3
|
|
|
|
|
26
|
my $multi = Mail::Message::Body::Multipart->new(parts => \@parts); |
197
|
|
|
|
|
|
|
|
198
|
3
|
|
|
|
|
20
|
$self->forwardNo(%args, body => $multi); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
#------------------------------------------ |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
sub forwardEncapsulate(@) |
205
|
1
|
|
|
1
|
1
|
4
|
{ my ($self, %args) = @_; |
206
|
|
|
|
|
|
|
|
207
|
1
|
|
|
|
|
3
|
my $preamble = $args{preamble}; |
208
|
1
|
50
|
|
|
|
5
|
$self->log(ERROR => 'Method forwardEncapsulate requires a preamble'), return |
209
|
|
|
|
|
|
|
unless ref $preamble; |
210
|
|
|
|
|
|
|
|
211
|
1
|
|
|
|
|
5
|
my $nested= Mail::Message::Body::Nested->new(nested => $self->clone); |
212
|
1
|
|
|
|
|
3
|
my @parts = ($preamble, $nested); |
213
|
1
|
50
|
|
|
|
4
|
push @parts, $args{signature} if defined $args{signature}; |
214
|
|
|
|
|
|
|
|
215
|
1
|
|
|
|
|
8
|
my $multi = Mail::Message::Body::Multipart->new(parts => \@parts); |
216
|
|
|
|
|
|
|
|
217
|
1
|
|
|
|
|
7
|
$self->forwardNo(%args, body => $multi); |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
#------------------------------------------ |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
# tests in t/57forw0s.t |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub forwardSubject($) |
226
|
14
|
|
|
14
|
1
|
111
|
{ my ($self, $subject) = @_; |
227
|
14
|
100
|
100
|
|
|
94
|
defined $subject && length $subject ? "Forw: $subject" : "Forwarded"; |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
#------------------------------------------ |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
sub forwardPrelude() |
234
|
1
|
|
|
1
|
1
|
4
|
{ my $head = shift->head; |
235
|
|
|
|
|
|
|
|
236
|
1
|
|
|
|
|
4
|
my @lines = "---- BEGIN forwarded message\n"; |
237
|
1
|
|
|
|
|
4
|
my $from = $head->get('from'); |
238
|
1
|
|
|
|
|
3
|
my $to = $head->get('to'); |
239
|
1
|
|
|
|
|
14
|
my $cc = $head->get('cc'); |
240
|
1
|
|
|
|
|
3
|
my $date = $head->get('date'); |
241
|
|
|
|
|
|
|
|
242
|
1
|
50
|
|
|
|
9
|
push @lines, $from->string if defined $from; |
243
|
1
|
50
|
|
|
|
7
|
push @lines, $to->string if defined $to; |
244
|
1
|
50
|
|
|
|
5
|
push @lines, $cc->string if defined $cc; |
245
|
1
|
50
|
|
|
|
5
|
push @lines, $date->string if defined $date; |
246
|
1
|
|
|
|
|
14
|
push @lines, "\n"; |
247
|
|
|
|
|
|
|
|
248
|
1
|
|
|
|
|
3
|
\@lines; |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
#------------------------------------------ |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
sub forwardPostlude() |
255
|
1
|
|
|
1
|
1
|
2
|
{ my $self = shift; |
256
|
1
|
|
|
|
|
3
|
my @lines = ("---- END forwarded message\n"); |
257
|
1
|
|
|
|
|
3
|
\@lines; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
#------------------------------------------ |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
#------------------------------------------ |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
1; |