Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

modred (49)

modred
  (email not shown publicly)

Journal of modred (49)

Thursday July 22, 2004
05:29 PM

Email::* Modules

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);
}