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 <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2012-04-21 13:26:09 +02:00
parent f6b8426e16
commit 61e754c65e
2 changed files with 6 additions and 2 deletions

View File

@ -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)
=================================

View File

@ -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,