line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2001-2021 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.02. |
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
|
|
2378
|
use vars '$VERSION'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
182
|
|
11
|
|
|
|
|
|
|
$VERSION = '3.011'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
3
|
|
|
3
|
|
21
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
66
|
|
15
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
73
|
|
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
3
|
|
502
|
use Mail::Message::Body::Multipart; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
106
|
|
18
|
3
|
|
|
3
|
|
20
|
use Mail::Address; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
89
|
|
19
|
3
|
|
|
3
|
|
18
|
use Scalar::Util 'blessed'; |
|
3
|
|
|
|
|
15
|
|
|
3
|
|
|
|
|
4455
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# tests in t/55reply1r.t, demo in the examples/ directory |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub reply(@) |
25
|
3
|
|
|
3
|
1
|
821
|
{ my ($self, %args) = @_; |
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
10
|
my $body = $args{body}; |
28
|
3
|
|
66
|
|
|
14
|
my $strip = !exists $args{strip_signature} || $args{strip_signature}; |
29
|
3
|
|
50
|
|
|
15
|
my $include = $args{include} || 'INLINE'; |
30
|
|
|
|
|
|
|
|
31
|
3
|
50
|
33
|
|
|
19
|
if($include eq 'NO') |
|
|
50
|
|
|
|
|
|
32
|
|
|
|
|
|
|
{ # Throw away real body. |
33
|
0
|
0
|
|
|
|
0
|
$body = Mail::Message::Body->new |
34
|
|
|
|
|
|
|
(data => ["\n[The original message is not included]\n\n"]) |
35
|
|
|
|
|
|
|
unless defined $body; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
elsif($include eq 'INLINE' || $include eq 'ATTACH') |
38
|
|
|
|
|
|
|
{ |
39
|
3
|
50
|
|
|
|
11
|
unless(defined $body) |
40
|
|
|
|
|
|
|
{ # text attachment |
41
|
3
|
|
|
|
|
10
|
$body = $self->body; |
42
|
3
|
50
|
33
|
|
|
21
|
$body = $body->part(0)->body if $body->isMultipart && $body->parts==1; |
43
|
3
|
50
|
|
|
|
12
|
$body = $body->nested->body if $body->isNested; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$body |
46
|
|
|
|
|
|
|
= $strip && ! $body->isMultipart && !$body->isBinary |
47
|
|
|
|
|
|
|
? $body->decoded->stripSignature |
48
|
|
|
|
|
|
|
( pattern => $args{strip_signature} |
49
|
|
|
|
|
|
|
, max_lines => $args{max_signature} |
50
|
|
|
|
|
|
|
) |
51
|
3
|
100
|
66
|
|
|
29
|
: $body->decoded; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
3
|
50
|
33
|
|
|
25
|
if($include eq 'INLINE' && $body->isMultipart) { $include = 'ATTACH' } |
|
0
|
50
|
33
|
|
|
0
|
|
55
|
|
|
|
|
|
|
elsif($include eq 'INLINE' && $body->isBinary) |
56
|
0
|
|
|
|
|
0
|
{ $include = 'ATTACH'; |
57
|
0
|
|
|
|
|
0
|
$body = Mail::Message::Body::Multipart->new(parts => [$body]); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
3
|
50
|
|
|
|
28
|
if($include eq 'INLINE') |
61
|
|
|
|
|
|
|
{ my $quote |
62
|
|
|
|
|
|
|
= defined $args{quote} ? $args{quote} |
63
|
|
|
|
|
|
|
: exists $args{quote} ? undef |
64
|
3
|
50
|
|
|
|
14
|
: '> '; |
|
|
100
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
3
|
100
|
|
|
|
12
|
if(defined $quote) |
67
|
2
|
100
|
|
2
|
|
12
|
{ my $quoting = ref $quote ? $quote : sub {$quote . $_}; |
|
2
|
|
|
|
|
6
|
|
68
|
2
|
|
|
|
|
15
|
$body = $body->foreachLine($quoting); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else |
73
|
0
|
|
|
|
|
0
|
{ $self->log(ERROR => "Cannot include reply source as $include."); |
74
|
0
|
|
|
|
|
0
|
return; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# |
78
|
|
|
|
|
|
|
# Collect header info |
79
|
|
|
|
|
|
|
# |
80
|
|
|
|
|
|
|
|
81
|
3
|
|
|
|
|
16
|
my $mainhead = $self->toplevel->head; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Where it comes from |
84
|
3
|
|
|
|
|
9
|
my $from = delete $args{From}; |
85
|
3
|
50
|
|
|
|
10
|
unless(defined $from) |
86
|
3
|
|
|
|
|
12
|
{ my @from = $self->to; |
87
|
3
|
50
|
|
|
|
751
|
$from = \@from if @from; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# To whom to send |
91
|
|
|
|
|
|
|
my $to = delete $args{To} |
92
|
3
|
|
33
|
|
|
19
|
|| $mainhead->get('reply-to') || $mainhead->get('from'); |
93
|
3
|
50
|
|
|
|
11
|
defined $to or return; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# Add Cc |
96
|
3
|
|
|
|
|
9
|
my $cc = delete $args{Cc}; |
97
|
3
|
100
|
66
|
|
|
18
|
if(!defined $cc && $args{group_reply}) |
98
|
1
|
|
|
|
|
5
|
{ my @cc = $self->cc; |
99
|
1
|
50
|
|
|
|
226
|
$cc = [ $self->cc ] if @cc; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Create a subject |
103
|
3
|
|
|
|
|
200
|
my $srcsub = delete $args{Subject}; |
104
|
3
|
0
|
|
|
|
15
|
my $subject |
|
|
50
|
|
|
|
|
|
105
|
|
|
|
|
|
|
= ! defined $srcsub ? $self->replySubject($self->subject) |
106
|
|
|
|
|
|
|
: ref $srcsub ? $srcsub->($self->subject) |
107
|
|
|
|
|
|
|
: $srcsub; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Create a nice message-id |
110
|
3
|
|
|
|
|
8
|
my $msgid = delete $args{'Message-ID'}; |
111
|
3
|
50
|
33
|
|
|
11
|
$msgid = "<$msgid>" if $msgid && $msgid !~ /^\s*\<.*\>\s*$/; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# Thread information |
114
|
3
|
|
|
|
|
11
|
my $origid = '<'.$self->messageId.'>'; |
115
|
3
|
|
|
|
|
9
|
my $refs = $mainhead->get('references'); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# Prelude |
118
|
|
|
|
|
|
|
my $prelude |
119
|
|
|
|
|
|
|
= defined $args{prelude} ? $args{prelude} |
120
|
|
|
|
|
|
|
: exists $args{prelude} ? undef |
121
|
3
|
100
|
|
|
|
18
|
: [ $self->replyPrelude($to) ]; |
|
|
50
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
3
|
100
|
66
|
|
|
32
|
$prelude = Mail::Message::Body->new(data => $prelude) |
124
|
|
|
|
|
|
|
if defined $prelude && ! blessed $prelude; |
125
|
|
|
|
|
|
|
|
126
|
3
|
|
|
|
|
8
|
my $postlude = $args{postlude}; |
127
|
3
|
50
|
66
|
|
|
20
|
$postlude = Mail::Message::Body->new(data => $postlude) |
128
|
|
|
|
|
|
|
if defined $postlude && ! blessed $postlude; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# |
131
|
|
|
|
|
|
|
# Create the message. |
132
|
|
|
|
|
|
|
# |
133
|
|
|
|
|
|
|
|
134
|
3
|
|
|
|
|
7
|
my $total; |
135
|
3
|
50
|
|
|
|
13
|
if($include eq 'NO') {$total = $body} |
|
0
|
50
|
|
|
|
0
|
|
136
|
|
|
|
|
|
|
elsif($include eq 'INLINE') |
137
|
3
|
|
|
|
|
7
|
{ my $signature = $args{signature}; |
138
|
3
|
50
|
33
|
|
|
9
|
$signature = $signature->body |
139
|
|
|
|
|
|
|
if defined $signature && $signature->isa('Mail::Message'); |
140
|
|
|
|
|
|
|
|
141
|
3
|
50
|
|
|
|
21
|
$total = $body->concatenate |
142
|
|
|
|
|
|
|
( $prelude, $body, $postlude |
143
|
|
|
|
|
|
|
, (defined $signature ? "-- \n" : undef), $signature |
144
|
|
|
|
|
|
|
); |
145
|
|
|
|
|
|
|
} |
146
|
3
|
50
|
|
|
|
14
|
if($include eq 'ATTACH') |
147
|
|
|
|
|
|
|
{ |
148
|
0
|
|
|
|
|
0
|
my $intro = $prelude->concatenate |
149
|
|
|
|
|
|
|
( $prelude |
150
|
|
|
|
|
|
|
, [ "\n", "[Your message is attached]\n" ] |
151
|
|
|
|
|
|
|
, $postlude |
152
|
|
|
|
|
|
|
); |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
$total = Mail::Message::Body::Multipart->new |
155
|
0
|
|
|
|
|
0
|
( parts => [ $intro, $body, $args{signature} ] |
156
|
|
|
|
|
|
|
); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
3
|
|
50
|
|
|
18
|
my $msgtype = $args{message_type} || 'Mail::Message'; |
160
|
|
|
|
|
|
|
|
161
|
3
|
50
|
50
|
|
|
47
|
my $reply = $msgtype->buildFromBody |
162
|
|
|
|
|
|
|
( $total |
163
|
|
|
|
|
|
|
, From => $from || 'Undisclosed senders:;' |
164
|
|
|
|
|
|
|
, To => $to |
165
|
|
|
|
|
|
|
, Subject => $subject |
166
|
|
|
|
|
|
|
, 'In-Reply-To' => $origid |
167
|
|
|
|
|
|
|
, References => ($refs ? "$refs $origid" : $origid) |
168
|
|
|
|
|
|
|
); |
169
|
|
|
|
|
|
|
|
170
|
3
|
|
|
|
|
11
|
my $newhead = $reply->head; |
171
|
3
|
100
|
|
|
|
14
|
$newhead->set(Cc => $cc) if $cc; |
172
|
3
|
100
|
|
|
|
15
|
$newhead->set(Bcc => delete $args{Bcc}) if $args{Bcc}; |
173
|
|
|
|
|
|
|
$newhead->add($_ => $args{$_}) |
174
|
3
|
|
|
|
|
30
|
for sort grep /^[A-Z]/, keys %args; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# Ready |
177
|
|
|
|
|
|
|
|
178
|
3
|
|
|
|
|
24
|
$self->log(PROGRESS => 'Reply created from '.$origid); |
179
|
3
|
|
|
|
|
17
|
$self->label(replied => 1); |
180
|
3
|
|
|
|
|
12
|
$reply; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
#------------------------------------------ |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# tests in t/35reply1rs.t |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub replySubject($) |
189
|
24
|
|
|
24
|
1
|
163
|
{ my ($thing, $subject) = @_; |
190
|
24
|
100
|
100
|
|
|
115
|
$subject = 'your mail' unless defined $subject && length $subject; |
191
|
24
|
|
|
|
|
79
|
my @subject = split /\:/, $subject; |
192
|
24
|
|
|
|
|
45
|
my $re_count = 1; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
# Strip multiple Re's from the start. |
195
|
|
|
|
|
|
|
|
196
|
24
|
|
|
|
|
64
|
while(@subject) |
197
|
38
|
100
|
|
|
|
143
|
{ last if $subject[0] =~ /[A-QS-Za-qs-z][A-DF-Za-df-z]/; |
198
|
|
|
|
|
|
|
|
199
|
14
|
|
|
|
|
29
|
for(shift @subject) |
200
|
14
|
|
|
|
|
81
|
{ while( /\bRe(?:\[\s*(\d+)\s*\]|\b)/g ) |
201
|
17
|
100
|
|
|
|
86
|
{ $re_count += defined $1 ? $1 : 1; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
# Strip multiple Re's from the end. |
207
|
|
|
|
|
|
|
|
208
|
24
|
50
|
|
|
|
53
|
if(@subject) |
209
|
24
|
|
|
|
|
50
|
{ for($subject[-1]) |
210
|
24
|
|
|
|
|
122
|
{ $re_count++ while s/\s*\(\s*(re|forw)\W*\)\s*$//i; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
# Create the new subject string. |
215
|
|
|
|
|
|
|
|
216
|
24
|
|
50
|
|
|
81
|
my $text = (join ':', @subject) || 'your mail'; |
217
|
24
|
|
|
|
|
44
|
for($text) |
218
|
24
|
|
|
|
|
69
|
{ s/^\s+//; |
219
|
24
|
|
|
|
|
62
|
s/\s+$//; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
24
|
100
|
|
|
|
153
|
$re_count==1 ? "Re: $text" : "Re[$re_count]: $text"; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
#------------------------------------------ |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
sub replyPrelude($) |
229
|
2
|
|
|
2
|
1
|
6
|
{ my ($self, $who) = @_; |
230
|
|
|
|
|
|
|
|
231
|
2
|
50
|
|
|
|
8
|
$who = $who->[0] if ref $who eq 'ARRAY'; |
232
|
|
|
|
|
|
|
|
233
|
2
|
50
|
|
|
|
19
|
my $user |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
234
|
|
|
|
|
|
|
= !defined $who ? undef |
235
|
|
|
|
|
|
|
: !ref $who ? (Mail::Address->parse($who))[0] |
236
|
|
|
|
|
|
|
: $who->isa('Mail::Message::Field') ? ($who->addresses)[0] |
237
|
|
|
|
|
|
|
: $who; |
238
|
|
|
|
|
|
|
|
239
|
2
|
50
|
33
|
|
|
521
|
my $from |
|
|
|
33
|
|
|
|
|
240
|
|
|
|
|
|
|
= ref $user && $user->isa('Mail::Address') |
241
|
|
|
|
|
|
|
? ($user->name || $user->address || $user->format) |
242
|
|
|
|
|
|
|
: 'someone'; |
243
|
|
|
|
|
|
|
|
244
|
2
|
|
|
|
|
186
|
my $time = gmtime $self->timestamp; |
245
|
2
|
|
|
|
|
14
|
"On $time, $from wrote:\n"; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
1; |