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.125.209]) by gnuweeb.org (Postfix) with ESMTPSA id DECD1819CF; Wed, 21 Dec 2022 01:34:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1671586455; bh=+3iQAFLm2u3uHqw5JQGa+r5IuhXMo6coVotFbYUOrzw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lot45bKlTSRgRCF8uPsB2KWrLtFP3i7XcbmPJ63ohi12dKYfWMiAObD9u6HN+YKfk uMfapcZkdWMujF8ZlSikpxW9dQwwxf7YP3SLvEqqCoXND0MIlRkcna8mcBRdkLffPE wmO8lrnV9/d6MppjWDlvQhAtO3Zh6Ed2NWGlRiWgFUSOMBjBjkFZ5+sOFfHeV6JKwn A3Rw0MSfLR7Y1q5v6zdT24Rq5VnwDtHsdoYOpxgtR7yJBmTh7XWooOGgHXpAk51Iax M2xiKdrzFpVCn2+ti0SAdbIPKU5eJgEXHdagujpVm7lfS0Z8y4Ndah3pX0W8zRiCFA XidplUV3tCphw== From: Muhammad Rizki To: Ammar Faizi Cc: Muhammad Rizki , Alviro Iskandar Setiawan , GNU/Weeb Mailing List Subject: [PATCH v4 02/17] fix: utils: Fix .patch file payload Date: Wed, 21 Dec 2022 08:33:32 +0700 Message-Id: <20221221013347.1704-3-kiizuha@gnuweeb.org> X-Mailer: git-send-email 2.34.1.windows.1 In-Reply-To: <20221221013347.1704-1-kiizuha@gnuweeb.org> References: <20221221013347.1704-1-kiizuha@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: >From the previous version 59d20af68a05, 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: 59d20af68a05 ("daemon: Move prepare for patch and clean up patch functions") Signed-off-by: Muhammad Rizki --- daemon/atom/utils.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/daemon/atom/utils.py b/daemon/atom/utils.py index 03453b4..6597c41 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,23 @@ 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) + else: + write_payload += mail.get_payload(decode=True) + + f.write(write_payload) caption = "#patch #ml" if platform is Platform.TELEGRAM: -- Muhammad Rizki