From 96db608e4d0a8d1c59f8e5d343fb8008e2236aed Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Fri, 4 Mar 2011 17:34:22 +0100 Subject: [PATCH] Remove convoluted assert statements 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 Signed-off-by: Nicolas Sebrecht --- offlineimap/folder/IMAP.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index eab7ffb..17b849b 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -252,6 +252,7 @@ class IMAPFolder(BaseFolder): headervalue += str(self.randomgenerator.randint(0,9999999999)) return (headername, headervalue) + def savemessage_addheader(self, content, headername, headervalue): self.ui.debug('imap', 'savemessage_addheader: called to add %s: %s' % (headername, @@ -271,6 +272,7 @@ class IMAPFolder(BaseFolder): self.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]) @@ -417,12 +419,16 @@ class IMAPFolder(BaseFolder): self.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. self.ui.debug('imap', 'savemessage: first attempt to get new UID')