]> git.proxmox.com Git - pmg-api.git/commitdiff
ruledb: properly substitute prox_vars in headers
authorStoiko Ivanov <s.ivanov@proxmox.com>
Thu, 24 Nov 2022 12:21:02 +0000 (13:21 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 24 Nov 2022 13:38:44 +0000 (14:38 +0100)
by storing the variables as perl-string (not mime-encoded, and not
utf-8 encoded), and appropriately dealing with multi-line values to
input (folding the headers and encoding as mime).

This fixes another glitch not caught by
d3d6b5dff9e4447d16cb92e0fdf26f67d9384423

the Subject was always displayed with a '?' in the end (due to the
(quoted-printable encoded) \n added).

Additionally adapt the other callsites of PMG::Utils::subst_values
where applicable.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/PMG/RuleDB/BCC.pm
src/PMG/RuleDB/ModField.pm
src/PMG/RuleDB/Notify.pm
src/PMG/Utils.pm
src/bin/pmg-smtp-filter

index d3646906b7cff518cd3c87db4897342404c3a265..4867d83892e234114f2cfcf41f4449b4854a071b 100644 (file)
@@ -117,7 +117,7 @@ sub execute {
 
     my $rulename = $vars->{RULE} // 'unknown';
 
-    my $bcc_to = PMG::Utils::subst_values($self->{target}, $vars);
+    my $bcc_to = PMG::Utils::subst_values_for_header($self->{target}, $vars);
 
     if ($bcc_to =~ m/^\s*$/) {
        # this happens if a notification is triggered by bounce mails
index 4ebb618c9413c47a884d751d985bdcd4a0c38ac4..34108d1418921d2eb4ecdc60dd5956576b6156ce 100644 (file)
@@ -5,7 +5,6 @@ use warnings;
 use DBI;
 use Digest::SHA;
 use Encode qw(encode decode);
-use MIME::Words qw(encode_mimewords);
 
 use PMG::Utils;
 use PMG::ModGroup;
@@ -98,17 +97,7 @@ sub execute {
     my ($self, $queue, $ruledb, $mod_group, $targets, 
        $msginfo, $vars, $marks) = @_;
 
-    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/\n/\n\t/sg; # indent content
-    $fvalue =~ s/\n\s*\n//sg;   # remove empty line
-    $fvalue =~ s/\n?\s*$//s;    # remove trailing spaces
+    my $fvalue = PMG::Utils::subst_values_for_header($self->{field_value}, $vars);
 
     my $subgroups = $mod_group->subgroups($targets);
 
index d67221ebefe156fe7dfefbda8080ea4be4d994d5..7b38e0d050ed71ae7153871cfa5b304d6889dc8d 100644 (file)
@@ -211,8 +211,8 @@ sub execute {
     my $rulename = $vars->{RULE} // 'unknown';
 
     my $body = PMG::Utils::subst_values($self->{body}, $vars);
-    my $subject = PMG::Utils::subst_values($self->{subject}, $vars);
-    my $to = PMG::Utils::subst_values($self->{to}, $vars);
+    my $subject = PMG::Utils::subst_values_for_header($self->{subject}, $vars);
+    my $to = PMG::Utils::subst_values_for_header($self->{to}, $vars);
 
     if ($to =~ m/^\s*$/) {
        # this happens if a notification is triggered by bounce mails
index cfb88520c48453d1246a8b728ddb28636ab0c94c..cc30e67b4063b8f1c65360fc961189cbf5485b10 100644 (file)
@@ -203,6 +203,23 @@ sub subst_values {
     return $body;
 }
 
+sub subst_values_for_header {
+    my ($header, $dh) = @_;
+
+    my $res = '';
+    foreach my $line (split('\r?\n\s*', subst_values ($header, $dh))) {
+       $res .= "\n" if $res;
+       $res .= MIME::Words::encode_mimewords(encode('UTF-8', $line), 'Charset' => 'UTF-8');
+    }
+
+    # support for multiline values (i.e. __SPAM_INFO__)
+    $res =~ s/\n/\n\t/sg; # indent content
+    $res =~ s/\n\s*\n//sg;   # remove empty line
+    $res =~ s/\n?\s*$//s;    # remove trailing spaces
+
+    return $res;
+}
+
 sub reinject_mail {
     my ($entity, $sender, $targets, $xforward, $me, $params) = @_;
 
index 35a6ac6f2196147db8a1279b9eabd0d9f427fafa..45e68a700858521534fce25223f080dadd561363 100755 (executable)
@@ -152,7 +152,7 @@ sub get_prox_vars {
     } if !$spaminfo;
 
     my $vars = {
-       'SUBJECT' => mime_to_perl_string($entity->head->get ('subject', 0) || 'No Subject'),
+       'SUBJECT' => PMG::Utils::decode_rfc1522($entity->head->get ('subject', 0) || 'No Subject'),
        'RULE' => $rule->{name},
        'RULE_INFO' => $msginfo->{rule_info},
        'SENDER' => $msginfo->{sender},