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.126.198]) by gnuweeb.org (Postfix) with ESMTPSA id 35A0F81565; Wed, 9 Nov 2022 02:50:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1667962230; bh=u6Ohmicy6kPcWgUh9DClHdBuaQGpCctXEdhDvYhHqyw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UAGvaCSDbj86wZBCK0BH93Ml7swpTB4eB8n1U5qW+BOSDpgvOETj4w3/txRW2ABL0 0EBuV3aLzrSfii9yo/ACgm2evvPSbDfDzTHJBixUN3sy/9w+iFOW4ZH1IeSrR+D/Fj SW2dB24eQk2bZBrFMuBnhJYK36bXf6/+OrCFhJG/3mxmxsCh2ICqwv+z8kcmcro4Xx FkGWWBi+3NaJb2Kk0S75gKmhCTBSflI+U1/NjGTDdDRLmj//y67oIhVbkhQbRJbkka NbxVUkGc+xASTV7b0iK/hHPM4euowuB8y8Ass57AgziPOyIYqVUTHPbmQr29s+k3lm V3c5w2Isf7goQ== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v2 05/17] utils: Back to use decode=True for the get_payload() Date: Wed, 9 Nov 2022 09:49:50 +0700 Message-Id: <20221109025002.258-6-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221109025002.258-1-kiizuha@gnuweeb.org> References: <20221109025002.258-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 cfcbeb4..dd9e1a6 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 @@ -267,11 +267,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