Sometimes I make a copy of a mailbox and I forget about it. Later, I found that mailbox and I'm not certain that I already have a copy of all those messages so I can remove the copy entirely.
I always thought that a tool that reaped some messages from a mailbox based on the Message-ID header existing in other mailboxes would be very useful. That way, I could easily find those messages that I don't have anywhere else and get rid of duplicates. So, this is what I came up with:
use Mail::Box::Manager;
use Mail::Box::Tie::HASH;
use strict;
use warnings;
die "usage: $0 copy orig\n" unless @ARGV == 2;
my ($copy_file, $orig_file) = @ARGV;
my $mgr = Mail::Box::Manager->new;
my $copy_folder = $mgr->open(access => 'rw', folder => $copy_file);
my $orig_folder = $mgr->open(access => 'r', folder => $orig_file);
tie my %copy, 'Mail::Box::Tie::HASH', $copy_folder;
tie my %orig, 'Mail::Box::Tie::HASH', $orig_folder;
while (my $msgid = each %orig) {
$copy{$msgid}->delete;
}
BTW, I used it on mbox folders, but it can used with other folder types too:
$ perl -MMail::Box::Manager -le '$,="\n"; print Mail::Box::Manager->ne
+w->folderTypes'
imap
imap4
maildir
mbox
mh
pop
pop3
I love Perl :)