As Limbic~Region pointed out, Mail::Box is perfect for this sort of thing. Here is an example (assuming mbox format):
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Mail::Box::Manager;
my ($folder1,$folder2,$folder3) = @ARGV;
my $mgr = Mail::Box::Manager->new( folderdir => [ '.' ] );
my $f1 = $mgr->open(folder => $folder1, ) or die $!;
my $f2 = $mgr->open(folder => $folder2, ) or die $1;
my $f3 = $mgr->open(folder => $folder3, create => 1, access => 'rw', )
+ or die $!;
foreach my $msg ( $f1->messages(),$f2->messages() ){
$msg->copyTo($f3) if $msg;
}
# or $mgr->copyMessage($f3, ($f1->messages(),$f2->messages()) );
$mgr->closeAllFolders();
1;
cp
----
"Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic." |