From f6b9c683338c72349bbec903ac3c51a2ff03c0e3 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 11 Aug 2011 12:22:36 +0200 Subject: [PATCH] IMAP: Don't use assert() in folder.savemessage() We simply assert()ed that APPENDing a message returned OK, but in some cases (e.g. Google chat messages) APPEND might return BAD or NO too. We should be throwing an OfflineImapError here at MESSAGE level, so that we can continue to sync all other messages, and still give the user some details on what went wrong at the end of the sync run. Signed-off-by: Sebastian Spaeth Signed-off-by: Nicolas Sebrecht --- offlineimap/folder/IMAP.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index 3c702f4..6bb9cfb 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -450,16 +450,20 @@ class IMAPFolder(BaseFolder): content[-50:]) else: dbg_output = content - self.ui.debug('imap', "savemessage: date: %s, content: '%s'" % (date, dbg_output)) - (typ,dat) = imapobj.append(self.getfullname(), + #Do the APPEND + (typ, dat) = imapobj.append(self.getfullname(), imaputil.flagsmaildir2imap(flags), date, content) - assert(typ == 'OK') - - # Checkpoint. Let it write out the messages, etc. + 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) + # 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() assert(typ == 'OK')