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 [175.158.50.43]) by gnuweeb.org (Postfix) with ESMTPSA id 616BA81A34; Wed, 18 Jan 2023 17:54:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1674064480; bh=ekVpPXwkWLhkNNjsE4rpUxy1z+/cw/VhtWsHpvZz7Xk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DN2FDGLd+wqo6abXleEoZ5Ja2z+SJ2DIg3p6joIJT5YG7icDNjb3END5upvgVkJ/V juN4ZLAXS+ndrXTEDVok6R1cXbzZkg7CGl+ELF4dIcR3/syOeGzHi5gck7CsxTmgDe K5zWTAFZmbqRsL+aB4+ySW73X2NM1wH2LsV3acZJL5MgUZDSfe1Yt3+nkM/R0eREK7 v8go4V3uxwGeeqMtrgIV5QVGpmKcga9784AyxRBUCMQkNxa6+FaeV5KrtzJ43ojFDC rwrbRokvYSXV4NWrPJOqYDETMA0iflbEQOxspefQWl88G5sqNRtoQbDW/2wz4MIu22 tDnCsyDhETA+Q== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v2 12/17] utils: fix: Fix charset issue for get_decoded_payload() Date: Thu, 19 Jan 2023 00:53:51 +0700 Message-Id: <20230118175356.1853-13-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20230118175356.1853-1-kiizuha@gnuweeb.org> References: <20230118175356.1853-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