Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone has some experience using Mail::IMAPClient to manage an IMAP mailbox? I created the following code snippit to delete all messages on an IMAP server that have been viewed. The messages appear to be deleted (Netscape Messenger and Outlook don't see them) but I eventually hit the quota ceiling. It's like the messages are just hidden. Any ideas? Thanks...AvignonHermit
use Mail::IMAPClient; #Now delete all messages that we now have a copy of (the messages have + been seen) print "\nRemoving viewed messages...\n"; my $imap = Mail::IMAPClient->new( Server => "XXXXXXX", User => "XXXXXX", Password => "XXXXXX", Port => "143", Debug => "0", Uid => 1, Clear => '1', ) || die ("Could not connect to server.\n"); $imap->select('inbox') || die ("Could not select INBOX\n"); my @toBeDeleted=$imap->seen(); my $numDeleted=$imap->delete_message(@toBeDeleted) || die ("Error remo +ving messages\n"); print "Deleted $numDeleted messages..."; $imap->expunge; $imap->close;

Replies are listed 'Best First'.
Re: Mail::IMAPClient Troubles
by ehdonhon (Curate) on Jan 23, 2002 at 08:55 UTC

    My experience with IMAP has been that you can never count on two imap servers to handle things in the same way. The pod does offer this small piece of advice:

    delete_message returns the number of messages it was told to delete. However, since the delete is done by issuing the +FLAGS.SILENT option of the STORE IMAP client command, there is no guarantee that the delete was successful for every message. In this manner the delete_message method sacrifices accuracy for speed. If you must have guaranteed results then use the IMAP STORE client command (via the default method) and use the +FLAGS (\Deleted) option, and then parse your results manually. Eg:

    $imap->store($msg_id,'+FLAGS (\Deleted)');
    my @results = $imap->History($imap->Transaction);
    ...                     # code to parse output goes here
    

Re: Mail::IMAPClient Troubles
by blahblahblah (Priest) on Jan 18, 2002 at 08:00 UTC
    I wrote a script that uses Mail::IMAPClient a couple of months ago. I just compared mine to yours and it seems to do pretty much the same things.

    One difference I notice is that I'm checking the return code of expunge the same way you do for delete. I don't remember whether I had a good reason for doing this, but it's worth trying.

    Have you tried turning debugging on? I found that very useful when I had some trouble with a MS Exchange server that didn't behave properly for one of the imap commands.