From 45a417ee724194c0e33f29badf163bde2d45b4b1 Mon Sep 17 00:00:00 2001 From: keskfrad Date: Thu, 21 May 2020 15:06:03 +0200 Subject: [PATCH] attempt to fix issue 169/177 --- imbox/parser.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/imbox/parser.py b/imbox/parser.py index 24dd7b4..a16921f 100644 --- a/imbox/parser.py +++ b/imbox/parser.py @@ -2,6 +2,7 @@ import io import re import email +import chardet import base64 import quopri import sys @@ -130,7 +131,10 @@ def decode_content(message): try: return content.decode(charset, 'ignore') except LookupError: - return content.decode(charset.replace("-", ""), 'ignore') + encoding = chardet.detect(content).get('encoding') + if encoding: + return content.decode(encoding, 'ignore') + return content except AttributeError: return content