[PATCH] Catch 'BAD' replies on append()ing a message

Sebastian Spaeth Sebastian at SSpaeth.de
Mon Aug 15 08:18:37 UTC 2011


append() raises an Exception, in case the IMAP server replies with 'BAD'
(but not when it responds with 'NO') but we were not catching that. Do
catch the situation and also raise an OfflineImapError at MESSAGE
severity, so that we can continue with the next message.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
 offlineimap/folder/IMAP.py |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index 6bb9cfb..b4120a6 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -454,9 +454,14 @@ class IMAPFolder(BaseFolder):
                           (date, dbg_output))
 
             #Do the APPEND
-            (typ, dat) = imapobj.append(self.getfullname(),
+            try:
+                (typ, dat) = imapobj.append(self.getfullname(),
                                        imaputil.flagsmaildir2imap(flags),
                                        date, content)
+            except Exception, 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:"
-- 
1.7.4.1




More information about the OfflineIMAP-project mailing list