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-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
|
|
1191
|
use vars '$VERSION'; |
|
14
|
|
|
|
|
40
|
|
|
14
|
|
|
|
|
754
|
|
11
|
|
|
|
|
|
|
$VERSION = '3.010'; |
12
|
|
|
|
|
|
|
|
13
|
14
|
|
|
14
|
|
93
|
use base 'Mail::Box::Message'; |
|
14
|
|
|
|
|
49
|
|
|
14
|
|
|
|
|
1710
|
|
14
|
|
|
|
|
|
|
|
15
|
14
|
|
|
14
|
|
95
|
use strict; |
|
14
|
|
|
|
|
131
|
|
|
14
|
|
|
|
|
320
|
|
16
|
14
|
|
|
14
|
|
74
|
use warnings; |
|
14
|
|
|
|
|
50
|
|
|
14
|
|
|
|
|
500
|
|
17
|
|
|
|
|
|
|
|
18
|
14
|
|
|
14
|
|
99
|
use File::Copy qw/move/; |
|
14
|
|
|
|
|
36
|
|
|
14
|
|
|
|
|
876
|
|
19
|
14
|
|
|
14
|
|
577
|
use IO::File; |
|
14
|
|
|
|
|
1137
|
|
|
14
|
|
|
|
|
5416
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub init($) |
23
|
737
|
|
|
737
|
0
|
5895
|
{ my ($self, $args) = @_; |
24
|
737
|
|
|
|
|
2140
|
$self->SUPER::init($args); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$self->filename($args->{filename}) |
27
|
737
|
50
|
|
|
|
2577
|
if $args->{filename}; |
28
|
|
|
|
|
|
|
|
29
|
737
|
|
|
|
|
1257
|
$self->{MBDM_fix_header} = $args->{fix_header}; |
30
|
737
|
|
|
|
|
1695
|
$self; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#------------------------------------------- |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#------------------------------------------- |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub print(;$) |
39
|
226
|
|
|
226
|
1
|
412
|
{ my $self = shift; |
40
|
226
|
|
33
|
|
|
520
|
my $out = shift || select; |
41
|
|
|
|
|
|
|
|
42
|
226
|
100
|
|
|
|
674
|
return $self->SUPER::print($out) |
43
|
|
|
|
|
|
|
if $self->isModified; |
44
|
|
|
|
|
|
|
|
45
|
181
|
|
|
|
|
471
|
my $filename = $self->filename; |
46
|
181
|
50
|
33
|
|
|
3456
|
if($filename && -r $filename) |
47
|
181
|
50
|
|
|
|
6521
|
{ if(open my $in, '<:raw', $filename) |
48
|
181
|
|
|
|
|
550
|
{ local $_; |
49
|
181
|
|
|
|
|
12463
|
print $out $_ while <$in>; |
50
|
181
|
|
|
|
|
1851
|
close $in; |
51
|
181
|
|
|
|
|
1028
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
$self->SUPER::print($out); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
1; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#------------------------------------------- |
61
|
|
|
|
|
|
|
|
62
|
14
|
|
|
14
|
|
10837
|
BEGIN { *write = \&print } # simply alias |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
#------------------------------------------- |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub filename(;$) |
68
|
3824
|
|
|
3824
|
1
|
5576
|
{ my $self = shift; |
69
|
3824
|
100
|
|
|
|
10477
|
@_ ? ($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
|
42
|
{ my $self = shift; |
96
|
24
|
|
|
|
|
91
|
$self->SUPER::diskDelete; |
97
|
|
|
|
|
|
|
|
98
|
24
|
|
|
|
|
52
|
my $filename = $self->filename; |
99
|
24
|
50
|
|
|
|
1388
|
unlink $filename if $filename; |
100
|
24
|
|
|
|
|
155
|
$self; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
#------------------------------------------- |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub parser() |
107
|
287
|
|
|
287
|
1
|
417
|
{ 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
|
|
|
|
71285
|
unless($parser) |
117
|
0
|
|
|
|
|
0
|
{ $self->log(ERROR => "Cannot create parser for $self->{MBDM_filename}."); |
118
|
0
|
|
|
|
|
0
|
return; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
287
|
|
|
|
|
857
|
$parser; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#------------------------------------------- |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub loadHead() |
128
|
406
|
|
|
406
|
1
|
2828
|
{ my $self = shift; |
129
|
406
|
|
|
|
|
978
|
my $head = $self->head; |
130
|
406
|
100
|
|
|
|
2607
|
return $head unless $head->isDelayed; |
131
|
|
|
|
|
|
|
|
132
|
279
|
|
|
|
|
645
|
my $folder = $self->folder; |
133
|
279
|
|
|
|
|
908
|
$folder->lazyPermitted(1); |
134
|
|
|
|
|
|
|
|
135
|
279
|
50
|
|
|
|
592
|
my $parser = $self->parser or return; |
136
|
279
|
|
|
|
|
1089
|
$self->readFromParser($parser); |
137
|
279
|
|
|
|
|
3618
|
$parser->stop; |
138
|
|
|
|
|
|
|
|
139
|
279
|
|
|
|
|
18123
|
$folder->lazyPermitted(0); |
140
|
|
|
|
|
|
|
|
141
|
279
|
|
|
|
|
888
|
$self->log(PROGRESS => 'Loaded delayed head.'); |
142
|
279
|
|
|
|
|
5015
|
$self->head; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
#------------------------------------------- |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub loadBody() |
149
|
150
|
|
|
150
|
1
|
243
|
{ my $self = shift; |
150
|
|
|
|
|
|
|
|
151
|
150
|
|
|
|
|
363
|
my $body = $self->body; |
152
|
150
|
100
|
|
|
|
1169
|
return $body unless $body->isDelayed; |
153
|
|
|
|
|
|
|
|
154
|
8
|
|
|
|
|
47
|
my $head = $self->head; |
155
|
8
|
50
|
|
|
|
89
|
my $parser = $self->parser or return; |
156
|
|
|
|
|
|
|
|
157
|
8
|
100
|
|
|
|
65
|
if($head->isDelayed) |
158
|
2
|
|
|
|
|
18
|
{ $head = $self->readHead($parser); |
159
|
2
|
50
|
|
|
|
5984
|
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
|
|
|
|
|
47
|
{ my ($begin, $end) = $body->fileLocation; |
170
|
6
|
|
|
|
|
42
|
$parser->filePosition($begin); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
8
|
|
|
|
|
356
|
my $newbody = $self->readBody($parser, $head); |
174
|
8
|
|
|
|
|
8832
|
$parser->stop; |
175
|
|
|
|
|
|
|
|
176
|
8
|
50
|
|
|
|
609
|
unless(defined $newbody) |
177
|
0
|
|
|
|
|
0
|
{ $self->log(ERROR => 'Unable to read delayed body.'); |
178
|
0
|
|
|
|
|
0
|
return; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
8
|
|
|
|
|
121
|
$self->log(PROGRESS => 'Loaded delayed body.'); |
182
|
8
|
|
|
|
|
174
|
$self->storeBody($newbody->contentInfoFrom($head)); |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
#------------------------------------------- |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub create($) |
189
|
316
|
|
|
316
|
1
|
628
|
{ my ($self, $filename) = @_; |
190
|
|
|
|
|
|
|
|
191
|
316
|
|
100
|
|
|
539
|
my $old = $self->filename || ''; |
192
|
316
|
100
|
66
|
|
|
888
|
return $self if $filename eq $old && !$self->isModified; |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
# Write the new data to a new file. |
195
|
|
|
|
|
|
|
|
196
|
225
|
|
|
|
|
408
|
my $new = $filename . '.new'; |
197
|
225
|
|
|
|
|
907
|
my $newfile = IO::File->new($new, 'w'); |
198
|
225
|
50
|
|
|
|
28964
|
$self->log(ERROR => "Cannot write message to $new: $!"), return |
199
|
|
|
|
|
|
|
unless $newfile; |
200
|
|
|
|
|
|
|
|
201
|
225
|
|
|
|
|
859
|
$self->write($newfile); |
202
|
225
|
|
|
|
|
14192
|
$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
|
|
|
|
17253
|
unlink $old if $old; |
210
|
|
|
|
|
|
|
|
211
|
225
|
50
|
|
|
|
1489
|
$self->log(ERROR => "Failed to move $new to $filename: $!"), return |
212
|
|
|
|
|
|
|
unless move($new, $filename); |
213
|
|
|
|
|
|
|
|
214
|
225
|
|
|
|
|
18321
|
$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
|
|
|
|
|
2529
|
$self->Mail::Box::Dir::Message::filename($filename); |
219
|
|
|
|
|
|
|
|
220
|
225
|
|
|
|
|
1253
|
$self; |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
#------------------------------------------- |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
1; |