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 641C48191C; Mon, 19 Dec 2022 23:57:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1671494268; bh=Pj78KQptU9iOfqMqH0vjR3Yp+g7Eqrj+RwgjWfpUlSk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ji0Ea/USH6SrBViIGVgNfdpStNUhcMUhEmGtTMGt7JenzCHUwMo65ib+xGXzgellU vAjQqgxMqbL5o1fKWTgczLggS7PwbkrSUEVHQ/H5dJxukCbqWMPmwgSBzMYBeKdkIz mDH2hYufQSgfmIwA/JQi/FF5PIXqNMgSu1FMzYXwM7YFNtfbIJmAn7CPRg9UFrkvJR WcE9lkq8MwyqZSY/kQQ00uSMDRLhcz4h5XOGSpu/OotRBvs4CuoTdCFvUaP2e3Sko2 II33Cg6apSMtcYyGTMU/VjTffuAGPxFxXNh3GlLnVBmjVirCw5cnadVpe+7XjGiStM lyWcqhhA1nNBg== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v3 02/17] fix: utils: Fix .patch file payload Date: Tue, 20 Dec 2022 06:57:06 +0700 Message-Id: <20221219235721.126-3-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: >From the previous version 59d20af, the .patch file payload uses the prepare_patch() `text` parameter that taken from the create_template() `caption` returned which is the caption is already trimmed. With the current fix, this should be use the full email payload instead so its not bothering with the trimmed payload from the create_template(). Fixes: 59d20af ("daemon: Move prepare for patch and clean up patch functions") Signed-off-by: Muhammad Rizki --- daemon/atom/utils.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/daemon/atom/utils.py b/daemon/atom/utils.py index 03453b4..8a6c1a8 100644 --- a/daemon/atom/utils.py +++ b/daemon/atom/utils.py @@ -213,7 +213,7 @@ def create_template(thread: Message, platform: Platform, to=None, cc=None): return ret, files, is_patch -def prepare_patch(mail, text, url, platform: Platform): +def prepare_patch(mail: Message, text, url, platform: Platform): tmp = gen_temp(url, platform) fnm = str(mail.get("subject")) sch = re.search(PATCH_PATTERN, fnm, re.IGNORECASE) @@ -230,7 +230,21 @@ def prepare_patch(mail, text, url, platform: Platform): cap = text.split("\n\n")[0] with open(file, "wb") as f: - f.write(bytes(text, encoding="utf8")) + write_payload = bytes(f"{cap}\n\n".encode()) + + # sometimes an email PATCH is a multipart + # so, we must loop the payload first + # then, check if each payload is a PATCH payload + # or no, if it's a PATCH payload then write payload + # to the file. + if mail.is_multipart(): + for m in mail.get_payload(): + subject = mail.get("subject") + if not __is_patch(subject, str(m)): + continue + write_payload += m.get_payload(decode=True) + + f.write(write_payload) caption = "#patch #ml" if platform is Platform.TELEGRAM: -- Muhammad Rizki