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 :)


In reply to Reaping messages by Message-ID by alexm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.