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 autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [101.128.125.209]) by gnuweeb.org (Postfix) with ESMTPSA id 8A9698194D; Mon, 19 Dec 2022 23:57:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1671494275; bh=bBXY7A8SgMPskjLt0pKtc+r4YTuZYRfw+uDCMQRG340=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e7/RtbMU6LdQSdI4Dkwln5gNlhMMvVt2FhaI8+mra7lneu92H4Qxnqxy9/bDEjwxN Qt+OHrBlExdUYfFvt/Ai+Cu223Vlr7YN7gTNyU3/k9MkPoco/BstBWGaf2jdTjBevp QPGBSbrgKc7aq00VqPDNwn5R26kH4mvq0D7rMTJQM6lFFFQR+pOg2wp6cPQnYVHNq/ w2VAtKo1v9QRN17qHSnTXe/maJPcG0YWcUbQ8t8LWX7Lk7MiiDLiDS2GEYjk87cy9Z B/9UpSKWRKN1avA0UN7l8z7zjtYVB1bbMkpCx3512Pw9nPRc0QTIYObhRuMxhZRsHg skCPEwqzVU/Ow== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v3 05/17] utils: Back to use decode=True for the get_payload() Date: Tue, 20 Dec 2022 06:57:09 +0700 Message-Id: <20221219235721.126-6-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221219235721.126-1-kiizuha@gnuweeb.org> References: <20221219235721.126-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Because at the previous version still not solving the error, this version is use decode=True for the get_payload() in the get_decoded_payload() just for the base64, quoted-printable, and binary transfer encoding only. Signed-off-by: Muhammad Rizki --- daemon/atom/utils.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/daemon/atom/utils.py b/daemon/atom/utils.py index c5f6a00..127b0cc 100644 --- a/daemon/atom/utils.py +++ b/daemon/atom/utils.py @@ -10,7 +10,7 @@ from pyrogram.types import Chat, InlineKeyboardMarkup, InlineKeyboardButton from email.message import Message from typing import Dict, Union from slugify import slugify -from base64 import b64decode +import traceback import hashlib import uuid import os @@ -287,11 +287,9 @@ def get_decoded_payload(payload: Message): tf_encode = payload.get("Content-Transfer-Encoding") charset = payload.get_content_charset("utf-8") - if tf_encode == "base64": - return b64decode(p).decode(charset) - if tf_encode == "quoted-printable": - quobyte = quopri.decodestring(p.encode()) - return quobyte.decode(charset) + if tf_encode in ["base64", "quoted-printable", "binary"]: + return payload.get_payload(decode=True) \ + .decode(errors="replace") return p.encode().decode(charset, errors="replace") -- Muhammad Rizki