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 <Sebastian@SSpaeth.de> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
d22c762385
commit
96db608e4d
@ -252,6 +252,7 @@ class IMAPFolder(BaseFolder):
|
|||||||
headervalue += str(self.randomgenerator.randint(0,9999999999))
|
headervalue += str(self.randomgenerator.randint(0,9999999999))
|
||||||
return (headername, headervalue)
|
return (headername, headervalue)
|
||||||
|
|
||||||
|
|
||||||
def savemessage_addheader(self, content, headername, headervalue):
|
def savemessage_addheader(self, content, headername, headervalue):
|
||||||
self.ui.debug('imap',
|
self.ui.debug('imap',
|
||||||
'savemessage_addheader: called to add %s: %s' % (headername,
|
'savemessage_addheader: called to add %s: %s' % (headername,
|
||||||
@ -271,6 +272,7 @@ class IMAPFolder(BaseFolder):
|
|||||||
self.ui.debug('imap', 'savemessage_addheader: trailer = ' + repr(trailer))
|
self.ui.debug('imap', 'savemessage_addheader: trailer = ' + repr(trailer))
|
||||||
return leader + newline + trailer
|
return leader + newline + trailer
|
||||||
|
|
||||||
|
|
||||||
def savemessage_searchforheader(self, imapobj, headername, headervalue):
|
def savemessage_searchforheader(self, imapobj, headername, headervalue):
|
||||||
if imapobj.untagged_responses.has_key('APPENDUID'):
|
if imapobj.untagged_responses.has_key('APPENDUID'):
|
||||||
return long(imapobj.untagged_responses['APPENDUID'][-1].split(' ')[1])
|
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 ' + \
|
self.ui.debug('imap', 'savemessage: new content length is ' + \
|
||||||
str(len(content)))
|
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),
|
imaputil.flagsmaildir2imap(flags),
|
||||||
date, content)[0] == 'OK')
|
date, content)
|
||||||
|
assert(typ == 'OK')
|
||||||
|
|
||||||
# Checkpoint. Let it write out the messages, etc.
|
# 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.
|
# Keep trying until we get the UID.
|
||||||
self.ui.debug('imap', 'savemessage: first attempt to get new UID')
|
self.ui.debug('imap', 'savemessage: first attempt to get new UID')
|
||||||
|
Loading…
Reference in New Issue
Block a user