From f024bb9e4cf5b153e5f156af910254c24381e502 Mon Sep 17 00:00:00 2001 From: Joseph Ishac Date: Wed, 14 Apr 2021 11:19:22 -0400 Subject: [PATCH] Wrap bytes check in a wrapper to be a bit more efficient --- offlineimap/folder/Maildir.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py index 64527c4..53525de 100644 --- a/offlineimap/folder/Maildir.py +++ b/offlineimap/folder/Maildir.py @@ -299,7 +299,11 @@ class MaildirFolder(BaseFolder): fd = open(filepath, 'rb') retval = self.parser['8bit'].parse(fd) try: - _ = retval.as_bytes(policy=self.policy['8bit']) + 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): # (Hopefully) Rare instance where multipart boundary is not