modred's Journal http://use.perl.org/~modred/journal/ modred's use Perl Journal en-us use Perl; is Copyright 1998-2006, Chris Nandor. Stories, comments, journals, and other submissions posted on use Perl; are Copyright their respective owners. 2012-01-25T02:39:11+00:00 pudge pudge@perl.org Technology hourly 1 1970-01-01T00:00+00:00 modred's Journal http://use.perl.org/images/topics/useperl.gif http://use.perl.org/~modred/journal/ Email::* Modules http://use.perl.org/~modred/journal/20001?from=rss <tt>The Email::* modules are quite useful. I wanted to merge a couple of mboxes together and put the result in date received order. It turned out to be dead simple with the Email modules.<br><br>#!perl -w<br><br>use strict;<br>use Email::Simple;<br>use Email::Folder;<br>use Email::Date;<br>use Email::LocalDelivery;<br>use Getopt::Long;<br><br># valid options are --first_mbox --second_mbox --out_mbox<br>my ($first, $second, $out);<br>unless(GetOptions('first_mbox=s' =&gt; \$first,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'second_mbox=s' =&gt; \$second,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'out_mbox=s' =&gt; \$out,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;)) {<br>&nbsp; &nbsp; die("Error with GetOptions: $!\n");<br>}<br><br>my $first_mbox = Email::Folder-&gt;new($first);<br>my $second_mbox = Email::Folder-&gt;new($second);<br><br>my @mail;<br><br>push(@mail, $first_mbox-&gt;messages(), $second_mbox-&gt;messages());<br><br>@mail = sort {<br>my $date_a = find_date($a);<br>my $date_b = find_date($b);<br>$date_a-&gt;epoch &lt;=&gt; $date_b-&gt;epoch;<br>} @mail;<br><br>foreach my $msg (@mail) {<br>&nbsp; &nbsp; my @delivered_to = Email::LocalDelivery-&gt;deliver($msg-&gt;as_string, $out);<br>}</tt> modred 2004-07-22T22:29:00+00:00 journal