| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mail::IMAPTalk::MailCache; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21625
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
30
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
471
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Mail::IMAPTalk::MailCache - Handles building a Mail::Cache cache for Mail::IMAPTalk |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.0.1 |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.0.1'; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Mail::IMAPTalk::MailCache; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $mc=Mail::Cache->new(); |
|
24
|
|
|
|
|
|
|
$mc->init('My::Module', 'imap', 'someAccount', 'INBOX'); |
|
25
|
|
|
|
|
|
|
if(!$mc->{error}){ |
|
26
|
|
|
|
|
|
|
my %returned=Mail::IMAPTalk::MailCache->cache($imap, $mc); |
|
27
|
|
|
|
|
|
|
if(!$returned{error}){ |
|
28
|
|
|
|
|
|
|
print "Error caching it.\n"; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $foo = Mail::IMAPTalk::MailCache->new(); |
|
33
|
|
|
|
|
|
|
... |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 FUNCTIONS |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 cache |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This caches the currently selected IMAP folder into a specified Mail::Cache. |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Three arguements are taken. The first that is taken is Mail::IMAPTalk object. |
|
42
|
|
|
|
|
|
|
The second is the Mail::Cache object. The third is if it should forcefully |
|
43
|
|
|
|
|
|
|
regenerate the the entire cache instead of just the new stuff. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $mc=Mail::Cache->new(); |
|
46
|
|
|
|
|
|
|
$mc->init('My::Module', 'imap', 'someAccount', 'INBOX'); |
|
47
|
|
|
|
|
|
|
if(!$mc->{error}){ |
|
48
|
|
|
|
|
|
|
my %returned=Mail::IMAPTalk::MailCache->cache($imap, $mc, 0); |
|
49
|
|
|
|
|
|
|
if(!$returned{error}){ |
|
50
|
|
|
|
|
|
|
print "Error: ".$returned{error}."\n"; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
}else{ |
|
53
|
|
|
|
|
|
|
print "Failed to init the mail cache.\n"; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub cache { |
|
59
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
60
|
0
|
|
|
|
|
|
my $imap=$_[1]; |
|
61
|
0
|
|
|
|
|
|
my $mc=$_[2]; |
|
62
|
0
|
|
|
|
|
|
my $force=$_[3]; |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $sorted = $imap->sort('(subject)', 'US-ASCII', 'NOT', 'DELETED'); |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my %returned; |
|
67
|
|
|
|
|
|
|
my %processed; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
#builds hash of already existing ones |
|
70
|
0
|
|
|
|
|
|
my @uids; |
|
71
|
0
|
|
|
|
|
|
my $int=0; |
|
72
|
0
|
|
|
|
|
|
my %exists; |
|
73
|
0
|
0
|
|
|
|
|
if (!$force) { |
|
74
|
0
|
|
|
|
|
|
@uids=$mc->listUIDs; |
|
75
|
0
|
|
|
|
|
|
while (defined($uids[$int])) { |
|
76
|
0
|
|
|
|
|
|
$exists{$uids[$int]}=''; |
|
77
|
0
|
|
|
|
|
|
$int++; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#go through the list and add them al |
|
82
|
0
|
|
|
|
|
|
$int=0; |
|
83
|
0
|
|
|
|
|
|
while (defined($sorted->[$int])) { |
|
84
|
0
|
|
|
|
|
|
my $uid=$sorted->[$int]; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
#process it if it is set to force |
|
87
|
|
|
|
|
|
|
#or if it does not exist |
|
88
|
0
|
0
|
0
|
|
|
|
if( $force || (!defined($exists{$uid})) ){ |
|
89
|
|
|
|
|
|
|
# my $headers=$imap->fetch($uid, 'rfc822.header'); |
|
90
|
0
|
|
|
|
|
|
my $headers=$imap->fetch($uid, 'body.peek[HEADER]'); |
|
91
|
|
|
|
|
|
|
# use Data::Dumper; |
|
92
|
|
|
|
|
|
|
# print Dumper($headers2->{$uid}{body})."\n\n\n"; |
|
93
|
|
|
|
|
|
|
# print Dumper($headers->{$uid}{'rfc822.header'})."\n"; |
|
94
|
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
my $size=$imap->fetch($sorted->[$int], 'rfc822.size'); |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# sleep 50000; |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$mc->setUID($uid, $headers->{$uid}{'body'}, |
|
100
|
|
|
|
|
|
|
$size->{$uid}{'rfc822.size'}); |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
#add it to the hash of processed |
|
104
|
0
|
|
|
|
|
|
$processed{$sorted->[$int]}=''; |
|
105
|
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
$int++; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
my @toremove; |
|
110
|
0
|
|
|
|
|
|
@uids=$mc->listUIDs; |
|
111
|
0
|
0
|
|
|
|
|
if ($mc->{error}) { |
|
112
|
0
|
|
|
|
|
|
warn('Macil::IMAPTalk::MailCache cache:1: Failed to get a list of cached UIDs for cleanup'); |
|
113
|
0
|
|
|
|
|
|
$returned{error}=1; |
|
114
|
0
|
|
|
|
|
|
return %returned; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
$int=0; |
|
118
|
0
|
|
|
|
|
|
while (defined($uids[$int])) { |
|
119
|
0
|
0
|
|
|
|
|
if (!defined($processed{$uids[$int]})) { |
|
120
|
0
|
|
|
|
|
|
push(@toremove, $uids[$int]); |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$int++; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
$mc->removeUIDs(\@toremove); |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
#success |
|
129
|
0
|
|
|
|
|
|
$returned{error}=0; |
|
130
|
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
return %returned; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 ERRORS |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 1 |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Failed to get a list of UIDs for the |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 AUTHOR |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Zane C. Bowers, C<< >> |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 BUGS |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
147
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
148
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 SUPPORT |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
perldoc Mail::IMAPTalk::MailCache |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
You can also look for information at: |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=over 4 |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
L |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
L |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
L |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * Search CPAN |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
L |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=back |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Copyright 2009 Zane C. Bowers, all rights reserved. |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
191
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
1; # End of Mail::IMAPTalk::MailCache |