public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api] ruledb: modfield: properly handle fields spanning multiple lines
Date: Tue, 15 Nov 2022 13:40:14 +0100	[thread overview]
Message-ID: <20221115124014.63658-1-s.ivanov@proxmox.com> (raw)

this commit fixes aa3a005a5e7e3ad69ed35e9957fa514f73315c72

MIME::Words::encode_mimewords does not deal with multiline headers
(the warning about this being a 'quick and dirty' solution [0]
partially tells as much).

Instead - split the replacement value after variable substition on:
'\r?\n\s*' (to capture multi-line values like __SPAM_INFO__, but also
already folded headers, which are separated by '\r?\n\s+') and do the
substitution for each line seperately.

reported in our community forum:
https://forum.proxmox.com/threads/.118001/

[0] https://metacpan.org/pod/MIME::Words#PUBLIC-INTERFACE

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
---
 src/PMG/RuleDB/ModField.pm | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/PMG/RuleDB/ModField.pm b/src/PMG/RuleDB/ModField.pm
index fb15076..4ebb618 100644
--- a/src/PMG/RuleDB/ModField.pm
+++ b/src/PMG/RuleDB/ModField.pm
@@ -98,10 +98,15 @@ sub execute {
     my ($self, $queue, $ruledb, $mod_group, $targets, 
 	$msginfo, $vars, $marks) = @_;
 
-    my $fvalue = PMG::Utils::subst_values ($self->{field_value}, $vars);
+    my $fvalue = '';
+
+    foreach my $line (split('\r?\n\s*',PMG::Utils::subst_values ($self->{field_value}, $vars))) {
+	$fvalue .= "\n" if $fvalue;
+	$fvalue .= encode_mimewords(encode('UTF-8', $line), 'Charset' => 'UTF-8');
+    }
 
     # support for multiline values (i.e. __SPAM_INFO__)
-    $fvalue =~ s/\r?\n/\n\t/sg; # indent content
+    $fvalue =~ s/\n/\n\t/sg; # indent content
     $fvalue =~ s/\n\s*\n//sg;   # remove empty line
     $fvalue =~ s/\n?\s*$//s;    # remove trailing spaces
 
@@ -109,7 +114,7 @@ sub execute {
 
     foreach my $ta (@$subgroups) {
 	my ($tg, $e) = (@$ta[0], @$ta[1]);
-	$e->head->replace($self->{field}, encode_mimewords(encode('UTF-8', $fvalue), "Charset" => "UTF-8"));
+	$e->head->replace($self->{field}, $fvalue);
     }
 }
 
-- 
2.30.2





             reply	other threads:[~2022-11-15 12:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-15 12:40 Stoiko Ivanov [this message]
2022-11-15 14:22 ` Dominik Csapak
2022-11-15 14:32 ` [pmg-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221115124014.63658-1-s.ivanov@proxmox.com \
    --to=s.ivanov@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal