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::Body::File; |
10
|
31
|
|
|
31
|
|
977
|
use vars '$VERSION'; |
|
31
|
|
|
|
|
95
|
|
|
31
|
|
|
|
|
1561
|
|
11
|
|
|
|
|
|
|
$VERSION = '3.012'; |
12
|
|
|
|
|
|
|
|
13
|
31
|
|
|
31
|
|
156
|
use base 'Mail::Message::Body'; |
|
31
|
|
|
|
|
165
|
|
|
31
|
|
|
|
|
3848
|
|
14
|
|
|
|
|
|
|
|
15
|
31
|
|
|
31
|
|
213
|
use strict; |
|
31
|
|
|
|
|
56
|
|
|
31
|
|
|
|
|
780
|
|
16
|
31
|
|
|
31
|
|
147
|
use warnings; |
|
31
|
|
|
|
|
67
|
|
|
31
|
|
|
|
|
887
|
|
17
|
|
|
|
|
|
|
|
18
|
31
|
|
|
31
|
|
3190
|
use Mail::Box::Parser; |
|
31
|
|
|
|
|
72
|
|
|
31
|
|
|
|
|
779
|
|
19
|
31
|
|
|
31
|
|
7113
|
use Mail::Message; |
|
31
|
|
|
|
|
92
|
|
|
31
|
|
|
|
|
1006
|
|
20
|
|
|
|
|
|
|
|
21
|
31
|
|
|
31
|
|
347
|
use Carp; |
|
31
|
|
|
|
|
85
|
|
|
31
|
|
|
|
|
1991
|
|
22
|
31
|
|
|
31
|
|
21484
|
use File::Temp qw/tempfile/; |
|
31
|
|
|
|
|
308911
|
|
|
31
|
|
|
|
|
2064
|
|
23
|
31
|
|
|
31
|
|
6416
|
use File::Copy qw/copy/; |
|
31
|
|
|
|
|
31517
|
|
|
31
|
|
|
|
|
38660
|
|
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
|
|
5
|
{ my ($self, $fh) = @_; |
56
|
1
|
|
|
|
|
6
|
my $file = $self->tempFilename; |
57
|
1
|
|
|
|
|
924
|
my $nrlines = 0; |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
5
|
local *OUT; |
60
|
|
|
|
|
|
|
|
61
|
1
|
50
|
|
|
|
58
|
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
|
|
|
|
|
11
|
while(my $l = $fh->getline) |
67
|
5
|
|
|
|
|
249
|
{ print OUT $l; |
68
|
5
|
|
|
|
|
13
|
$nrlines++; |
69
|
|
|
|
|
|
|
} |
70
|
1
|
|
|
|
|
160
|
close OUT; |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
8
|
$self->{MMBF_nrlines} = $nrlines; |
73
|
1
|
|
|
|
|
11
|
$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
|
|
|
|
|
6
|
my $file = $self->tempFilename; |
102
|
|
|
|
|
|
|
|
103
|
1
|
|
|
|
|
669
|
local *OUT; |
104
|
|
|
|
|
|
|
|
105
|
1
|
50
|
|
|
|
62
|
unless(open OUT, '>:raw', $file) |
106
|
0
|
|
|
|
|
0
|
{ $self->log(ERROR => "Cannot write to $file: $!"); |
107
|
0
|
|
|
|
|
0
|
return; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
11
|
print OUT @$lines; |
111
|
1
|
|
|
|
|
165
|
close OUT; |
112
|
|
|
|
|
|
|
|
113
|
1
|
|
|
|
|
7
|
$self->{MMBF_nrlines} = @$lines; |
114
|
1
|
|
|
|
|
10
|
$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
|
8
|
{ my $self = shift; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
return $self->{MMBF_nrlines} |
133
|
2
|
50
|
|
|
|
20
|
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
|
5
|
{ my $self = shift; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
return $self->{MMBF_size} |
156
|
2
|
50
|
|
|
|
9
|
if exists $self->{MMBF_size}; |
157
|
|
|
|
|
|
|
|
158
|
2
|
|
|
|
|
5
|
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
|
720
|
{ my $self = shift; |
168
|
|
|
|
|
|
|
|
169
|
3
|
|
|
|
|
12
|
my $file = $self->tempFilename; |
170
|
|
|
|
|
|
|
|
171
|
3
|
|
|
|
|
14
|
local *IN; |
172
|
|
|
|
|
|
|
|
173
|
3
|
50
|
|
|
|
185
|
open IN, '<:raw', $file |
174
|
|
|
|
|
|
|
or die "Cannot read from $file: $!\n"; |
175
|
|
|
|
|
|
|
|
176
|
3
|
|
|
|
|
148
|
my $return = join '', ; |
177
|
3
|
|
|
|
|
46
|
close IN; |
178
|
|
|
|
|
|
|
|
179
|
3
|
|
|
|
|
34
|
$return; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub lines() |
183
|
3
|
|
|
3
|
1
|
594
|
{ my $self = shift; |
184
|
|
|
|
|
|
|
|
185
|
3
|
|
|
|
|
11
|
my $file = $self->tempFilename; |
186
|
|
|
|
|
|
|
|
187
|
3
|
|
|
|
|
11
|
local *IN; |
188
|
3
|
50
|
|
|
|
112
|
open IN, '<:raw', $file |
189
|
|
|
|
|
|
|
or die "Cannot read from $file: $!\n"; |
190
|
|
|
|
|
|
|
|
191
|
3
|
|
|
|
|
144
|
my @r = ; |
192
|
3
|
|
|
|
|
31
|
close IN; |
193
|
|
|
|
|
|
|
|
194
|
3
|
|
|
|
|
16
|
$self->{MMBF_nrlines} = @r; |
195
|
3
|
100
|
|
|
|
31
|
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
|
58
|
{ my $self = shift; |
205
|
2
|
|
33
|
|
|
13
|
my $fh = shift || select; |
206
|
2
|
|
|
|
|
17
|
my $file = $self->tempFilename; |
207
|
|
|
|
|
|
|
|
208
|
2
|
|
|
|
|
4
|
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
|
|
|
|
12
|
if(ref $fh eq 'GLOB') {print $fh $_ while } |
|
0
|
|
|
|
|
0
|
|
215
|
2
|
|
|
|
|
52
|
else {$fh->print($_) while } |
216
|
2
|
|
|
|
|
129
|
close IN; |
217
|
|
|
|
|
|
|
|
218
|
2
|
|
|
|
|
12
|
$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
|
2874
|
{ my $self = shift; |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
@_ ? ($self->{MMBF_filename} = shift) |
248
|
|
|
|
|
|
|
: $self->{MMBF_filename} ? $self->{MMBF_filename} |
249
|
15
|
100
|
|
|
|
380
|
: ($self->{MMBF_filename} = (tempfile)[1]); |
|
|
50
|
|
|
|
|
|
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
#------------------------------------------ |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
|
255
|
2
|
|
|
2
|
|
317
|
sub DESTROY { unlink shift->tempFilename } |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
#------------------------------------------ |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
1; |