Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9806EC35257 for ; Fri, 2 Oct 2020 23:29:37 +0000 (UTC) Received: by mail.kernel.org (Postfix) id 7C2872074B; Fri, 2 Oct 2020 23:29:37 +0000 (UTC) Received: from [192.168.1.64] (unknown [89.36.78.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 371F32072E for ; Fri, 2 Oct 2020 23:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601681377; bh=fGzVxekhLk2cM4n4c/BRu6SzjEEhtaVVaiwWz4JJEGs=; h=From:List-Id:To:Subject:Date:In-Reply-To:References:From; b=h2TrPjwfJPvPBpyh/FqM5Co++TP3Vhk3jTa5NptEUcN3OFiHCYSem7AhwwOL7Tpfy hC7DItTnBHoOlGQmi3BLtQ4m0QL/0EwcEI1TNLg4qU0YS7HJ2TbgshFpLN4O63u5nP 1XTRrwwcfS941KvLbaN4la8/HvzwEpi9MGcFWzF0= From: Konstantin Ryabitsev List-Id: To: signatures@kernel.org Subject: [PATCH 05/10] Tighten follow-up header parsing Date: Fri, 2 Oct 2020 19:29:10 -0400 Message-Id: <20201002232915.1728301-6-konstantin@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201002232915.1728301-1-konstantin@linuxfoundation.org> References: <20201002232915.1728301-1-konstantin@linuxfoundation.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patch-Hashes: v=1; h=sha256; g=63351966684662db932652ef5356c69f5d6fb11c; i=OI5ZwwtNfeSCAe0RdlNnH3TepPelrwAI/N17MbGWw2U=; m=KXSRZG4VPwEwLPZ99tbTfv71ZIWWqQxU1zfqV1EAhUg=; p=S5BJXr2bwWBdbE9bmKYFHLAnIppcZUfDULhhbbP2i0o= X-Patch-Sig: m=pgp; i=konstantin@linuxfoundation.org; s=0xB6C41CE35664996C; b=iHUEABYIAB0WIQR2vl2yUnHhSB5njDW2xBzjVmSZbAUCX3e33QAKCRC2xBzjVmSZbMutAP4+VH4 fGjPSGDEBXfjDAyrLV1Q0T34QLvguGReCz5nwxwD9GWyL0FdFgVfRZqoDl6iSdjACoa2cuTbZtbFi m49ZXQw= The combined routine was too broad for parsing follow-up messages, so this tightens it to avoid too many false positive matches. Signed-off-by: Konstantin Ryabitsev --- b4/__init__.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/b4/__init__.py b/b4/__init__.py index 1cebe2b..d4a67a5 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -1179,6 +1179,8 @@ class LoreMessage: @staticmethod def find_trailers(body): + headers = ('subject', 'date', 'from') + nonperson = ('fixes', 'subject', 'date') # Fix some more common copypasta trailer wrapping # Fixes: abcd0123 (foo bar # baz quux) @@ -1189,7 +1191,8 @@ class LoreMessage: # Signed-off-by: Foo foo # [for the thing that the thing is too long the thing that is # thing but thing] - body = re.sub(r'^(\[[^]]+)\n([^]]+]$)', r'\1 \2', body, flags=re.M) + # (too false-positivey, commented out) + # body = re.sub(r'^(\[[^]]+)\n([^]]+]$)', r'\1 \2', body, flags=re.M) trailers = list() others = list() was_trailer = False @@ -1197,8 +1200,17 @@ class LoreMessage: line = line.strip('\r') matches = re.search(r'^(\w\S+):\s+(\S.*)', line, flags=re.I) if matches: - was_trailer = True groups = list(matches.groups()) + # We only accept headers if we haven't seen any non-trailer lines + tname = groups[0].lower() + if len(others) and tname in headers: + logger.debug('Ignoring %s (header after other content)', line) + continue + mperson = re.search(r'<[^>]+>', groups[1]) + if not mperson and tname not in nonperson: + logger.debug('Ignoring %s (not a recognized non-person trailer)', line) + continue + was_trailer = True groups.append(None) trailers.append(groups) continue -- 2.26.2