From b40e835215c2bd3bb51eebe807adfe3a7ba1600f Mon Sep 17 00:00:00 2001 From: Thomas Oettli Date: Mon, 27 Jan 2020 22:47:57 +0100 Subject: [PATCH] Fix error during decoding of mail body --- pyquarantine/notifications.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pyquarantine/notifications.py b/pyquarantine/notifications.py index ac914f9..7d87bfb 100644 --- a/pyquarantine/notifications.py +++ b/pyquarantine/notifications.py @@ -229,15 +229,12 @@ class EMailNotification(BaseNotification): break if body is not None: - # get the character set, fallback to utf-8 if not defined in header - charset = body.get_content_charset() - if charset is None: - charset = "utf-8" - - # decode content - content = body.get_payload(decode=True).decode( - encoding=charset, errors="replace") - + charset = body.get_content_charset() or "utf-8" + content = body.get_payload(decode=True) + try: + content = content.decode(encoding=charset, errors="replace") + except LookupError: + content = content.decode("utf-8", errors="replace") content_type = body.get_content_type() if content_type == EMailNotification._plain_text: # convert text/plain to text/html