Email::* Modules

modred on 2004-07-22T22:29:00

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.

#!perl -w

use strict; use Email::Simple; use Email::Folder; use Email::Date; use Email::LocalDelivery; use Getopt::Long;

# valid options are --first_mbox --second_mbox --out_mbox my ($first, $second, $out); unless(GetOptions('first_mbox=s' => \$first, 'second_mbox=s' => \$second, 'out_mbox=s' => \$out, )) { die("Error with GetOptions: $!\n"); }

my $first_mbox = Email::Folder->new($first); my $second_mbox = Email::Folder->new($second);

my @mail;

push(@mail, $first_mbox->messages(), $second_mbox->messages());

@mail = sort { my $date_a = find_date($a); my $date_b = find_date($b); $date_a->epoch <=> $date_b->epoch; } @mail;

foreach my $msg (@mail) { my @delivered_to = Email::LocalDelivery->deliver($msg->as_string, $out); }