delete specific mail in all folders

LALOT Dominique dom.lalot at gmail.com
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..

Dom

#!/usr/bin/perl
use Mail::IMAPTalk;

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

#http://linuxfr.org/forums/27/21722.html
$IMAP->set_root_folder('inbox', '/', 1, 'user');
@folder=$IMAP->list("user.%",'*');
foreach $bals (@folder){
$tot=0;
$msgnb=0;
   foreach $bal (@$bals){
      if ($bal=~/user\//){
         #$IMAP->examine($_);
         #$count=$IMAP->message_count($_);
         $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){
            $size=$Res->{$id}->{'rfc822.size'};
            $subject=$Res->{$id}->{'envelope'}->{'Subject'};
            print "id=$id size=$size sub=$subject\n";
         }
         $IMAP->store($ResSearch, '+flags', '(\\deleted)');
         $lasterr=$IMAP->get_last_error();
         if (defined $lasterr){
            next if ($lasterr=~/No fetch data/);
            warn " $bal: $@";
            next;
         }
     }
   }
}
$IMAP->logout();


2009/5/11 Gerald Nowitzky <whl at igne.de>

> 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: http://cyrusimap.web.cmu.edu/
> Cyrus Wiki/FAQ: http://cyrusimap.web.cmu.edu/twiki
> List Archives/Info: http://asg.web.cmu.edu/cyrus/mailing-list.html
>



-- 
Dominique LALOT
Ingénieur Systèmes et Réseaux
http://annuaire.univmed.fr/showuser.php?uid=lalot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.andrew.cmu.edu/pipermail/info-cyrus/attachments/20090511/7ea933b4/attachment-0001.html 


More information about the Info-cyrus mailing list