line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::IMAPTalk::SortHelper; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24020
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
988
|
use Mail::IMAPTalk::MailCache; |
|
1
|
|
|
|
|
535
|
|
|
1
|
|
|
|
|
1255
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Mail::IMAPTalk::SortHelper - Handles some processing of the returns from sort and thread. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 0.0.1 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.0.1'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Generates a array from the sorted return of either |
23
|
|
|
|
|
|
|
Mail::IMAPTalk->sort or Mail::IMAPTalk->thread. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Mail::Cache is used to speed this up. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use Mail::IMAPTalk::SortHelper; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $sh = Mail::IMAPTalk::SortHelper->new(); |
30
|
|
|
|
|
|
|
... |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 FUNCTIONS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 new |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
This initiates the object. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $sh = Mail::IMAPTalk::SortHelper->new(); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub new{ |
43
|
0
|
|
|
0
|
1
|
|
my $self={error=>undef, errorString=>'', inline=>0, char=>'>'}; |
44
|
0
|
|
|
|
|
|
bless $self; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 process |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
This processes the returned data from either sort or thread. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Three arguements are required. The first is the data returned from |
54
|
|
|
|
|
|
|
it, the second is the Mail::IMAPTalk object, and the third is |
55
|
|
|
|
|
|
|
a Mail::Cache object. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $sorted=$imap->thread('REFERENCES', 'UTF8', 'NOT', 'DELETED'); |
58
|
|
|
|
|
|
|
$mc->init('My::Module', 'imap', 'myAccount', 'INBOX'); |
59
|
|
|
|
|
|
|
my @processed=$sh->(@{$sorted}, $imap, $mc); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
use Data::Dumper; |
62
|
|
|
|
|
|
|
print Data::Dumper->Dump(\@processed); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub process{ |
67
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
68
|
0
|
|
|
|
|
|
my @r=@{$_[1]}; |
|
0
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $i=$_[2]; |
70
|
0
|
|
|
|
|
|
my $mc=$_[3]; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#makes sure the cache is up to date |
73
|
0
|
|
|
|
|
|
my %mimcr=Mail::IMAPTalk::MailCache->cache($i, $mc, 0); |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my %dates=$mc->getDates; |
76
|
0
|
|
|
|
|
|
$self->{dates}=\%dates; |
77
|
0
|
|
|
|
|
|
my %sizes=$mc->getSizes; |
78
|
0
|
|
|
|
|
|
$self->{sizes}=\%sizes; |
79
|
0
|
|
|
|
|
|
my %froms=$mc->getFroms; |
80
|
0
|
|
|
|
|
|
$self->{froms}=\%froms; |
81
|
0
|
|
|
|
|
|
my %subjects=$mc->getSubjects; |
82
|
0
|
|
|
|
|
|
$self->{subjects}=\%subjects; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my @p; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $int=0; |
87
|
0
|
|
|
|
|
|
while (defined($r[$int])) { |
88
|
|
|
|
|
|
|
#if it is a array, then it is threaded and we need to handle this differently... |
89
|
0
|
0
|
|
|
|
|
if (ref($r[$int]) eq 'ARRAY') { |
90
|
0
|
|
|
|
|
|
my $t=$r[$int]; |
91
|
0
|
|
|
|
|
|
my @additionalP=$self->processArray($t, $i, $mc, 0); |
92
|
0
|
|
|
|
|
|
push(@p, @additionalP); |
93
|
|
|
|
|
|
|
}else { |
94
|
0
|
|
|
|
|
|
my $uid=$r[$int]; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $toadd={}; |
97
|
0
|
|
|
|
|
|
$toadd->{uid}=$uid; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$toadd->{subject}=$self->{subjects}{$uid}; |
100
|
0
|
|
|
|
|
|
$toadd->{date}=$self->{dates}->{$uid}; |
101
|
0
|
|
|
|
|
|
$toadd->{from}=$self->{froms}->{$uid}; |
102
|
0
|
|
|
|
|
|
$toadd->{size}=$self->{sizes}->{$uid}; |
103
|
0
|
|
|
|
|
|
$toadd->{over}='0'; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#make sure they are all defined... |
106
|
0
|
0
|
|
|
|
|
if (!defined($toadd->{subject})) { |
107
|
0
|
|
|
|
|
|
$toadd->{subject}=''; |
108
|
|
|
|
|
|
|
} |
109
|
0
|
0
|
|
|
|
|
if (!defined($toadd->{date})) { |
110
|
0
|
|
|
|
|
|
$toadd->{date}=''; |
111
|
|
|
|
|
|
|
} |
112
|
0
|
0
|
|
|
|
|
if (!defined($toadd->{from})) { |
113
|
0
|
|
|
|
|
|
$toadd->{from}=''; |
114
|
|
|
|
|
|
|
} |
115
|
0
|
0
|
|
|
|
|
if (!defined($toadd->{size})) { |
116
|
0
|
|
|
|
|
|
$toadd->{size}=''; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
push(@p, $toadd); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$int++; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
return @p; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 processArray |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This is a internal function used for when dealing with threads. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub processArray{ |
135
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
136
|
0
|
|
|
|
|
|
my $i=$_[2]; |
137
|
0
|
|
|
|
|
|
my $mc=$_[3]; |
138
|
0
|
|
|
|
|
|
my $over=$_[4]; |
139
|
0
|
|
|
|
|
|
my @r; #if we don't get handed an array, we don't do any thing that would be annoying |
140
|
0
|
0
|
|
|
|
|
if (ref($_[1]) eq 'ARRAY') { |
141
|
0
|
|
|
|
|
|
@r=@{$_[1]} |
|
0
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
#puts together the inline |
145
|
0
|
|
|
|
|
|
my $inlineappend=''; |
146
|
0
|
|
|
|
|
|
my $int=1;#we start at one as zero does not have one |
147
|
0
|
|
|
|
|
|
while ($int <= $over) { |
148
|
0
|
|
|
|
|
|
$inlineappend=$self->{char}.$inlineappend; |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
$int++; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
my @p; #holds what will be returned |
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
$int=0; |
156
|
0
|
|
|
|
|
|
while (defined($r[$int])) { |
157
|
0
|
0
|
|
|
|
|
if (ref($r[$int]) eq 'ARRAY') { |
158
|
|
|
|
|
|
|
#handles any sub threads |
159
|
0
|
|
|
|
|
|
my $t=$r[$int]; |
160
|
0
|
|
|
|
|
|
my $newover=$over; |
161
|
0
|
|
|
|
|
|
$newover++; |
162
|
0
|
|
|
|
|
|
my @additionalP=$self->processArray($t, $i, $mc, $newover); |
163
|
0
|
|
|
|
|
|
push(@p, @additionalP); |
164
|
|
|
|
|
|
|
}else { |
165
|
|
|
|
|
|
|
#handles any message for this over lovel |
166
|
0
|
|
|
|
|
|
my $uid=$r[$int]; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
my $toadd={}; |
169
|
0
|
|
|
|
|
|
$toadd->{uid}=$uid; |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
$toadd->{subject}=$inlineappend.$self->{subjects}->{$uid}; |
172
|
0
|
|
|
|
|
|
$toadd->{date}=$self->{dates}->{$uid}; |
173
|
0
|
|
|
|
|
|
$toadd->{from}=$self->{froms}->{$uid}; |
174
|
0
|
|
|
|
|
|
$toadd->{size}=$self->{sizes}->{$uid}; |
175
|
0
|
|
|
|
|
|
$toadd->{over}=$over; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
#make sure they are all defined... |
178
|
0
|
0
|
|
|
|
|
if (!defined($toadd->{subject})) { |
179
|
0
|
|
|
|
|
|
$toadd->{subject}=''; |
180
|
|
|
|
|
|
|
} |
181
|
0
|
0
|
|
|
|
|
if (!defined($toadd->{date})) { |
182
|
0
|
|
|
|
|
|
$toadd->{date}=''; |
183
|
|
|
|
|
|
|
} |
184
|
0
|
0
|
|
|
|
|
if (!defined($toadd->{from})) { |
185
|
0
|
|
|
|
|
|
$toadd->{from}=''; |
186
|
|
|
|
|
|
|
} |
187
|
0
|
0
|
|
|
|
|
if (!defined($toadd->{size})) { |
188
|
0
|
|
|
|
|
|
$toadd->{size}=''; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
push(@p, $toadd); |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
0
|
|
|
|
|
|
$int++; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# print "processed array\n"; |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
return @p; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head2 getInline |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Gets the inline mode setting. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub getInline{ |
209
|
0
|
|
|
0
|
1
|
|
return $_[0]->{inline}; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 getInlineCharacter |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
This fetches what is currently being used for the inline character. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
sub getInlineCharacter{ |
219
|
0
|
|
|
0
|
1
|
|
return $_[0]->{char}; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head2 setInline |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Turn inline mode on or off. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=cut |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
sub setInline{ |
229
|
0
|
|
|
0
|
1
|
|
$_[0]->{inline}=$_[1]; |
230
|
|
|
|
|
|
|
|
231
|
0
|
|
|
|
|
|
return 1; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head2 setInlineCharacter |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
This sets the inline over character. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
If it is undef or '', then it is reset to '>'. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
$sh->setInlineCharacter('='); |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=cut |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
sub setInlineCharacter{ |
245
|
0
|
0
|
|
0
|
1
|
|
if (!defined($_[1])) { |
246
|
0
|
|
|
|
|
|
$_[0]->{char}='-'; |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
0
|
0
|
|
|
|
|
if ($_[1] eq '') { |
250
|
0
|
|
|
|
|
|
$_[0]->{char}='-'; |
251
|
0
|
|
|
|
|
|
return 1; |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
0
|
|
|
|
|
|
$_[0]->{char}=$_[1]; |
255
|
|
|
|
|
|
|
|
256
|
0
|
|
|
|
|
|
return 1; |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=head1 RETRUNED ARRAY FORMAT |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
The returned a is a array of hashes. |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head2 HASH KEYS |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head3 over |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
This is how far over a item a thread. A value of zero |
268
|
|
|
|
|
|
|
indicates it's the root of the thread. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
Unless this is a threaded search, it will always be 0. |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head3 uid |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
This is the IMAP UID of the message. |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=head3 from |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
This is the From header of the message. |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=head3 date |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
This is the Date header of the message. |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head3 subject |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
This is the subject header of the message. |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
If inline mode is turned on the number of inline characters |
289
|
|
|
|
|
|
|
will be appended to it determines by how far over it is. |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=head3 size |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
This is the size of the message. |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head1 AUTHOR |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Zane C. Bowers, C<< >> |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
=head1 BUGS |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
302
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
303
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
=head1 SUPPORT |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
perldoc Mail::IMAPTalk::SortHelper |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
You can also look for information at: |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=over 4 |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
L |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
L |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
=item * CPAN Ratings |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
L |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=item * Search CPAN |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
L |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
=back |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
ANDK, #52167, pointed out the missing dependency in Makefile.PL |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
Copyright 2011 Zane C. Bowers-Hadley, all rights reserved. |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
347
|
|
|
|
|
|
|
under the same terms as Perl itself. |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
=cut |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
1; # End of Mail::IMAPTalk::SortHelper |