Robustify (&fix) error throwing on APPEND

If APPEND raises abort(), the (typ, dat) variables will not be set, so
we should not be using it for the  OfflineImapError Exception
string. Fixing and prettifying the string formatting a bit at the same
time.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2011-09-26 15:57:35 +02:00
parent 1b6d76345a
commit 953c58a9c9

View File

@ -541,21 +541,18 @@ class IMAPFolder(BaseFolder):
imapobj = self.imapserver.acquireconnection()
if not retry_left:
raise OfflineImapError("Saving msg in folder '%s', "
"repository '%s' failed. Server reponded; %s %s\n"
"repository '%s' failed. Server reponded: %s\n"
"Message content was: %s" %
(self, self.getrepository(),
typ, dat, dbg_output),
(self, self.getrepository(), str(e), 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.
typ, dat = 'BAD', str(e)
if typ != 'OK': #APPEND failed
raise OfflineImapError("Saving msg in folder '%s', repository "
"'%s' failed. Server reponded; %s %s\nMessage content was:"
" %s" % (self, self.getrepository(), typ, dat, dbg_output),
OfflineImapError.ERROR.MESSAGE)
except imapobj.error, e: # APPEND failed
# If the server responds with 'BAD', append()
# raise()s directly. So we catch that too.
raise OfflineImapError("Saving msg folder '%s', repo '%s'"
"failed. Server reponded: %s\nMessage content was: "
"%s" % (self, self.getrepository(), str(e), dbg_output),
OfflineImapError.ERROR.MESSAGE)
# Checkpoint. Let it write out stuff, etc. Eg searches for
# just uploaded messages won't work if we don't do this.
(typ,dat) = imapobj.check()