line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2001-2019 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::MH::Index; |
10
|
11
|
|
|
11
|
|
1148
|
use vars '$VERSION'; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
484
|
|
11
|
|
|
|
|
|
|
$VERSION = '3.008'; |
12
|
|
|
|
|
|
|
|
13
|
11
|
|
|
11
|
|
51
|
use base 'Mail::Reporter'; |
|
11
|
|
|
|
|
19
|
|
|
11
|
|
|
|
|
874
|
|
14
|
|
|
|
|
|
|
|
15
|
11
|
|
|
11
|
|
60
|
use strict; |
|
11
|
|
|
|
|
18
|
|
|
11
|
|
|
|
|
213
|
|
16
|
11
|
|
|
11
|
|
51
|
use warnings; |
|
11
|
|
|
|
|
25
|
|
|
11
|
|
|
|
|
327
|
|
17
|
|
|
|
|
|
|
|
18
|
11
|
|
|
11
|
|
4106
|
use Mail::Message::Head::Subset; |
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
309
|
|
19
|
11
|
|
|
11
|
|
61
|
use Carp; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
6747
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#------------------------------------------- |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub init($) |
26
|
4
|
|
|
4
|
0
|
85
|
{ my ($self, $args) = @_; |
27
|
4
|
|
|
|
|
19
|
$self->SUPER::init($args); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$self->{MBMI_filename} = $args->{filename} |
30
|
4
|
50
|
|
|
|
50
|
or croak "No index filename specified."; |
31
|
|
|
|
|
|
|
|
32
|
4
|
|
50
|
|
|
18
|
$self->{MBMI_head_wrap} = $args->{head_wrap} || 72; |
33
|
|
|
|
|
|
|
$self->{MBMI_head_type} |
34
|
4
|
|
50
|
|
|
20
|
= $args->{head_type} || 'Mail::Message::Head::Subset'; |
35
|
|
|
|
|
|
|
|
36
|
4
|
|
|
|
|
16
|
$self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
#------------------------------------------- |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
6
|
|
|
6
|
1
|
32
|
sub filename() {shift->{MBMI_filename}} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#------------------------------------------- |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub write(@) |
48
|
5
|
|
|
5
|
1
|
9
|
{ my $self = shift; |
49
|
5
|
50
|
|
|
|
16
|
my $index = $self->filename or return $self; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Remove empty index-file. |
52
|
5
|
50
|
|
|
|
21
|
unless(@_) |
53
|
0
|
|
|
|
|
0
|
{ unlink $index; |
54
|
0
|
|
|
|
|
0
|
return $self; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
5
|
|
|
|
|
16
|
local *INDEX; |
58
|
5
|
50
|
|
|
|
285
|
open INDEX, '>:raw', $index |
59
|
|
|
|
|
|
|
or return $self; |
60
|
|
|
|
|
|
|
|
61
|
5
|
|
|
|
|
20
|
my $fieldtype = 'Mail::Message::Field'; |
62
|
5
|
|
|
|
|
10
|
my $written = 0; |
63
|
|
|
|
|
|
|
|
64
|
5
|
|
|
|
|
15
|
foreach my $msg (@_) |
65
|
178
|
|
|
|
|
446
|
{ my $head = $msg->head; |
66
|
178
|
50
|
66
|
|
|
1684
|
next if $head->isDelayed && $head->isa('Mail::Message::Head::Subset'); |
67
|
|
|
|
|
|
|
|
68
|
178
|
|
|
|
|
964
|
my $filename = $msg->filename; |
69
|
178
|
|
|
|
|
2818
|
print INDEX "X-MailBox-Filename: $filename\n" |
70
|
|
|
|
|
|
|
, 'X-MailBox-Size: ', (-s $filename), "\n"; |
71
|
|
|
|
|
|
|
|
72
|
178
|
|
|
|
|
1587
|
$head->print(\*INDEX); |
73
|
178
|
|
|
|
|
36715
|
$written++; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
5
|
|
|
|
|
279
|
close INDEX; |
77
|
|
|
|
|
|
|
|
78
|
5
|
50
|
|
|
|
23
|
$written or unlink $index; |
79
|
|
|
|
|
|
|
|
80
|
5
|
|
|
|
|
30
|
$self; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#------------------------------------------- |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub append(@) |
87
|
1
|
|
|
1
|
1
|
3
|
{ my $self = shift; |
88
|
1
|
50
|
|
|
|
5
|
my $index = $self->filename or return $self; |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
3
|
local *INDEX; |
91
|
1
|
50
|
|
|
|
45
|
open INDEX, '>>:raw', $index |
92
|
|
|
|
|
|
|
or return $self; |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
4
|
my $fieldtype = 'Mail::Message::Field'; |
95
|
|
|
|
|
|
|
|
96
|
1
|
|
|
|
|
3
|
foreach my $msg (@_) |
97
|
1
|
|
|
|
|
5
|
{ my $head = $msg->head; |
98
|
1
|
50
|
33
|
|
|
10
|
next if $head->isDelayed && $head->isa('Mail::Message::Head::Subset'); |
99
|
|
|
|
|
|
|
|
100
|
1
|
|
|
|
|
4
|
my $filename = $msg->filename; |
101
|
1
|
|
|
|
|
19
|
print INDEX "X-MailBox-Filename: $filename\n" |
102
|
|
|
|
|
|
|
, 'X-MailBox-Size: ', (-s $filename), "\n"; |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
8
|
$head->print(\*INDEX); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
134
|
close INDEX; |
108
|
1
|
|
|
|
|
6
|
$self; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#------------------------------------------- |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub read(;$) |
115
|
4
|
|
|
4
|
1
|
8
|
{ my $self = shift; |
116
|
4
|
|
|
|
|
9
|
my $filename = $self->{MBMI_filename}; |
117
|
|
|
|
|
|
|
|
118
|
4
|
50
|
|
|
|
32
|
my $parser = Mail::Box::Parser->new |
119
|
|
|
|
|
|
|
( filename => $filename |
120
|
|
|
|
|
|
|
, mode => 'r' |
121
|
|
|
|
|
|
|
) or return; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
0
|
my @options = ($self->logSettings, wrap_length => $self->{MBMI_head_wrap}); |
124
|
0
|
|
|
|
|
0
|
my $type = $self->{MBMI_head_type}; |
125
|
0
|
|
|
|
|
0
|
my $index_age= -M $filename; |
126
|
0
|
|
|
|
|
0
|
my %index; |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
0
|
while(my $head = $type->new(@options)->read($parser)) |
129
|
|
|
|
|
|
|
{ |
130
|
|
|
|
|
|
|
# cleanup the index from files which were renamed |
131
|
0
|
|
|
|
|
0
|
my $msgfile = $head->get('x-mailbox-filename'); |
132
|
0
|
|
|
|
|
0
|
my $size = int $head->get('x-mailbox-size'); |
133
|
0
|
0
|
0
|
|
|
0
|
next unless -f $msgfile && -s _ == $size; |
134
|
0
|
0
|
0
|
|
|
0
|
next if defined $index_age && -M _ < $index_age; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# keep this one |
137
|
0
|
|
|
|
|
0
|
$index{$msgfile} = $head; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
0
|
$parser->stop; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
0
|
$self->{MBMI_index} = \%index; |
143
|
0
|
|
|
|
|
0
|
$self; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
#------------------------------------------- |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub get($) |
150
|
94
|
|
|
94
|
1
|
149
|
{ my ($self, $msgfile) = @_; |
151
|
94
|
|
|
|
|
156
|
$self->{MBMI_index}{$msgfile}; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
#------------------------------------------- |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
1; |