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::MH::Labels; |
10
|
11
|
|
|
11
|
|
988
|
use vars '$VERSION'; |
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
634
|
|
11
|
|
|
|
|
|
|
$VERSION = '3.009'; |
12
|
|
|
|
|
|
|
|
13
|
11
|
|
|
11
|
|
62
|
use base 'Mail::Reporter'; |
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
1039
|
|
14
|
|
|
|
|
|
|
|
15
|
11
|
|
|
11
|
|
68
|
use strict; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
245
|
|
16
|
11
|
|
|
11
|
|
67
|
use warnings; |
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
323
|
|
17
|
|
|
|
|
|
|
|
18
|
11
|
|
|
11
|
|
60
|
use Mail::Message::Head::Subset; |
|
11
|
|
|
|
|
46
|
|
|
11
|
|
|
|
|
338
|
|
19
|
|
|
|
|
|
|
|
20
|
11
|
|
|
11
|
|
59
|
use File::Copy; |
|
11
|
|
|
|
|
30
|
|
|
11
|
|
|
|
|
588
|
|
21
|
11
|
|
|
11
|
|
66
|
use Carp; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
11443
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#------------------------------------------- |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub init($) |
28
|
21
|
|
|
21
|
0
|
464
|
{ my ($self, $args) = @_; |
29
|
21
|
|
|
|
|
115
|
$self->SUPER::init($args); |
30
|
|
|
|
|
|
|
$self->{MBML_filename} = $args->{filename} |
31
|
21
|
50
|
|
|
|
273
|
or croak "No label filename specified."; |
32
|
|
|
|
|
|
|
|
33
|
21
|
|
|
|
|
102
|
$self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#------------------------------------------- |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
29
|
|
|
29
|
1
|
82
|
sub filename() {shift->{MBML_filename}} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
#------------------------------------------- |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub get($) |
45
|
434
|
|
|
434
|
1
|
869
|
{ my ($self, $msgnr) = @_; |
46
|
434
|
|
|
|
|
910
|
$self->{MBML_labels}[$msgnr]; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#------------------------------------------- |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub read() |
53
|
17
|
|
|
17
|
1
|
84
|
{ my $self = shift; |
54
|
17
|
|
|
|
|
54
|
my $seq = $self->filename; |
55
|
|
|
|
|
|
|
|
56
|
17
|
100
|
|
|
|
678
|
open SEQ, '<:raw', $seq |
57
|
|
|
|
|
|
|
or return; |
58
|
|
|
|
|
|
|
|
59
|
9
|
|
|
|
|
33
|
my @labels; |
60
|
|
|
|
|
|
|
|
61
|
9
|
|
|
|
|
26
|
local $_; |
62
|
9
|
|
|
|
|
195
|
while() |
63
|
16
|
|
|
|
|
56
|
{ s/\s*\#.*$//; |
64
|
16
|
50
|
|
|
|
48
|
next unless length; |
65
|
|
|
|
|
|
|
|
66
|
16
|
50
|
|
|
|
118
|
next unless s/^\s*(\w+)\s*\:\s*//; |
67
|
16
|
|
|
|
|
51
|
my $label = $1; |
68
|
|
|
|
|
|
|
|
69
|
16
|
|
|
|
|
32
|
my $set = 1; |
70
|
16
|
100
|
|
|
|
67
|
if($label eq 'cur' ) { $label = 'current' } |
|
1
|
100
|
|
|
|
3
|
|
71
|
2
|
|
|
|
|
5
|
elsif($label eq 'unseen') { $label = 'seen'; $set = 0 } |
|
2
|
|
|
|
|
4
|
|
72
|
|
|
|
|
|
|
|
73
|
16
|
|
|
|
|
82
|
foreach (split /\s+/) |
74
|
32
|
100
|
|
|
|
157
|
{ if( /^(\d+)\-(\d+)\s*$/ ) |
|
|
50
|
|
|
|
|
|
75
|
10
|
|
|
|
|
68
|
{ push @{$labels[$_]}, $label, $set foreach $1..$2; |
|
78
|
|
|
|
|
254
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
elsif( /^\d+\s*$/ ) |
78
|
22
|
|
|
|
|
66
|
{ push @{$labels[$_]}, $label, $set; |
|
22
|
|
|
|
|
134
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
9
|
|
|
|
|
106
|
close SEQ; |
84
|
|
|
|
|
|
|
|
85
|
9
|
|
|
|
|
45
|
$self->{MBML_labels} = \@labels; |
86
|
9
|
|
|
|
|
45
|
$self; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
#------------------------------------------- |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub write(@) |
93
|
11
|
|
|
11
|
1
|
28
|
{ my $self = shift; |
94
|
11
|
|
|
|
|
40
|
my $filename = $self->filename; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Remove when no messages are left. |
97
|
11
|
50
|
|
|
|
38
|
unless(@_) |
98
|
0
|
|
|
|
|
0
|
{ unlink $filename; |
99
|
0
|
|
|
|
|
0
|
return $self; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
11
|
50
|
|
|
|
746
|
open my $out, '>:raw', $filename or return; |
103
|
11
|
|
|
|
|
108
|
$self->print($out, @_); |
104
|
11
|
|
|
|
|
372
|
close $out; |
105
|
|
|
|
|
|
|
|
106
|
11
|
|
|
|
|
86
|
$self; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
#------------------------------------------- |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub append(@) |
113
|
1
|
|
|
1
|
1
|
4
|
{ my $self = shift; |
114
|
1
|
|
|
|
|
5
|
my $filename = $self->filename; |
115
|
|
|
|
|
|
|
|
116
|
1
|
50
|
|
|
|
76
|
open(my $out, '>>:raw', $filename) or return; |
117
|
1
|
|
|
|
|
10
|
$self->print($out, @_); |
118
|
1
|
|
|
|
|
26
|
close $out; |
119
|
|
|
|
|
|
|
|
120
|
1
|
|
|
|
|
8
|
$self; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
#------------------------------------------- |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub print($@) |
127
|
12
|
|
|
12
|
1
|
40
|
{ my ($self, $out) = (shift, shift); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# Collect the labels from the selected messages. |
130
|
12
|
|
|
|
|
31
|
my %labeled; |
131
|
12
|
|
|
|
|
42
|
foreach my $message (@_) |
132
|
310
|
|
|
|
|
684
|
{ my $labels = $message->labels; |
133
|
310
|
|
|
|
|
1514
|
(my $seq = $message->filename) =~ s!.*/!!; |
134
|
|
|
|
|
|
|
|
135
|
10
|
|
|
|
|
28
|
push @{$labeled{unseen}}, $seq |
136
|
310
|
100
|
|
|
|
705
|
unless $labels->{seen}; |
137
|
|
|
|
|
|
|
|
138
|
310
|
|
|
|
|
681
|
foreach (keys %$labels) |
139
|
351
|
|
|
|
|
873
|
{ push @{$labeled{$_}}, $seq |
140
|
369
|
100
|
|
|
|
738
|
if $labels->{$_}; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
12
|
|
|
|
|
53
|
delete $labeled{seen}; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# Write it out |
146
|
|
|
|
|
|
|
|
147
|
12
|
|
|
|
|
33
|
local $" = ' '; |
148
|
12
|
|
|
|
|
66
|
foreach (sort keys %labeled) |
149
|
|
|
|
|
|
|
{ |
150
|
12
|
|
|
|
|
24
|
my @msgs = @{$labeled{$_}}; #they are ordered already. |
|
12
|
|
|
|
|
44
|
|
151
|
12
|
100
|
|
|
|
42
|
$_ = 'cur' if $_ eq 'current'; |
152
|
12
|
|
|
|
|
101
|
print $out "$_:"; |
153
|
|
|
|
|
|
|
|
154
|
12
|
|
|
|
|
52
|
while(@msgs) |
155
|
21
|
|
|
|
|
45
|
{ my $start = shift @msgs; |
156
|
21
|
|
|
|
|
32
|
my $end = $start; |
157
|
|
|
|
|
|
|
|
158
|
21
|
|
100
|
|
|
159
|
$end = shift @msgs |
159
|
|
|
|
|
|
|
while @msgs && $msgs[0]==$end+1; |
160
|
|
|
|
|
|
|
|
161
|
21
|
100
|
|
|
|
103
|
print $out ($start==$end ? " $start" : " $start-$end"); |
162
|
|
|
|
|
|
|
} |
163
|
12
|
|
|
|
|
34
|
print $out "\n"; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
12
|
|
|
|
|
45
|
$self; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
#------------------------------------------- |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; |