[PATCH 3/4] Remove convoluted assert statements
Sebastian Spaeth
Sebastian at SSpaeth.de
Fri Jan 28 08:22:18 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 a11ee38..f3cc341 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -253,6 +253,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,
@@ -272,6 +273,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])
@@ -413,12 +415,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')
--
1.7.1
More information about the OfflineIMAP-project
mailing list