From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [101.128.112.71]) by gnuweeb.org (Postfix) with ESMTPSA id ACF2A8193D; Tue, 17 Jan 2023 22:13:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1673993587; bh=ekVpPXwkWLhkNNjsE4rpUxy1z+/cw/VhtWsHpvZz7Xk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fIPU1yPva3oLga82zQmEFUV45yRUjDgKI7SJTHc7pnqMw9sWuJ/3lAe++3x+LMG83 xNq6OVf6VRq1qND+l3hu/92xQghCwHggQUy7C0mw6vNUibD24GZU5N2Dv7cgh4Bt5W pSruuOgLQdI3C8pJ0rPvFAi0GURRaZp16vnc4CzPt2u9nOiutOUwZLQP++ouAvCMge eO98Kn4d6TOIDw8QohLByGcUslPMNBIysvzFzvwA9UZYL+5nkKDkiUVi18TWl3KO9W HcVxgjiG/1/JBw7sIl7y5BJMaiouJYx9s5jTbYbDb0W4qDAR8jO0lD/bDGxB1wEO6I aTcZxFp2jepTA== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v1 12/15] utils: fix: Fix charset issue for get_decoded_payload() Date: Wed, 18 Jan 2023 05:12:13 +0700 Message-Id: <20230117221216.1783-13-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20230117221216.1783-1-kiizuha@gnuweeb.org> References: <20230117221216.1783-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Fix the `LookupError` that is thrown by the `decode()` function. The `unknown-8bit` charset is not found in the built-in `decode()` function in Python, so we must manually fix it by using an if statement and decoding using the `ascii` charset while forcing errors using `surrogateescape`. Sample: https://lore.kernel.org/all/Y8Am5wAxC48N12PE@quaddy.sgn/raw Signed-off-by: Muhammad Rizki --- daemon/atom/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/daemon/atom/utils.py b/daemon/atom/utils.py index 96a10a0..73c8978 100644 --- a/daemon/atom/utils.py +++ b/daemon/atom/utils.py @@ -323,6 +323,9 @@ def get_decoded_payload(payload: Message): return payload.get_payload(decode=True) \ .decode(errors="replace") + if charset == "unknown-8bit": + return p.encode().decode("utf-8", "surrogateescape") + return p.encode().decode(charset, errors="replace") -- Muhammad Rizki