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:
parent
1a4b7c337c
commit
24db42916c
@ -495,11 +495,10 @@ class IMAPFolder(BaseFolder):
|
|||||||
self.savemessageflags(uid, flags)
|
self.savemessageflags(uid, flags)
|
||||||
return uid
|
return uid
|
||||||
|
|
||||||
|
retry_left = 2 # succeeded in APPENDING?
|
||||||
imapobj = self.imapserver.acquireconnection()
|
imapobj = self.imapserver.acquireconnection()
|
||||||
try:
|
try:
|
||||||
success = False # succeeded in APPENDING?
|
while retry_left:
|
||||||
while not success:
|
|
||||||
|
|
||||||
# UIDPLUS extension provides us with an APPENDUID response.
|
# UIDPLUS extension provides us with an APPENDUID response.
|
||||||
use_uidplus = 'UIDPLUS' in imapobj.capabilities
|
use_uidplus = 'UIDPLUS' in imapobj.capabilities
|
||||||
|
|
||||||
@ -536,12 +535,20 @@ class IMAPFolder(BaseFolder):
|
|||||||
(typ, dat) = imapobj.append(self.getfullname(),
|
(typ, dat) = imapobj.append(self.getfullname(),
|
||||||
imaputil.flagsmaildir2imap(flags),
|
imaputil.flagsmaildir2imap(flags),
|
||||||
date, content)
|
date, content)
|
||||||
success = True
|
retry_left = 0 # Mark as success
|
||||||
except imapobj.abort, e:
|
except imapobj.abort, e:
|
||||||
# connection has been reset, release connection and retry.
|
# connection has been reset, release connection and retry.
|
||||||
self.ui.error(e, exc_info()[2])
|
self.ui.error(e, exc_info()[2])
|
||||||
self.imapserver.releaseconnection(imapobj, True)
|
self.imapserver.releaseconnection(imapobj, True)
|
||||||
imapobj = self.imapserver.acquireconnection()
|
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:
|
except imapobj.error, e:
|
||||||
# If the server responds with 'BAD', append() raise()s directly.
|
# If the server responds with 'BAD', append() raise()s directly.
|
||||||
# So we need to prepare a response ourselves.
|
# So we need to prepare a response ourselves.
|
||||||
|
Loading…
Reference in New Issue
Block a user