Wrap bytes check in a wrapper to be a bit more efficient

This commit is contained in:
Joseph Ishac 2021-04-14 11:19:22 -04:00
parent 0345390aa1
commit f024bb9e4c

View File

@ -299,6 +299,10 @@ class MaildirFolder(BaseFolder):
fd = open(filepath, 'rb')
retval = self.parser['8bit'].parse(fd)
try:
if len(retval.defects) > 0:
ui.warn("Message has defects: {}".format(retval.defects))
# See if the defects are preventing us from obtaining bytes and
# handle known issues
_ = retval.as_bytes(policy=self.policy['8bit'])
except UnicodeEncodeError as err:
if any(isinstance(defect, NoBoundaryInMultipartDefect) for defect in retval.defects):