From e145beb394b84f533b1762dc9a1779463a9502cd Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Mon, 26 Sep 2011 16:04:00 +0200 Subject: [PATCH] Fix "command CHECK illegal in state AUTH" Dave identified a case where our new dropped connection handling did not work out correctly: we use the retry_left variable to signify success (0=success if no exception occured). However, we were decrementing the variable AFTER all the exception checks, so if there was one due to a dropped connection, it could well be that we 1) did not raise an exception (because we want to retry), and 2) then DECREMENTED retry_left, which indicated "all is well, no need to retry". The code then continued to check() the append, which failed with the above message (because we obtained a new connection which had not even selected the current folder and we were still in mode AUTH). The fix is of course, to fix our logic: Decrement retry_left first, THEN decide whether to raise() (retry_left==0) or retry (retry_left>0) which would then correctly attempt another loop. I am sorry for this newbie type of logic error. The retry count loop was too hastily slipped in, it seems. Reported-by: Dave Abrahams Signed-off-by: Sebastian Spaeth --- offlineimap/folder/IMAP.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index 69b202c..00361b0 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -536,7 +536,7 @@ class IMAPFolder(BaseFolder): retry_left = 0 # Mark as success except imapobj.abort, e: # connection has been reset, release connection and retry. - self.ui.error(e, exc_info()[2]) + retry_left -= 1 self.imapserver.releaseconnection(imapobj, True) imapobj = self.imapserver.acquireconnection() if not retry_left: @@ -545,7 +545,8 @@ class IMAPFolder(BaseFolder): "Message content was: %s" % (self, self.getrepository(), str(e), dbg_output), OfflineImapError.ERROR.MESSAGE) - retry_left -= 1 + self.ui.error(e, exc_info()[2]) + except imapobj.error, e: # APPEND failed # If the server responds with 'BAD', append() # raise()s directly. So we catch that too.