Maildirs merging
on January 10th, 2007Lately, I’ve run into a problem after moving hosting server from one provider to another. There were some old mails in backed-up maildirs and some new mails in current maildirs. For some reason mailutil from pine package didn’t want to transfer old mails. New mails of course had to stay, and old boxes had to me merged with all attributes saved. For some other reason perl script I’ve found didn’t work also (based on Mail::Folder::Maildir).
Fortunately fast simple hacked script using Mail::Box::Maildir worked with no problems. In case you’d like to do the same - run it with full path to source maildir in first arg and destination maildir in second:
#!/usr/bin/perl use Mail::Box::Maildir; use Mail::Box::Manager; my $src = shift @ARGV; my $dest = shift @ARGV; my $mgr = new Mail::Box::Manager; my $mb = $mgr->open( folder => $src, access => 'r', type => 'Mail::Box::Maildir') or die "error: $!"; my $nmb = $mgr->open( folder => $dest, access => 'rw', create => 1, type => 'Mail::Box::Maildir') or die "error: $!"; $mb->copyTo($nmb, select => 'ALL', subfolders => 'RECURSE'); $mgr->closeAllFolders();