Browse Source

Catch unicode decode errors

emails with spam might have non-ASCII characters, don't let the script explode.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
main
Mario Limonciello 1 year ago
parent
commit
7bfa5f4d10
  1. 14
      contrib/process_linux_firmware.py

14
contrib/process_linux_firmware.py

@ -44,11 +44,15 @@ def classify_content(content): @@ -44,11 +44,15 @@ def classify_content(content):

for part in msg.walk():
if part.get_content_type() == "text/plain":
body = part.get_payload(decode=True).decode("utf-8")
for key in content_types.keys():
if key in body:
return content_types[key]
break
try:
body = part.get_payload(decode=True).decode("utf-8")
for key in content_types.keys():
if key in body:
return content_types[key]
break
except UnicodeDecodeError as e:
logging.warning("Failed to decode email: %s, treating as SPAM" % e)
break
return ContentType.SPAM



Loading…
Cancel
Save