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 0B0F27102E for ; Tue, 17 May 2022 12:15:14 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id EF35A27A3C for ; Tue, 17 May 2022 12:15:13 +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 47CA927A2F for ; Tue, 17 May 2022 12:15: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 0E3224366E; Tue, 17 May 2022 12:05:19 +0200 (CEST) Message-ID: Date: Tue, 17 May 2022 12:05:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:101.0) Gecko/20100101 Thunderbird/101.0 Content-Language: en-US To: Stoiko Ivanov , pmg-devel@lists.proxmox.com References: <20220517093925.18457-1-s.ivanov@proxmox.com> From: Dominik Csapak In-Reply-To: <20220517093925.18457-1-s.ivanov@proxmox.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.319 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 NICE_REPLY_A -0.401 Looks like a legit reply (A) 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: Re: [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 10:15:14 -0000 On 5/17/22 11:39, Stoiko Ivanov wrote: > 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; > + } > } > } > } the docs say that get_all returns always a list, so we could do: for my $value ($entity->head->get_all($self->{field})) { ... } directly, no? would save us a level of indentation