| 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::Body::File; |
|
10
|
31
|
|
|
31
|
|
1063
|
use vars '$VERSION'; |
|
|
31
|
|
|
|
|
97
|
|
|
|
31
|
|
|
|
|
1788
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '3.011'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
31
|
|
|
31
|
|
186
|
use base 'Mail::Message::Body'; |
|
|
31
|
|
|
|
|
102
|
|
|
|
31
|
|
|
|
|
4425
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
31
|
|
|
31
|
|
236
|
use strict; |
|
|
31
|
|
|
|
|
89
|
|
|
|
31
|
|
|
|
|
812
|
|
|
16
|
31
|
|
|
31
|
|
192
|
use warnings; |
|
|
31
|
|
|
|
|
64
|
|
|
|
31
|
|
|
|
|
1083
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
31
|
|
|
31
|
|
3945
|
use Mail::Box::Parser; |
|
|
31
|
|
|
|
|
65
|
|
|
|
31
|
|
|
|
|
891
|
|
|
19
|
31
|
|
|
31
|
|
8612
|
use Mail::Message; |
|
|
31
|
|
|
|
|
111
|
|
|
|
31
|
|
|
|
|
1152
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
31
|
|
|
31
|
|
237
|
use Carp; |
|
|
31
|
|
|
|
|
71
|
|
|
|
31
|
|
|
|
|
2678
|
|
|
22
|
31
|
|
|
31
|
|
26274
|
use File::Temp qw/tempfile/; |
|
|
31
|
|
|
|
|
369700
|
|
|
|
31
|
|
|
|
|
2388
|
|
|
23
|
31
|
|
|
31
|
|
8168
|
use File::Copy qw/copy/; |
|
|
31
|
|
|
|
|
37731
|
|
|
|
31
|
|
|
|
|
46324
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _data_from_filename(@) |
|
27
|
0
|
|
|
0
|
|
0
|
{ my ($self, $filename) = @_; |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
local $_; |
|
30
|
0
|
|
|
|
|
0
|
local (*IN, *OUT); |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
0
|
unless(open IN, '<:raw', $filename) |
|
33
|
0
|
|
|
|
|
0
|
{ $self->log(ERROR => |
|
34
|
|
|
|
|
|
|
"Unable to read file $filename for message body file: $!"); |
|
35
|
0
|
|
|
|
|
0
|
return; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
0
|
my $file = $self->tempFilename; |
|
39
|
0
|
0
|
|
|
|
0
|
unless(open OUT, '>:raw', $file) |
|
40
|
0
|
|
|
|
|
0
|
{ $self->log(ERROR => "Cannot write to temporary body file $file: $!"); |
|
41
|
0
|
|
|
|
|
0
|
return; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
my $nrlines = 0; |
|
45
|
0
|
|
|
|
|
0
|
while() { print OUT; $nrlines++ } |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
0
|
close OUT; |
|
48
|
0
|
|
|
|
|
0
|
close IN; |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
0
|
$self->{MMBF_nrlines} = $nrlines; |
|
51
|
0
|
|
|
|
|
0
|
$self; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _data_from_filehandle(@) |
|
55
|
1
|
|
|
1
|
|
4
|
{ my ($self, $fh) = @_; |
|
56
|
1
|
|
|
|
|
18
|
my $file = $self->tempFilename; |
|
57
|
1
|
|
|
|
|
856
|
my $nrlines = 0; |
|
58
|
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
6
|
local *OUT; |
|
60
|
|
|
|
|
|
|
|
|
61
|
1
|
50
|
|
|
|
108
|
unless(open OUT, '>:raw', $file) |
|
62
|
0
|
|
|
|
|
0
|
{ $self->log(ERROR => "Cannot write to temporary body file $file: $!"); |
|
63
|
0
|
|
|
|
|
0
|
return; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
10
|
while(my $l = $fh->getline) |
|
67
|
5
|
|
|
|
|
311
|
{ print OUT $l; |
|
68
|
5
|
|
|
|
|
13
|
$nrlines++; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
1
|
|
|
|
|
117
|
close OUT; |
|
71
|
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
9
|
$self->{MMBF_nrlines} = $nrlines; |
|
73
|
1
|
|
|
|
|
9
|
$self; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _data_from_glob(@) |
|
77
|
0
|
|
|
0
|
|
0
|
{ my ($self, $fh) = @_; |
|
78
|
0
|
|
|
|
|
0
|
my $file = $self->tempFilename; |
|
79
|
0
|
|
|
|
|
0
|
my $nrlines = 0; |
|
80
|
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
0
|
local $_; |
|
82
|
0
|
|
|
|
|
0
|
local *OUT; |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
0
|
unless(open OUT, '>:raw', $file) |
|
85
|
0
|
|
|
|
|
0
|
{ $self->log(ERROR => "Cannot write to temporary body file $file: $!"); |
|
86
|
0
|
|
|
|
|
0
|
return; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
0
|
while(<$fh>) |
|
90
|
0
|
|
|
|
|
0
|
{ print OUT; |
|
91
|
0
|
|
|
|
|
0
|
$nrlines++; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
0
|
|
|
|
|
0
|
close OUT; |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
0
|
$self->{MMBF_nrlines} = $nrlines; |
|
96
|
0
|
|
|
|
|
0
|
$self; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _data_from_lines(@) |
|
100
|
1
|
|
|
1
|
|
5
|
{ my ($self, $lines) = @_; |
|
101
|
1
|
|
|
|
|
5
|
my $file = $self->tempFilename; |
|
102
|
|
|
|
|
|
|
|
|
103
|
1
|
|
|
|
|
592
|
local *OUT; |
|
104
|
|
|
|
|
|
|
|
|
105
|
1
|
50
|
|
|
|
61
|
unless(open OUT, '>:raw', $file) |
|
106
|
0
|
|
|
|
|
0
|
{ $self->log(ERROR => "Cannot write to $file: $!"); |
|
107
|
0
|
|
|
|
|
0
|
return; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
13
|
print OUT @$lines; |
|
111
|
1
|
|
|
|
|
112
|
close OUT; |
|
112
|
|
|
|
|
|
|
|
|
113
|
1
|
|
|
|
|
9
|
$self->{MMBF_nrlines} = @$lines; |
|
114
|
1
|
|
|
|
|
11
|
$self; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub clone() |
|
118
|
0
|
|
|
0
|
1
|
0
|
{ my $self = shift; |
|
119
|
0
|
|
|
|
|
0
|
my $clone = ref($self)->new(based_on => $self); |
|
120
|
|
|
|
|
|
|
|
|
121
|
0
|
0
|
|
|
|
0
|
copy($self->tempFilename, $clone->tempFilename) |
|
122
|
|
|
|
|
|
|
or return; |
|
123
|
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
0
|
$clone->{MMBF_nrlines} = $self->{MMBF_nrlines}; |
|
125
|
0
|
|
|
|
|
0
|
$clone->{MMBF_size} = $self->{MMBF_size}; |
|
126
|
0
|
|
|
|
|
0
|
$self; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub nrLines() |
|
130
|
2
|
|
|
2
|
1
|
5
|
{ my $self = shift; |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
return $self->{MMBF_nrlines} |
|
133
|
2
|
50
|
|
|
|
23
|
if defined $self->{MMBF_nrlines}; |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
0
|
my $file = $self->tempFilename; |
|
136
|
0
|
|
|
|
|
0
|
my $nrlines = 0; |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
0
|
local $_; |
|
139
|
0
|
|
|
|
|
0
|
local *IN; |
|
140
|
|
|
|
|
|
|
|
|
141
|
0
|
0
|
|
|
|
0
|
open IN, '<:raw', $file |
|
142
|
|
|
|
|
|
|
or die "Cannot read from $file: $!\n"; |
|
143
|
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
0
|
$nrlines++ while ; |
|
145
|
0
|
|
|
|
|
0
|
close IN; |
|
146
|
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
0
|
$self->{MMBF_nrlines} = $nrlines; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
#------------------------------------------ |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub size() |
|
153
|
2
|
|
|
2
|
1
|
6
|
{ my $self = shift; |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
return $self->{MMBF_size} |
|
156
|
2
|
50
|
|
|
|
10
|
if exists $self->{MMBF_size}; |
|
157
|
|
|
|
|
|
|
|
|
158
|
2
|
|
|
|
|
8
|
my $size = eval { -s $self->tempFilename }; |
|
|
2
|
|
|
|
|
7
|
|
|
159
|
|
|
|
|
|
|
|
|
160
|
2
|
50
|
|
|
|
12
|
$size -= $self->nrLines |
|
161
|
|
|
|
|
|
|
if $Mail::Message::crlf_platform; # remove count for extra CR's |
|
162
|
|
|
|
|
|
|
|
|
163
|
2
|
|
|
|
|
16
|
$self->{MMBF_size} = $size; |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub string() |
|
167
|
3
|
|
|
3
|
1
|
676
|
{ my $self = shift; |
|
168
|
|
|
|
|
|
|
|
|
169
|
3
|
|
|
|
|
10
|
my $file = $self->tempFilename; |
|
170
|
|
|
|
|
|
|
|
|
171
|
3
|
|
|
|
|
15
|
local *IN; |
|
172
|
|
|
|
|
|
|
|
|
173
|
3
|
50
|
|
|
|
161
|
open IN, '<:raw', $file |
|
174
|
|
|
|
|
|
|
or die "Cannot read from $file: $!\n"; |
|
175
|
|
|
|
|
|
|
|
|
176
|
3
|
|
|
|
|
134
|
my $return = join '', ; |
|
177
|
3
|
|
|
|
|
37
|
close IN; |
|
178
|
|
|
|
|
|
|
|
|
179
|
3
|
|
|
|
|
36
|
$return; |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub lines() |
|
183
|
3
|
|
|
3
|
1
|
576
|
{ my $self = shift; |
|
184
|
|
|
|
|
|
|
|
|
185
|
3
|
|
|
|
|
11
|
my $file = $self->tempFilename; |
|
186
|
|
|
|
|
|
|
|
|
187
|
3
|
|
|
|
|
13
|
local *IN; |
|
188
|
3
|
50
|
|
|
|
120
|
open IN, '<:raw', $file |
|
189
|
|
|
|
|
|
|
or die "Cannot read from $file: $!\n"; |
|
190
|
|
|
|
|
|
|
|
|
191
|
3
|
|
|
|
|
83
|
my @r = ; |
|
192
|
3
|
|
|
|
|
33
|
close IN; |
|
193
|
|
|
|
|
|
|
|
|
194
|
3
|
|
|
|
|
17
|
$self->{MMBF_nrlines} = @r; |
|
195
|
3
|
100
|
|
|
|
34
|
wantarray ? @r: \@r; |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub file() |
|
199
|
0
|
|
|
0
|
1
|
0
|
{ open my $tmp, '<:raw', shift->tempFilename; |
|
200
|
0
|
|
|
|
|
0
|
$tmp; |
|
201
|
|
|
|
|
|
|
} |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
sub print(;$) |
|
204
|
2
|
|
|
2
|
1
|
130
|
{ my $self = shift; |
|
205
|
2
|
|
33
|
|
|
14
|
my $fh = shift || select; |
|
206
|
2
|
|
|
|
|
19
|
my $file = $self->tempFilename; |
|
207
|
|
|
|
|
|
|
|
|
208
|
2
|
|
|
|
|
8
|
local $_; |
|
209
|
2
|
|
|
|
|
7
|
local *IN; |
|
210
|
|
|
|
|
|
|
|
|
211
|
2
|
50
|
|
|
|
93
|
open IN, '<:raw', $file |
|
212
|
|
|
|
|
|
|
or croak "Cannot read from $file: $!\n"; |
|
213
|
|
|
|
|
|
|
|
|
214
|
2
|
50
|
|
|
|
14
|
if(ref $fh eq 'GLOB') {print $fh $_ while } |
|
|
0
|
|
|
|
|
0
|
|
|
215
|
2
|
|
|
|
|
50
|
else {$fh->print($_) while } |
|
216
|
2
|
|
|
|
|
147
|
close IN; |
|
217
|
|
|
|
|
|
|
|
|
218
|
2
|
|
|
|
|
14
|
$self; |
|
219
|
|
|
|
|
|
|
} |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
sub read($$;$@) |
|
222
|
0
|
|
|
0
|
1
|
0
|
{ my ($self, $parser, $head, $bodytype) = splice @_, 0, 4; |
|
223
|
0
|
|
|
|
|
0
|
my $file = $self->tempFilename; |
|
224
|
|
|
|
|
|
|
|
|
225
|
0
|
|
|
|
|
0
|
local *OUT; |
|
226
|
|
|
|
|
|
|
|
|
227
|
0
|
0
|
|
|
|
0
|
open OUT, '>:raw', $file |
|
228
|
|
|
|
|
|
|
or die "Cannot write to $file: $!.\n"; |
|
229
|
|
|
|
|
|
|
|
|
230
|
0
|
|
|
|
|
0
|
(my $begin, my $end, $self->{MMBF_nrlines}) = $parser->bodyAsFile(\*OUT,@_); |
|
231
|
0
|
|
|
|
|
0
|
close OUT; |
|
232
|
|
|
|
|
|
|
|
|
233
|
0
|
|
|
|
|
0
|
$self->fileLocation($begin, $end); |
|
234
|
0
|
|
|
|
|
0
|
$self; |
|
235
|
|
|
|
|
|
|
} |
|
236
|
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
# on UNIX always true. Expensive to calculate on Windows: message size |
|
238
|
|
|
|
|
|
|
# may be off-by-one in rare cases. |
|
239
|
0
|
|
|
0
|
1
|
0
|
sub endsOnNewline() { shift->size==0 } |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
#------------------------------------------ |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
sub tempFilename(;$) |
|
245
|
15
|
|
|
15
|
1
|
3533
|
{ my $self = shift; |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
@_ ? ($self->{MMBF_filename} = shift) |
|
248
|
|
|
|
|
|
|
: $self->{MMBF_filename} ? $self->{MMBF_filename} |
|
249
|
15
|
100
|
|
|
|
356
|
: ($self->{MMBF_filename} = (tempfile)[1]); |
|
|
|
50
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
} |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
#------------------------------------------ |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
|
|
255
|
2
|
|
|
2
|
|
368
|
sub DESTROY { unlink shift->tempFilename } |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
#------------------------------------------ |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
1; |