]> git.proxmox.com Git - mirror_linux-firmware.git/commitdiff
Catch unicode decode errors
authorMario Limonciello <mario.limonciello@amd.com>
Mon, 23 Oct 2023 15:10:24 +0000 (10:10 -0500)
committerMario Limonciello <mario.limonciello@amd.com>
Mon, 23 Oct 2023 15:10:47 +0000 (10:10 -0500)
emails with spam might have non-ASCII characters, don't let the script explode.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
contrib/process_linux_firmware.py

index 2b7c7f8d5fc3fc17abe6ed35f8ee65da5b55f02d..ab005ee7cc774a35aeac479aec71a2979738108b 100755 (executable)
@@ -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