[PATCH 3/4] Remove convoluted assert statements

Sebastian Spaeth Sebastian at SSpaeth.de
Fri Jan 21 14:09:06 GMT 2011


The working horse of the savemessage() function, imaplib.append() was
hidden away in an assert statement. Pull the real functions out of the
asserts and simply assert on the return values. This looks less
convoluted and makes this easier to understand in my opinion.

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

diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index 494e309..44dc1cc 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -246,6 +246,7 @@ class IMAPFolder(BaseFolder):
         headervalue += str(self.randomgenerator.randint(0,9999999999))
         return (headername, headervalue)
 
+
     def savemessage_addheader(self, content, headername, headervalue):
         ui = UIBase.getglobalui()
         ui.debug('imap',
@@ -266,6 +267,7 @@ class IMAPFolder(BaseFolder):
         ui.debug('imap', 'savemessage_addheader: trailer = ' + repr(trailer))
         return leader + newline + trailer
 
+
     def savemessage_searchforheader(self, imapobj, headername, headervalue):
         if imapobj.untagged_responses.has_key('APPENDUID'):
             return long(imapobj.untagged_responses['APPENDUID'][-1].split(' ')[1])
@@ -381,12 +383,16 @@ class IMAPFolder(BaseFolder):
             ui.debug('imap', 'savemessage: new content length is ' + \
                      str(len(content)))
 
-            assert(imapobj.append(self.getfullname(),
+            # TODO: append could raise a ValueError if the date is not in
+            #       valid format...?
+            (typ,dat) = imapobj.append(self.getfullname(),
                                        imaputil.flagsmaildir2imap(flags),
-                                       date, content)[0] == 'OK')
+                                       date, content)
+            assert(typ == 'OK')
 
             # Checkpoint.  Let it write out the messages, etc.
-            assert(imapobj.check()[0] == 'OK')
+            (typ,dat) = imapobj.check()
+            assert(typ == 'OK')
 
             # Keep trying until we get the UID.
             ui.debug('imap', 'savemessage: first attempt to get new UID')
-- 
1.7.1





More information about the OfflineIMAP-project mailing list