]> git.proxmox.com Git - pmg-api.git/commitdiff
ruledb: modfield: properly handle fields spanning multiple lines
authorStoiko Ivanov <s.ivanov@proxmox.com>
Tue, 15 Nov 2022 12:40:14 +0000 (13:40 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 15 Nov 2022 14:31:13 +0000 (15:31 +0100)
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>
Reviewed-By: Dominik Csapak <d.csapak@proxmox.com>
Tested-By: Dominik Csapak <d.csapak@proxmox.com>

src/PMG/RuleDB/ModField.pm

index fb15076cc97396e9248f860e24072dc7d4f0e9f8..4ebb618c9413c47a884d751d985bdcd4a0c38ac4 100644 (file)
@@ -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);
     }
 }