Merge branch 'mlimonci/unicode' into 'main'
Catch unicode decode errors See merge request kernel-firmware/linux-firmware!37
This commit is contained in:
commit
5f560c1e0d
|
@ -44,11 +44,15 @@ def classify_content(content):
|
||||||
|
|
||||||
for part in msg.walk():
|
for part in msg.walk():
|
||||||
if part.get_content_type() == "text/plain":
|
if part.get_content_type() == "text/plain":
|
||||||
|
try:
|
||||||
body = part.get_payload(decode=True).decode("utf-8")
|
body = part.get_payload(decode=True).decode("utf-8")
|
||||||
for key in content_types.keys():
|
for key in content_types.keys():
|
||||||
if key in body:
|
if key in body:
|
||||||
return content_types[key]
|
return content_types[key]
|
||||||
break
|
break
|
||||||
|
except UnicodeDecodeError as e:
|
||||||
|
logging.warning("Failed to decode email: %s, treating as SPAM" % e)
|
||||||
|
break
|
||||||
return ContentType.SPAM
|
return ContentType.SPAM
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue