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 C7393710BE for ; Tue, 17 May 2022 12:20:32 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B684C27A8A for ; Tue, 17 May 2022 12:20:02 +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 EE6C127A81 for ; Tue, 17 May 2022 12:20:01 +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 C13154366E for ; Tue, 17 May 2022 12:20:01 +0200 (CEST) From: Stoiko Ivanov To: pmg-devel@lists.proxmox.com Date: Tue, 17 May 2022 12:19:50 +0200 Message-Id: <20220517101950.24110-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.196 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. [matchfield.pm, metacpan.org, proxmox.com] Subject: [pmg-devel] [PATCH pmg-api v2] 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 10:20:32 -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 --- v1->v2: * dropped useless indentation by directly iterating over the list (if it's empty the iteration will not happen) - huge thx to Dominik for the feedback! 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PMG/RuleDB/MatchField.pm b/src/PMG/RuleDB/MatchField.pm index b1da4fa..2671ea4 100644 --- a/src/PMG/RuleDB/MatchField.pm +++ b/src/PMG/RuleDB/MatchField.pm @@ -102,7 +102,7 @@ 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}))) { + for my $value ($entity->head->get_all($self->{field})) { chomp $value; my $decvalue = MIME::Words::decode_mimewords($value); -- 2.30.2