From 24db42916c418b336dec6310ce8cae1d9a1ea4cb Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Tue, 13 Sep 2011 16:27:54 +0200 Subject: [PATCH] IMAP savemessage(): Don't loop indefinitely on failure We were retrying indefinitely on imapobj.abort() (as that is what imaplib2 suggests), but if the failure occurs repeatedly, we'll never quit this loop. So implement a counter that errs out after unsuccessful retries. Signed-off-by: Sebastian Spaeth Signed-off-by: Nicolas Sebrecht --- offlineimap/folder/IMAP.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index f3d1ad8..67603dd 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -495,11 +495,10 @@ class IMAPFolder(BaseFolder): self.savemessageflags(uid, flags) return uid + retry_left = 2 # succeeded in APPENDING? imapobj = self.imapserver.acquireconnection() try: - success = False # succeeded in APPENDING? - while not success: - + while retry_left: # UIDPLUS extension provides us with an APPENDUID response. use_uidplus = 'UIDPLUS' in imapobj.capabilities @@ -536,12 +535,20 @@ class IMAPFolder(BaseFolder): (typ, dat) = imapobj.append(self.getfullname(), imaputil.flagsmaildir2imap(flags), date, content) - success = True + 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]) self.imapserver.releaseconnection(imapobj, True) imapobj = self.imapserver.acquireconnection() + if not retry_left: + raise OfflineImapError("Saving msg in folder '%s', " + "repository '%s' failed. Server reponded; %s %s\n" + "Message content was: %s" % + (self, self.getrepository(), + typ, dat, dbg_output), + OfflineImapError.ERROR.MESSAGE) + retry_left -= 1 except imapobj.error, e: # If the server responds with 'BAD', append() raise()s directly. # So we need to prepare a response ourselves.