Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Reaping messages by Message-ID

by alexm (Chaplain)
on Jul 14, 2008 at 15:45 UTC ( [id://697505]=CUFP: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://697505]
Approved by moritz
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2026-01-21 16:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (125 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.