| 1 | package Mail::IMAPTalk::SortHelper; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use Mail::IMAPTalk::MailCache; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 2 | 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 | 0 | ▶ | sub new{ | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 43 | 0 | 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 | 0 | ▶ | sub process{ | ||||||||
|
Subroutine
process: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||
| 67 | 0 | my $self=$_[0]; | |||||||||
| 68 | 0 | my @r=@{$_[1]}; | |||||||||
| 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])) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | #if it is a array, then it is threaded and we need to handle this differently... | ||||||||||
| 89 | 0 | ▶ | if (ref($r[$int]) eq 'ARRAY') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | if (!defined($toadd->{subject})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 107 | 0 | $toadd->{subject}=''; | |||||||||
| 108 | } | ||||||||||
| 109 | 0 | ▶ | if (!defined($toadd->{date})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | 0 | $toadd->{date}=''; | |||||||||
| 111 | } | ||||||||||
| 112 | 0 | ▶ | if (!defined($toadd->{from})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 113 | 0 | $toadd->{from}=''; | |||||||||
| 114 | } | ||||||||||
| 115 | 0 | ▶ | if (!defined($toadd->{size})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 0 | ▶ | sub processArray{ | ||||||||
|
Subroutine
processArray: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||
| 135 | 0 | 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 | ▶ | if (ref($_[1]) eq 'ARRAY') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 141 | 0 | @r=@{$_[1]} | |||||||||
| 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) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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])) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 157 | 0 | ▶ | if (ref($r[$int]) eq 'ARRAY') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | if (!defined($toadd->{subject})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 179 | 0 | $toadd->{subject}=''; | |||||||||
| 180 | } | ||||||||||
| 181 | 0 | ▶ | if (!defined($toadd->{date})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 182 | 0 | $toadd->{date}=''; | |||||||||
| 183 | } | ||||||||||
| 184 | 0 | ▶ | if (!defined($toadd->{from})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 185 | 0 | $toadd->{from}=''; | |||||||||
| 186 | } | ||||||||||
| 187 | 0 | ▶ | if (!defined($toadd->{size})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 0 | ▶ | sub getInline{ | ||||||||
|
Subroutine
getInline: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 209 | 0 | 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 | 0 | ▶ | sub getInlineCharacter{ | ||||||||
|
Subroutine
getInlineCharacter: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 219 | 0 | return $_[0]->{char}; | |||||||||
| 220 | } | ||||||||||
| 221 | |||||||||||
| 222 | =head2 setInline | ||||||||||
| 223 | |||||||||||
| 224 | Turn inline mode on or off. | ||||||||||
| 225 | |||||||||||
| 226 | =cut | ||||||||||
| 227 | |||||||||||
| 228 | 0 | ▶ | sub setInline{ | ||||||||
|
Subroutine
setInline: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 229 | 0 | $_[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 | 0 | ▶ | sub setInlineCharacter{ | ||||||||
|
Subroutine
setInlineCharacter: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 245 | 0 | ▶ | if (!defined($_[1])) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 246 | 0 | $_[0]->{char}='-'; | |||||||||
| 247 | } | ||||||||||
| 248 | |||||||||||
| 249 | 0 | ▶ | if ($_[1] eq '') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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<< <vvelox at vvelox.net> >> | ||||||||||
| 298 | |||||||||||
| 299 | =head1 BUGS | ||||||||||
| 300 | |||||||||||
| 301 | Please report any bugs or feature requests to C<bug-mail-imaptalk-sorthelper at rt.cpan.org>, or through | ||||||||||
| 302 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Mail-IMAPTalk-SortHelper>. 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<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Mail-IMAPTalk-SortHelper> | ||||||||||
| 322 | |||||||||||
| 323 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 324 | |||||||||||
| 325 | L<http://annocpan.org/dist/Mail-IMAPTalk-SortHelper> | ||||||||||
| 326 | |||||||||||
| 327 | =item * CPAN Ratings | ||||||||||
| 328 | |||||||||||
| 329 | L<http://cpanratings.perl.org/d/Mail-IMAPTalk-SortHelper> | ||||||||||
| 330 | |||||||||||
| 331 | =item * Search CPAN | ||||||||||
| 332 | |||||||||||
| 333 | L<http://search.cpan.org/dist/Mail-IMAPTalk-SortHelper/> | ||||||||||
| 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 | 2 | 1; # End of Mail::IMAPTalk::SortHelper | |||||||||