line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2001-2020 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-Box. 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::Box::Dir::Message; |
10
|
14
|
|
|
14
|
|
1256
|
use vars '$VERSION'; |
|
14
|
|
|
|
|
40
|
|
|
14
|
|
|
|
|
751
|
|
11
|
|
|
|
|
|
|
$VERSION = '3.009'; |
12
|
|
|
|
|
|
|
|
13
|
14
|
|
|
14
|
|
84
|
use base 'Mail::Box::Message'; |
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
1759
|
|
14
|
|
|
|
|
|
|
|
15
|
14
|
|
|
14
|
|
95
|
use strict; |
|
14
|
|
|
|
|
127
|
|
|
14
|
|
|
|
|
356
|
|
16
|
14
|
|
|
14
|
|
78
|
use warnings; |
|
14
|
|
|
|
|
27
|
|
|
14
|
|
|
|
|
473
|
|
17
|
|
|
|
|
|
|
|
18
|
14
|
|
|
14
|
|
94
|
use File::Copy qw/move/; |
|
14
|
|
|
|
|
43
|
|
|
14
|
|
|
|
|
851
|
|
19
|
14
|
|
|
14
|
|
634
|
use IO::File; |
|
14
|
|
|
|
|
1077
|
|
|
14
|
|
|
|
|
5058
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub init($) |
23
|
737
|
|
|
737
|
0
|
5584
|
{ my ($self, $args) = @_; |
24
|
737
|
|
|
|
|
2127
|
$self->SUPER::init($args); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$self->filename($args->{filename}) |
27
|
737
|
50
|
|
|
|
2461
|
if $args->{filename}; |
28
|
|
|
|
|
|
|
|
29
|
737
|
|
|
|
|
1234
|
$self->{MBDM_fix_header} = $args->{fix_header}; |
30
|
737
|
|
|
|
|
1769
|
$self; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#------------------------------------------- |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#------------------------------------------- |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub print(;$) |
39
|
226
|
|
|
226
|
1
|
387
|
{ my $self = shift; |
40
|
226
|
|
33
|
|
|
507
|
my $out = shift || select; |
41
|
|
|
|
|
|
|
|
42
|
226
|
100
|
|
|
|
648
|
return $self->SUPER::print($out) |
43
|
|
|
|
|
|
|
if $self->isModified; |
44
|
|
|
|
|
|
|
|
45
|
181
|
|
|
|
|
445
|
my $filename = $self->filename; |
46
|
181
|
50
|
33
|
|
|
3465
|
if($filename && -r $filename) |
47
|
181
|
50
|
|
|
|
5904
|
{ if(open my $in, '<:raw', $filename) |
48
|
181
|
|
|
|
|
483
|
{ local $_; |
49
|
181
|
|
|
|
|
10785
|
print $out $_ while <$in>; |
50
|
181
|
|
|
|
|
1688
|
close $in; |
51
|
181
|
|
|
|
|
944
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
$self->SUPER::print($out); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
1; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#------------------------------------------- |
61
|
|
|
|
|
|
|
|
62
|
14
|
|
|
14
|
|
10372
|
BEGIN { *write = \&print } # simply alias |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
#------------------------------------------- |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub filename(;$) |
68
|
3824
|
|
|
3824
|
1
|
5558
|
{ my $self = shift; |
69
|
3824
|
100
|
|
|
|
10521
|
@_ ? ($self->{MBDM_filename} = shift) : $self->{MBDM_filename}; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#------------------------------------------- |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Asking the filesystem for the size is faster counting (in |
76
|
|
|
|
|
|
|
# many situations. It even may be lazy. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub size() |
79
|
0
|
|
|
0
|
1
|
0
|
{ my $self = shift; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
0
|
unless($self->isModified) |
82
|
0
|
|
|
|
|
0
|
{ my $filename = $self->filename; |
83
|
0
|
0
|
|
|
|
0
|
if(defined $filename) |
84
|
0
|
|
|
|
|
0
|
{ my $size = -s $filename; |
85
|
0
|
0
|
|
|
|
0
|
return $size if defined $size; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
0
|
$self->SUPER::size; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#------------------------------------------- |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub diskDelete() |
95
|
24
|
|
|
24
|
1
|
70
|
{ my $self = shift; |
96
|
24
|
|
|
|
|
98
|
$self->SUPER::diskDelete; |
97
|
|
|
|
|
|
|
|
98
|
24
|
|
|
|
|
54
|
my $filename = $self->filename; |
99
|
24
|
50
|
|
|
|
1298
|
unlink $filename if $filename; |
100
|
24
|
|
|
|
|
165
|
$self; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
#------------------------------------------- |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub parser() |
107
|
287
|
|
|
287
|
1
|
418
|
{ my $self = shift; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $parser = Mail::Box::Parser->new |
110
|
|
|
|
|
|
|
( filename => $self->{MBDM_filename} |
111
|
|
|
|
|
|
|
, mode => 'r' |
112
|
|
|
|
|
|
|
, fix_header_errors => $self->{MBDM_fix_header} |
113
|
287
|
|
|
|
|
972
|
, $self->logSettings |
114
|
|
|
|
|
|
|
); |
115
|
|
|
|
|
|
|
|
116
|
287
|
50
|
|
|
|
73082
|
unless($parser) |
117
|
0
|
|
|
|
|
0
|
{ $self->log(ERROR => "Cannot create parser for $self->{MBDM_filename}."); |
118
|
0
|
|
|
|
|
0
|
return; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
287
|
|
|
|
|
805
|
$parser; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#------------------------------------------- |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub loadHead() |
128
|
406
|
|
|
406
|
1
|
2699
|
{ my $self = shift; |
129
|
406
|
|
|
|
|
951
|
my $head = $self->head; |
130
|
406
|
100
|
|
|
|
2607
|
return $head unless $head->isDelayed; |
131
|
|
|
|
|
|
|
|
132
|
279
|
|
|
|
|
640
|
my $folder = $self->folder; |
133
|
279
|
|
|
|
|
983
|
$folder->lazyPermitted(1); |
134
|
|
|
|
|
|
|
|
135
|
279
|
50
|
|
|
|
620
|
my $parser = $self->parser or return; |
136
|
279
|
|
|
|
|
1139
|
$self->readFromParser($parser); |
137
|
279
|
|
|
|
|
3803
|
$parser->stop; |
138
|
|
|
|
|
|
|
|
139
|
279
|
|
|
|
|
17012
|
$folder->lazyPermitted(0); |
140
|
|
|
|
|
|
|
|
141
|
279
|
|
|
|
|
942
|
$self->log(PROGRESS => 'Loaded delayed head.'); |
142
|
279
|
|
|
|
|
5069
|
$self->head; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
#------------------------------------------- |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub loadBody() |
149
|
150
|
|
|
150
|
1
|
287
|
{ my $self = shift; |
150
|
|
|
|
|
|
|
|
151
|
150
|
|
|
|
|
385
|
my $body = $self->body; |
152
|
150
|
100
|
|
|
|
1212
|
return $body unless $body->isDelayed; |
153
|
|
|
|
|
|
|
|
154
|
8
|
|
|
|
|
37
|
my $head = $self->head; |
155
|
8
|
50
|
|
|
|
64
|
my $parser = $self->parser or return; |
156
|
|
|
|
|
|
|
|
157
|
8
|
100
|
|
|
|
45
|
if($head->isDelayed) |
158
|
2
|
|
|
|
|
25
|
{ $head = $self->readHead($parser); |
159
|
2
|
50
|
|
|
|
5787
|
if(defined $head) |
160
|
2
|
|
|
|
|
16
|
{ $self->log(PROGRESS => 'Loaded delayed head.'); |
161
|
2
|
|
|
|
|
41
|
$self->head($head); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else |
164
|
0
|
|
|
|
|
0
|
{ $self->log(ERROR => 'Unable to read delayed head.'); |
165
|
0
|
|
|
|
|
0
|
return; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
else |
169
|
6
|
|
|
|
|
34
|
{ my ($begin, $end) = $body->fileLocation; |
170
|
6
|
|
|
|
|
32
|
$parser->filePosition($begin); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
8
|
|
|
|
|
330
|
my $newbody = $self->readBody($parser, $head); |
174
|
8
|
|
|
|
|
9925
|
$parser->stop; |
175
|
|
|
|
|
|
|
|
176
|
8
|
50
|
|
|
|
525
|
unless(defined $newbody) |
177
|
0
|
|
|
|
|
0
|
{ $self->log(ERROR => 'Unable to read delayed body.'); |
178
|
0
|
|
|
|
|
0
|
return; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
8
|
|
|
|
|
114
|
$self->log(PROGRESS => 'Loaded delayed body.'); |
182
|
8
|
|
|
|
|
163
|
$self->storeBody($newbody->contentInfoFrom($head)); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
#------------------------------------------- |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub create($) |
189
|
316
|
|
|
316
|
1
|
592
|
{ my ($self, $filename) = @_; |
190
|
|
|
|
|
|
|
|
191
|
316
|
|
100
|
|
|
586
|
my $old = $self->filename || ''; |
192
|
316
|
100
|
66
|
|
|
938
|
return $self if $filename eq $old && !$self->isModified; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
# Write the new data to a new file. |
195
|
|
|
|
|
|
|
|
196
|
225
|
|
|
|
|
399
|
my $new = $filename . '.new'; |
197
|
225
|
|
|
|
|
1005
|
my $newfile = IO::File->new($new, 'w'); |
198
|
225
|
50
|
|
|
|
26658
|
$self->log(ERROR => "Cannot write message to $new: $!"), return |
199
|
|
|
|
|
|
|
unless $newfile; |
200
|
|
|
|
|
|
|
|
201
|
225
|
|
|
|
|
928
|
$self->write($newfile); |
202
|
225
|
|
|
|
|
13542
|
$newfile->close; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# Accept the new data |
205
|
|
|
|
|
|
|
# maildir produces warning where not expected... |
206
|
|
|
|
|
|
|
# $self->log(WARNING => "Failed to remove $old: $!") |
207
|
|
|
|
|
|
|
# if $old && !unlink $old; |
208
|
|
|
|
|
|
|
|
209
|
225
|
100
|
|
|
|
15492
|
unlink $old if $old; |
210
|
|
|
|
|
|
|
|
211
|
225
|
50
|
|
|
|
1056
|
$self->log(ERROR => "Failed to move $new to $filename: $!"), return |
212
|
|
|
|
|
|
|
unless move($new, $filename); |
213
|
|
|
|
|
|
|
|
214
|
225
|
|
|
|
|
17547
|
$self->modified(0); |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
# Do not affect flags for Maildir (and some other) which keep it |
217
|
|
|
|
|
|
|
# in there. Flags will be processed later. |
218
|
225
|
|
|
|
|
2437
|
$self->Mail::Box::Dir::Message::filename($filename); |
219
|
|
|
|
|
|
|
|
220
|
225
|
|
|
|
|
1197
|
$self; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
#------------------------------------------- |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
1; |