line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2001-2023 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::Body::File; |
10
|
34
|
|
|
34
|
|
870
|
use vars '$VERSION'; |
|
34
|
|
|
|
|
99
|
|
|
34
|
|
|
|
|
1828
|
|
11
|
|
|
|
|
|
|
$VERSION = '3.013'; |
12
|
|
|
|
|
|
|
|
13
|
34
|
|
|
34
|
|
227
|
use base 'Mail::Message::Body'; |
|
34
|
|
|
|
|
103
|
|
|
34
|
|
|
|
|
4672
|
|
14
|
|
|
|
|
|
|
|
15
|
34
|
|
|
34
|
|
257
|
use strict; |
|
34
|
|
|
|
|
74
|
|
|
34
|
|
|
|
|
851
|
|
16
|
34
|
|
|
34
|
|
190
|
use warnings; |
|
34
|
|
|
|
|
65
|
|
|
34
|
|
|
|
|
1162
|
|
17
|
|
|
|
|
|
|
|
18
|
34
|
|
|
34
|
|
3760
|
use Mail::Box::Parser; |
|
34
|
|
|
|
|
80
|
|
|
34
|
|
|
|
|
978
|
|
19
|
34
|
|
|
34
|
|
8747
|
use Mail::Message; |
|
34
|
|
|
|
|
120
|
|
|
34
|
|
|
|
|
1106
|
|
20
|
|
|
|
|
|
|
|
21
|
34
|
|
|
34
|
|
227
|
use Carp; |
|
34
|
|
|
|
|
112
|
|
|
34
|
|
|
|
|
2115
|
|
22
|
34
|
|
|
34
|
|
27009
|
use File::Temp qw/tempfile/; |
|
34
|
|
|
|
|
393058
|
|
|
34
|
|
|
|
|
2543
|
|
23
|
34
|
|
|
34
|
|
8217
|
use File::Copy qw/copy/; |
|
34
|
|
|
|
|
39362
|
|
|
34
|
|
|
|
|
50290
|
|
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
|
|
3
|
{ my ($self, $fh) = @_; |
56
|
1
|
|
|
|
|
4
|
my $file = $self->tempFilename; |
57
|
1
|
|
|
|
|
758
|
my $nrlines = 0; |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
5
|
local *OUT; |
60
|
|
|
|
|
|
|
|
61
|
1
|
50
|
|
|
|
62
|
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
|
|
|
|
|
40
|
while(my $l = $fh->getline) |
67
|
5
|
|
|
|
|
308
|
{ print OUT $l; |
68
|
5
|
|
|
|
|
12
|
$nrlines++; |
69
|
|
|
|
|
|
|
} |
70
|
1
|
|
|
|
|
134
|
close OUT; |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
11
|
$self->{MMBF_nrlines} = $nrlines; |
73
|
1
|
|
|
|
|
8
|
$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
|
|
4
|
{ my ($self, $lines) = @_; |
101
|
1
|
|
|
|
|
3
|
my $file = $self->tempFilename; |
102
|
|
|
|
|
|
|
|
103
|
1
|
|
|
|
|
358
|
local *OUT; |
104
|
|
|
|
|
|
|
|
105
|
1
|
50
|
|
|
|
60
|
unless(open OUT, '>:raw', $file) |
106
|
0
|
|
|
|
|
0
|
{ $self->log(ERROR => "Cannot write to $file: $!"); |
107
|
0
|
|
|
|
|
0
|
return; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
9
|
print OUT @$lines; |
111
|
1
|
|
|
|
|
84
|
close OUT; |
112
|
|
|
|
|
|
|
|
113
|
1
|
|
|
|
|
7
|
$self->{MMBF_nrlines} = @$lines; |
114
|
1
|
|
|
|
|
9
|
$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
|
|
|
|
19
|
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
|
|
|
|
|
3
|
my $size = eval { -s $self->tempFilename }; |
|
2
|
|
|
|
|
6
|
|
159
|
|
|
|
|
|
|
|
160
|
2
|
50
|
|
|
|
10
|
$size -= $self->nrLines |
161
|
|
|
|
|
|
|
if $Mail::Message::crlf_platform; # remove count for extra CR's |
162
|
|
|
|
|
|
|
|
163
|
2
|
|
|
|
|
14
|
$self->{MMBF_size} = $size; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub string() |
167
|
3
|
|
|
3
|
1
|
1144
|
{ my $self = shift; |
168
|
|
|
|
|
|
|
|
169
|
3
|
|
|
|
|
8
|
my $file = $self->tempFilename; |
170
|
|
|
|
|
|
|
|
171
|
3
|
|
|
|
|
10
|
local *IN; |
172
|
|
|
|
|
|
|
|
173
|
3
|
50
|
|
|
|
122
|
open IN, '<:raw', $file |
174
|
|
|
|
|
|
|
or die "Cannot read from $file: $!\n"; |
175
|
|
|
|
|
|
|
|
176
|
3
|
|
|
|
|
90
|
my $return = join '', ; |
177
|
3
|
|
|
|
|
37
|
close IN; |
178
|
|
|
|
|
|
|
|
179
|
3
|
|
|
|
|
32
|
$return; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub lines() |
183
|
3
|
|
|
3
|
1
|
691
|
{ my $self = shift; |
184
|
|
|
|
|
|
|
|
185
|
3
|
|
|
|
|
8
|
my $file = $self->tempFilename; |
186
|
|
|
|
|
|
|
|
187
|
3
|
|
|
|
|
9
|
local *IN; |
188
|
3
|
50
|
|
|
|
120
|
open IN, '<:raw', $file |
189
|
|
|
|
|
|
|
or die "Cannot read from $file: $!\n"; |
190
|
|
|
|
|
|
|
|
191
|
3
|
|
|
|
|
90
|
my @r = ; |
192
|
3
|
|
|
|
|
33
|
close IN; |
193
|
|
|
|
|
|
|
|
194
|
3
|
|
|
|
|
13
|
$self->{MMBF_nrlines} = @r; |
195
|
3
|
100
|
|
|
|
29
|
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
|
39
|
{ my $self = shift; |
205
|
2
|
|
33
|
|
|
11
|
my $fh = shift || select; |
206
|
2
|
|
|
|
|
18
|
my $file = $self->tempFilename; |
207
|
|
|
|
|
|
|
|
208
|
2
|
|
|
|
|
6
|
local $_; |
209
|
2
|
|
|
|
|
5
|
local *IN; |
210
|
|
|
|
|
|
|
|
211
|
2
|
50
|
|
|
|
86
|
open IN, '<:raw', $file |
212
|
|
|
|
|
|
|
or croak "Cannot read from $file: $!\n"; |
213
|
|
|
|
|
|
|
|
214
|
2
|
50
|
|
|
|
10
|
if(ref $fh eq 'GLOB') {print $fh $_ while } |
|
0
|
|
|
|
|
0
|
|
215
|
2
|
|
|
|
|
59
|
else {$fh->print($_) while } |
216
|
2
|
|
|
|
|
146
|
close IN; |
217
|
|
|
|
|
|
|
|
218
|
2
|
|
|
|
|
13
|
$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
|
4182
|
{ my $self = shift; |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
@_ ? ($self->{MMBF_filename} = shift) |
248
|
|
|
|
|
|
|
: $self->{MMBF_filename} ? $self->{MMBF_filename} |
249
|
15
|
100
|
|
|
|
241
|
: ($self->{MMBF_filename} = (tempfile)[1]); |
|
|
50
|
|
|
|
|
|
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
#------------------------------------------ |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
|
255
|
2
|
|
|
2
|
|
429
|
sub DESTROY { unlink shift->tempFilename } |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
#------------------------------------------ |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
1; |