delete specific mail in all folders

LALOT Dominique dom.lalot at
Mon May 11 05:43:20 EDT 2009

That could be something like that script (test and adapt). I'm just a
beginer with Mail::IMAPTalk and I don't use correctly search method
The trick will be to find the from and subject and/or the date..


use Mail::IMAPTalk;

$IMAP = Mail::IMAPTalk->new(
             Server   => 'localhost',
             Username => 'cyrus',
             Password => 'xxx',
             Uid      => 1 )
           || die "Failed to connect/login to IMAP server";

$IMAP->set_root_folder('inbox', '/', 1, 'user');
foreach $bals (@folder){
   foreach $bal (@$bals){
      if ($bal=~/user\//){
         $IMAP->select($bal) || warn "cant access $bal: $@";
         $ResSearch = $IMAP->search('1:*', 'FROM', 'xxx'); # find the good
search to do
         $Res = $IMAP->fetch($Res, '(rfc822.size envelope)') || die "cant
access $bal: $@";
         foreach $id (keys %$Res){
            print "id=$id size=$size sub=$subject\n";
         $IMAP->store($ResSearch, '+flags', '(\\deleted)');
         if (defined $lasterr){
            next if ($lasterr=~/No fetch data/);
            warn " $bal: $@";

2009/5/11 Gerald Nowitzky <whl at>

> Hello!
> I have been confronted with a request today: We are running cyrus as imap
> server. We have currently about 3 million files and 150GB in our mail dir.
> One user has accidently sent something confidential to all users via a
> list.
> The request was, of course, to delete the mail from all mailboxes. Is there
> any reasonable approach to do something like this?
> Thanks!
> (Gerald)
> ----
> Cyrus Home Page:
> Cyrus Wiki/FAQ:
> List Archives/Info:

Dominique LALOT
Ingénieur Systèmes et Réseaux
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Info-cyrus mailing list