Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

IMAPClient Fails when storing large amount of messages in deleted

by helpo11 (Initiate)
on Oct 17, 2013 at 17:47 UTC ( #1058656=perlquestion: print w/ replies, xml ) Need Help??
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?

Comment on IMAPClient Fails when storing large amount of messages in deleted
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 (Chaplain) 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.  :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1058656]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2014-12-26 15:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls