http://qs321.pair.com?node_id=1058656

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

Hi All,

Here's my dilemma, I use Mail::IMAPClient to access and clean out my imap messages once a week; however, after a certain amount of messages it fails to do anything. I do get the error message, Trying command when NOT connected! at /usr/local/share/perl/5.10.1/Mail/IMAPClient.pm line 118....

Though I am to able to manually log into imap and remove the messages manually, and rerun the script without any issues.

Is the there a limitation on the amount of messages, IMAPClient can handle? i.e. expunge or store in deleted folder

Is Net::IMAP::Simple a better option?

Replies are listed 'Best First'.
Re: IMAPClient Fails when storing large amount of messages in deleted
by naChoZ (Curate) on Oct 17, 2013 at 18:14 UTC

    It's more likely that it's timing out while waiting for the imap server to complete the operation. Instead of sending a mass delete of a bunch of messages, break it up into chunks. Something along the lines of:

    my $msgset = Mail::IMAPClient::MessageSet->new( $imap->messages ); my $msg_ids = []; if ( $msgset ) { $msg_ids = $msgset->unfold; } while ( my @cur_block = splice @$msg_ids, 0, 500 ) { # delete the current block of messages... }

    Untested of course. Hopefully that gets you going in the right direction.

    --
    Andy

Re: IMAPClient Fails when storing large amount of messages in deleted
by marinersk (Priest) on Oct 17, 2013 at 19:01 UTC
    I had the same problem with my mail deletion routine. I, too, theorized the operation was timing out.

    I wrapped it into a loop where it deletes 100 messages at a time. The problem has never returned.

    NOTE: Re-read the inbox count at the start of each loop and terminate if you are out of messages. You are not allowed to ask how I know this is important.  :-)