use utf-8 if unknown charset in get_header_unicode()

This commit is contained in:
Son NK 2020-11-18 10:02:10 +01:00
parent 391318cbaa
commit be510ea1d7
1 changed files with 5 additions and 0 deletions

View File

@ -603,6 +603,11 @@ def get_header_unicode(header: str):
return decoded_string.decode(charset)
except UnicodeDecodeError:
LOG.warning("Cannot decode header %s", header)
except LookupError: # charset is unknown, e.g.
LOG.exception(
"Cannot decode %s with %s, use utf-8", decoded_string, charset
)
return decoded_string.decode("utf-8")
return header