Sometimes we just have to move on. Your current mail server may just not be meeting your needs, so you've put up something new. But what about old mail? If your servers are identical (Sendmail to Sendmail, etc.) or use the same mailbox storage format, you may be able to just transfer files directly. If not, read on..
If everyone uses POP, there's usually not much to transfer, and if you can shut off incoming mail and just wait long enough for everyone to pop their mail, there won't be anything. But many people now use cd /home/e-smith/files/users/tony/Maildir
for i in *
do
cat $i | /var/qmail/bin/qmail-inject
done
Repeating that for each directory would move all mail to the new server. However, it all ends up in the user's INBOX unless that server can apply rules to determine where to file it. To assist that, you may want to use a perl program instead. Something like this:
#!/usr/bin/perl
use Mail::Mailer;
@stuff=;
foreach (@stuff) {
$from=$_ if /^From:/;
$to=$_ if /^To:/;
$subject=$_ if /^Subject:/;
last if $subject;
}
$from=~ s/From: //;
$from=~ s//;
$from=~ s/>//;
$to=~ s/To: //;
$to=~ s//;
$to=~ s/>//;
$subject=~ s/^/* FILE ME IN CUSTS */;
$mailer=Mail::Mailer->new();
$mailer->open({From =>$from,
    
To => $to,
    
Subject => $subject,
    
}) or die "Can't open $!
";
foreach (@stuff) {
  
print $mailer $_;
}
$mailer=>close();
You'd adjust the modification to Subject appropriately, or add entirely new headers if desired.
If your mail is stored in Unix mailbox fashion, you need something to read the messages and break them up. While you could read the mailboxes directly, it's more portable to use tools like POP:
#!/usr/bin/perl
use Net::POP3;
$pop=Net::POP3->new('10.1.36.237') or die "$!";
$pop->login("tony","password");
$messages=$pop->list;
foreach $msg(keys %$messages) {
$message=$pop->get($msg);
foreach (@$message) {
#same basic idea as above,
}
}
You may need to get Net::POP3 from CPAN. There are similar modules for IMAP.
Bruce Garlock suggested that APLawrence.com
A.P. Lawrence provides SCO Unix and Linux consulting services http://www.pcunix.com
Transferring Mail to a New Mail Server
0 views
Comments (0)
Please sign in to leave a comment.





No comments yet. Be the first to comment!