From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id F3F2770FF3 for ; Tue, 17 May 2022 11:45:42 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EE91B2729D for ; Tue, 17 May 2022 11:45:12 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 2C22027294 for ; Tue, 17 May 2022 11:45:12 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 69D0D4366E for ; Tue, 17 May 2022 11:39:52 +0200 (CEST) From: Stoiko Ivanov To: pmg-devel@lists.proxmox.com Date: Tue, 17 May 2022 11:39:25 +0200 Message-Id: <20220517093925.18457-1-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.197 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox.com, metacpan.org, matchfield.pm] Subject: [pmg-devel] [PATCH pmg-api] rulesystem: matchfield: match all headers not only the first X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 May 2022 09:45:43 -0000 currently the match field uses $entity->head->get in scalar context, which only returns the first matching header (see [0]) switch over to using get_all in list context and iterating over all headers makes it possible to match subsequent headers. while it is uncommon in general - the Received headers are usually not restricted to one - reported in our community forum: https://forum.proxmox.com/threads/.109629/ [0] https://metacpan.org/pod/MIME::Head#Getting-field-contents Signed-off-by: Stoiko Ivanov --- best viewed with `git show -w` tested with the sample from the forum for the multiple received headers case and a simple subject match for the single header case. src/PMG/RuleDB/MatchField.pm | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/PMG/RuleDB/MatchField.pm b/src/PMG/RuleDB/MatchField.pm index b1da4fa..171cb3d 100644 --- a/src/PMG/RuleDB/MatchField.pm +++ b/src/PMG/RuleDB/MatchField.pm @@ -102,13 +102,15 @@ sub parse_entity { if (my $id = $entity->head->mime_attr ('x-proxmox-tmp-aid')) { chomp $id; - if (defined(my $value = $entity->head->get($self->{field}))) { - chomp $value; + if (my @values = $entity->head->get_all($self->{field})) { + for my $value (@values) { + chomp $value; - my $decvalue = MIME::Words::decode_mimewords($value); + my $decvalue = MIME::Words::decode_mimewords($value); - if ($decvalue =~ m|$self->{field_value}|i) { - push @$res, $id; + if ($decvalue =~ m|$self->{field_value}|i) { + push @$res, $id; + } } } } -- 2.30.2