From 494005eaa5e19961a455276861fb8e0d520b4656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Tue, 5 Jul 2022 12:19:14 +0200 Subject: [PATCH] Fix: Add weird encodings to the list (#1146) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit cfed4061e7bf3e34c52518b905065055acb8858e) Co-authored-by: Adrià Casajús --- app/email_utils.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/email_utils.py b/app/email_utils.py index c5c21785..f2d5a02a 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -874,8 +874,24 @@ def get_encoding(msg: Message) -> EmailEncoding: - base64 - 7bit: default if unknown or empty """ - cte = str(msg.get(headers.CONTENT_TRANSFER_ENCODING, "")).lower().strip() - if cte in ("", "7bit", "7-bit", "8bit", "binary", "8bit;", "utf-8"): + cte = ( + str(msg.get(headers.CONTENT_TRANSFER_ENCODING, "")) + .lower() + .strip() + .strip('"') + .strip("'") + ) + if cte in ( + "", + "7bit", + "7-bit", + "7bits", + "8bit", + "8bits", + "binary", + "8bit;", + "utf-8", + ): return EmailEncoding.NO if cte == "base64":