[PATCH 3/3] IMAP: Don't use assert() in folder.savemessage()

Sebastian Spaeth Sebastian at SSpaeth.de
Thu Aug 11 11:22:36 BST 2011

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 <Sebastian at SSpaeth.de>
 offlineimap/folder/IMAP.py |   14 +++++++++-----
 1 files 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):
                 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(),
                                        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')

More information about the OfflineIMAP-project mailing list