From 61e754c65ef08c85aa160b407d21475174c56262 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Sat, 21 Apr 2012 13:26:09 +0200 Subject: [PATCH] Do not try to release IMAP connection twice Reported by sharat87 in https://github.com/spaetz/offlineimap/pull/38, he would often get an unhandled Exception when trying to releaseconnection() a connection that was not in the pool of connections. The reason this could happen is that when folder.IMAP.quickchanged() raises an Exception in select(), we would release the connection in the "except" handling, and than release the same connection in the "finally" clause, which led to the error. The right thing is to only release the connection once, of course. Signed-off-by: Sebastian Spaeth --- Changelog.rst | 1 + offlineimap/folder/IMAP.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Changelog.rst b/Changelog.rst index 2564ae5..7acccd3 100644 --- a/Changelog.rst +++ b/Changelog.rst @@ -12,6 +12,7 @@ WIP (add new stuff for the next release) * Actually perform the SSL fingerprint check (reported by J. Cook) * Curses UI, don't use colors after we shut down curses already (C.Höger) * Document that '%' needs encoding as '%%' in *.conf +* Fix crash when IMAP.quickchanged() led to an Error (reported by sharat87) OfflineIMAP v6.5.3.1 (2012-04-03) ================================= diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index 6bdcc71..bb1b51f 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -93,14 +93,17 @@ class IMAPFolder(BaseFolder): # Select folder and get number of messages restype, imapdata = imapobj.select(self.getfullname(), True, True) + self.imapserver.releaseconnection(imapobj) except OfflineImapError as e: # retry on dropped connections, raise otherwise self.imapserver.releaseconnection(imapobj, True) if e.severity == OfflineImapError.ERROR.FOLDER_RETRY: retry = True else: raise - finally: - self.imapserver.releaseconnection(imapobj) + except: + # cleanup and raise on all other errors + self.imapserver.releaseconnection(imapobj, True) + raise # 1. Some mail servers do not return an EXISTS response # if the folder is empty. 2. ZIMBRA servers can return # multiple EXISTS replies in the form 500, 1000, 1500,