From b01274ce3838404436caab077ad619648ecc7f0a Mon Sep 17 00:00:00 2001 From: Eygene Ryabinkin Date: Wed, 26 Feb 2014 17:51:48 +0400 Subject: [PATCH] Fix double release of IMAP connection object This commit fixes the case when we're invoking releaseconnection() for a given imapobj twice. This bug manifests itself as {{{ ValueError: list.remove(x): x not in list File "[...]/offlineimap/folder/IMAP.py", line 615, in savemessage self.imapserver.releaseconnection(imapobj) File "[...]/offlineimap/imapserver.py", line 130, in releaseconnection self.assignedconnections.remove(connection) }}} Signed-off-by: Eygene Ryabinkin --- offlineimap/folder/IMAP.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index cec9eda..1f3803c 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -500,6 +500,11 @@ class IMAPFolder(BaseFolder): retry_left = 2 # succeeded in APPENDING? imapobj = self.imapserver.acquireconnection() + # NB: in the finally clause for this try we will release + # NB: the acquired imapobj, so don't do that twice unless + # NB: you will put another connection to imapobj. If you + # NB: really do need to release connection manually, set + # NB: imapobj to None. try: while retry_left: # UIDPLUS extension provides us with an APPENDUID response. @@ -612,7 +617,7 @@ class IMAPFolder(BaseFolder): self.ui.warn('imap', "savemessage: Searching mails for new " "Message-ID failed. Could not determine new UID.") finally: - self.imapserver.releaseconnection(imapobj) + if imapobj: self.imapserver.releaseconnection(imapobj) if uid: # avoid UID FETCH 0 crash happening later on self.messagelist[uid] = {'uid': uid, 'flags': flags}