The best way that I could think to accomplish something like this would be to sort through the first folder and create a hash with the date (or whichever property of the message you wish to sort by) and message id. Then sort the hash and pull each message by id and put it into a new "sorted" folder. I used the CPAN module
Mail::Box::Manager.
For example:
use Mail::Box::Manager;
my $unsorted_folder = "inbox";
my $sorted_folder = "inbox.sort";
my %msghash;
my $mgr = Mail::Box::Manager->new;
my $unsortfolder = $mgr->open(folder => $unsorted_folder);
my $sortfolder = $mgr->open(folder => $sorted_folder);
# iterate over the messages & create the hash
foreach my $id ($unsortfolder->messages) {
my $message = $unsortfolder->message($id);
$msghash{$id} = $message->get('Date');
}
# compare the dates & add to new folder
foreach my $msg (keys %msghash) {
@datesorted = <date sorting algorithm>
foreach (@datesorted) {
$sortedfolder->addMessage($unsortedfolder->message($_));
}
}
$unsortfolder->close();
$sortedfolder->close();
The code is untested. I'm sure there is probably a better way to do this. To sort by dates, look into using the CPAN module Date::Manip. Hope the concept helps.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.