Skip Menu |

This queue is for tickets about the Mail-IMAPClient CPAN distribution.

Report information
The Basics
Id: 49401
Status: resolved
Priority: 0/
Queue: Mail-IMAPClient

People
Owner: PLOBBES [...] cpan.org
Requestors: gumby3203 [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 3.21



Subject: IMAPClient fails to disconnect/expunge
Date: Thu, 3 Sep 2009 12:15:28 -0400
To: bug-Mail-IMAPClient [...] rt.cpan.org
From: Gary Baluha <gumby3203 [...] gmail.com>
Environment: IMAPClient version 3.20 perl v5.8.8 Mandriva Linux 2007.0 (2.6.17 kernel) Problem: When logging out of the imap server, IMAPClient appears to crash. Messages flagged as "Deleted" fail to get expunged. From the debugging output: Connecting via IO::Socket::INET to <HOST>:143 Timeout 600 Connected to <HOST> errno(Operation now in progress) Read: * OK V3000 IMAP4rev1 v10.210 server ready Sending: 257 LOGIN "1003" 1003 Sent 23 bytes Read: 257 OK LOGIN completed Sending: 258 STATUS INBOX (MESSAGES) Sent 29 bytes Read: * STATUS INBOX (MESSAGES 1) Read: 258 OK STATUS completed . . . Sending: 263 LOGOUT Sent 12 bytes Read: * BYE V3000 IMAP4rev1 server terminating connection ERROR: * BYE V3000 IMAP4rev1 server terminating connection at /usr/lib/perl5/site_perl/5.8.8/Mail/IMAPClient.pm line 1343 Mail::IMAPClient::_get_response('Mail::IMAPClient=HASH(0x804c09c)', 263, 'undef') called at /usr/lib/perl5/site_perl/5.8.8/Mail/IMAPClient.pm line 1277 Mail::IMAPClient::_imap_command_do('Mail::IMAPClient=HASH(0x804c09c)', 'LOGOUT') called at /usr/lib/perl5/site_perl/5.8.8/Mail/IMAPClient.pm line 1183 Mail::IMAPClient::_imap_command('Mail::IMAPClient=HASH(0x804c09c)', 'LOGOUT') called at /usr/lib/perl5/site_perl/5.8.8/Mail/IMAPClient.pm line 1758 Mail::IMAPClient::logout('Mail::IMAPClient=HASH(0x804c09c)') called at /etc/vopt/vmailretr.pl line 233 ERROR: * BYE V3000 IMAP4rev1 server terminating connection at /usr/lib/perl5/site_perl/5.8.8/Mail/IMAPClient.pm line 1228 Mail::IMAPClient::_imap_command('Mail::IMAPClient=HASH(0x804c09c)', 'LOGOUT') called at /usr/lib/perl5/site_perl/5.8.8/Mail/IMAPClient.pm line 1758 Mail::IMAPClient::logout('Mail::IMAPClient=HASH(0x804c09c)') called at /etc/vopt/vmailretr.pl line 233 Associated perl code: my $Vmail_IMAP = Mail::IMAPClient->new(Uid=>FALSE, Debug=>$debug, Keepalive=>TRUE); if ($debug) { $Vmail_IMAP->Debug_fh(IO::File->new(">$debug_path")); } . . . $Vmail_IMAP->User($IMAPUser); $Vmail_IMAP->Password($currRow->{Pass}); if (!$Vmail_IMAP->connect()) { exit; } $msgCount = $Vmail_IMAP->message_count(MBOX); . . . $Vmail_IMAP->expunge(); $Vmail_IMAP->logout();
Example of a manual login/logout to the IMAP server being used: [root@server]# telnet <HOST> 143 Trying <HOST>... Connected to host<HOST> (<HOST>). Escape character is '^]'. * OK V3000 IMAP4rev1 v10.210 server ready . login <USER> <PASS> . OK LOGIN completed . logout * BYE V3000 IMAP4rev1 server terminating connection . OK LOGOUT completed Connection closed by foreign host.
The trace doesn't show an EXPUNGE command being issued... and currently the code will not call EXPUNGE unless a folder is selected. Given your example code, you do not appear to be selecting a Folder and therefore EXPUNGE will not happen. There is no implicit selection of a folder even when you call message_count() you need to explicitly select it. Try using the following instead: $Vmail_IMAP->expunge(MBOX) The ERROR being reported via debug and setting LastError is a minor bug as the code should not be considering a BYE during LOGOUT as an error. I'll fix that in the next release, thanks!
I missed a line of code in my copy/paste just before the expunge command, which was: $Vmail_IMAP->select(MBOX). However, I still changed the expunge command as suggested. Also, if the folder argument is required as you suggest, the CPAN documentation is incorrect: "The expunge method accepts one optional argument, a folder name. It expunges the folder specified as the argument, or the currently selected folder if no argument is supplied."
If you did do a select then expunge (without a folder arg) and that failed to try the expunge then there's a bug there. When I get a chance I'll test to see what happens and patch as necessary, thanks!
Finally, here's a more complete response on my part... Regarding issue #1: Messages flagged as "Deleted" fail to get expunged - The logic was broken early on in 3.x from what I can tell, so thanks for finding this and the behavior will be patched in the next release. Regarding issue #2: When logging out of the imap server, IMAPClient appears to crash - I am going to stick by current behavior (setting LastError) for now because of the following info from RFC 3501 Section 7.1.5. BYE Response: 1) as part of a normal logout sequence. The server will close the connection after sending the tagged OK response to the LOGOUT command. Based on the info you have provided, your IMAP server is responding with a tagged BYE (* BYE) instead of a tagged OK (* OK). This seems to go against the RFC - at least my interpretation. Feel free to try and convince me otherwise but that's my current position on this. All Mail::IMAPClient does is set "LastError" which allows you to retrieve the full info in the tagged BYE response. From the code perspective, one can feel free to ignore that "error" since the logout/disconnect still happens. If you agree with me, you may want to file a bug with the developer of the IMAP server... of course, I'm no authority figure in the IMAP world!
Just released Mail::IMAPClient 3.21 which should resolve this bug. Please feel free to reopen or file a new bug if you run into any problems!
Subject: Re: [rt.cpan.org #49401] IMAPClient fails to disconnect/expunge
Date: Wed, 23 Sep 2009 21:52:07 -0400
To: bug-Mail-IMAPClient [...] rt.cpan.org
From: Gary Baluha <gumby3203 [...] gmail.com>
Thanks. I installed it today and will monitor and let you know. On Tue, Sep 22, 2009 at 10:45 PM, Phil Lobbes via RT < bug-Mail-IMAPClient@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=49401 > > > Just released Mail::IMAPClient 3.21 which should resolve this bug. > Please feel free to reopen or file a new bug if you run into any problems! >
closing as resolved as the reply reopened the ticket.