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 kanazawa.. (unknown [101.128.126.198]) by gnuweeb.org (Postfix) with ESMTPSA id 9EE0F80E4B; Fri, 4 Nov 2022 18:09:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1667585388; bh=8LQPddJEPgrO3KlQpv+ttkwnK6tNlLdIuaOVrBb2n3s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O4JPG+w3vV/c0iuuf76m+Op/kjtCB46blxyGUztV/+9WPSZFdck3iDNwSBQvK4aup CPcJUcjIYqgzHxJ39Hj9LJKRJbfjnnEx/5nhJhqxn3Nup3mYZyLqPiX8GKQ/avaPiW grLci3tw1IjSppxj8/cFjE9AKNeg8vIShb3OfPQrFu9odV7IRRrbGIptVXz244i3IU 6lGpsOlr+crJ+9XKBucA9BOZanEXQJYqTweRDP+M9WmGPp+edkoHNK4SZ/C/wyJPLM EbPPWz2EdjeCV1DQmDLO3oX0qhp56PZ8pT8NntLeALkblVPFqJmaDu0aWYLz4BA/ja kH9IDthDpt1kg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v1 04/16] utils: Back to use decode=True for the get_payload() Date: Sat, 5 Nov 2022 01:09:11 +0700 Message-Id: <20221104180931.3852-5-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221104180931.3852-1-kiizuha@gnuweeb.org> References: <20221104180931.3852-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 b807f7b..15679d2 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 @@ -272,11 +272,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