I don't know whether this would help with the migration, but I routinely solve a similar problem. I have implemented mail failover between two servers -- which are configured with identical sets of mailboxes -- and every 10 minutes or so, a script grabs any E-Mails from the other server and stores them locally in the proper mailboxes. This script relies on IMAP connectivity and passwords in plaintext in a passwd-file. Here it is:
#!/usr/bin/perl
require '/vmail/Simple.pm';
use Net::SMTP;
$passwdfile = "/path/to/passwd-file"; $remoteserver = "myotherserver.com";
open(FIN, $passwdfile); @pwlines = (<FIN>); close(FIN);
for ($i = 0; $i <= $#pwlines; $i++) { @pwflds = split(/[:]/, $pwlines[$i]); if ($#pwflds == 3) { @pwparts = split(/[}]/, $pwflds[1]); if ($#pwparts == 1) { $thislogin = $pwflds[0]; $thispassword = $pwparts[1]; transfermail($remoteserver, $thislogin, $thispassword); } } }
sub transfermail { my $remoteserver = $_[0]; my $thislogin = $_[1]; my $thispassword = $_[2];
print $remoteserver, " - ", $thislogin, " - ", $thispassword, "\n";
my $server = new Net::IMAP::Simple( $remoteserver );
my $login_status = $server->login( $thislogin, $thispassword ); if ($login_status) { my $number_of_messages = $server->select("INBOX"); print $thislogin, " - ", $number_of_messages, " messages.\n";
my $msg;
for ($msg = 1; $msg <= $number_of_messages; $msg++)
{
$ok = 1;
$lines = $server->get( $msg ) or $ok = 0;
$smtp = Net::SMTP->new("127.0.0.1") or $ok = 0;
$smtp->mail($thislogin) or $ok = 0;
$smtp->recipient($thislogin) or $ok = 0;
$smtp->data() or $ok = 0;
$smtp->datasend(@$lines) or $ok = 0;
$smtp->dataend() or $ok = 0;
$smtp->quit or $ok = 0;
if ($ok)
{
$server->delete( $msg );
}
}
} else { print $thislogin, " - could not log in.\n"; }
$server->quit();
}
1;