1
0
mirror of https://github.com/OfflineIMAP/offlineimap.git synced 2024-06-29 07:50:51 +02:00

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 <Sebastian@SSpaeth.de>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Sebastian Spaeth 2011-09-13 16:27:54 +02:00 committed by Nicolas Sebrecht
parent 1a4b7c337c
commit 24db42916c

View File

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