public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pmg-devel] [PATCH pmg-api] ruledb: modfield: properly handle fields spanning multiple lines
@ 2022-11-15 12:40 Stoiko Ivanov
  2022-11-15 14:22 ` Dominik Csapak
  2022-11-15 14:32 ` [pmg-devel] applied: " Thomas Lamprecht
  0 siblings, 2 replies; 3+ messages in thread
From: Stoiko Ivanov @ 2022-11-15 12:40 UTC (permalink / raw)
  To: pmg-devel

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





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pmg-devel] [PATCH pmg-api] ruledb: modfield: properly handle fields spanning multiple lines
  2022-11-15 12:40 [pmg-devel] [PATCH pmg-api] ruledb: modfield: properly handle fields spanning multiple lines Stoiko Ivanov
@ 2022-11-15 14:22 ` Dominik Csapak
  2022-11-15 14:32 ` [pmg-devel] applied: " Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Dominik Csapak @ 2022-11-15 14:22 UTC (permalink / raw)
  To: Stoiko Ivanov, pmg-devel

LGTM and seems to fix the issue mentioned in the forum
(triggered that yesterday too, but thought it was a fallout
in the spamquarantine from the utf8 patches)

Reviewed-By: Dominik Csapak <d.csapak@proxmox.com>
Tested-By: Dominik Csapak <d.csapak@proxmox.com>




^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pmg-devel] applied: [PATCH pmg-api] ruledb: modfield: properly handle fields spanning multiple lines
  2022-11-15 12:40 [pmg-devel] [PATCH pmg-api] ruledb: modfield: properly handle fields spanning multiple lines Stoiko Ivanov
  2022-11-15 14:22 ` Dominik Csapak
@ 2022-11-15 14:32 ` Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2022-11-15 14:32 UTC (permalink / raw)
  To: Stoiko Ivanov, pmg-devel

Am 15/11/2022 um 13:40 schrieb Stoiko Ivanov:
> 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(-)
> 
>

applied, with Dominik's T-b & R-b, thanks!




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-15 14:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-15 12:40 [pmg-devel] [PATCH pmg-api] ruledb: modfield: properly handle fields spanning multiple lines Stoiko Ivanov
2022-11-15 14:22 ` Dominik Csapak
2022-11-15 14:32 ` [pmg-devel] applied: " Thomas Lamprecht

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