From: Dominik Csapak <d.csapak@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api v4 02/12] ruledb: properly substitute prox_vars in headers
Date: Thu, 24 Nov 2022 13:21:02 +0100 [thread overview]
Message-ID: <20221124122112.666868-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20221124122112.666868-1-d.csapak@proxmox.com>
From: Stoiko Ivanov <s.ivanov@proxmox.com>
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 | 2 +-
src/PMG/RuleDB/ModField.pm | 13 +------------
src/PMG/RuleDB/Notify.pm | 4 ++--
src/PMG/Utils.pm | 17 +++++++++++++++++
src/bin/pmg-smtp-filter | 2 +-
5 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/src/PMG/RuleDB/BCC.pm b/src/PMG/RuleDB/BCC.pm
index d364690..4867d83 100644
--- a/src/PMG/RuleDB/BCC.pm
+++ b/src/PMG/RuleDB/BCC.pm
@@ -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
diff --git a/src/PMG/RuleDB/ModField.pm b/src/PMG/RuleDB/ModField.pm
index 4ebb618..34108d1 100644
--- a/src/PMG/RuleDB/ModField.pm
+++ b/src/PMG/RuleDB/ModField.pm
@@ -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);
diff --git a/src/PMG/RuleDB/Notify.pm b/src/PMG/RuleDB/Notify.pm
index d67221e..7b38e0d 100644
--- a/src/PMG/RuleDB/Notify.pm
+++ b/src/PMG/RuleDB/Notify.pm
@@ -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
diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm
index cfb8852..cc30e67 100644
--- a/src/PMG/Utils.pm
+++ b/src/PMG/Utils.pm
@@ -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) = @_;
diff --git a/src/bin/pmg-smtp-filter b/src/bin/pmg-smtp-filter
index 35a6ac6..45e68a7 100755
--- a/src/bin/pmg-smtp-filter
+++ b/src/bin/pmg-smtp-filter
@@ -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},
--
2.30.2
next prev parent reply other threads:[~2022-11-24 12:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-24 12:21 [pmg-devel] [PATCH pmg-api v4 00/12] ruledb - improve experience for non-ascii tests and mails Dominik Csapak
2022-11-24 12:21 ` [pmg-devel] [PATCH pmg-api v4 01/12] utils: return perl string from decode_rfc1522 Dominik Csapak
2022-11-24 12:21 ` Dominik Csapak [this message]
2022-11-24 12:21 ` [pmg-devel] [PATCH pmg-api v4 03/12] fix #2541 ruledb: encode relevant values as utf-8 in database Dominik Csapak
2022-11-24 12:21 ` [pmg-devel] [PATCH pmg-api v4 04/12] ruledb: encode e-mail addresses for syslog Dominik Csapak
2022-11-24 12:21 ` [pmg-devel] [PATCH pmg-api v4 05/12] partially fix #2465: handle smtputf8 addresses in the rule-system Dominik Csapak
2022-11-24 12:21 ` [pmg-devel] [PATCH pmg-api v4 06/12] quarantine: handle utf8 data Dominik Csapak
2022-11-24 12:21 ` [pmg-devel] [PATCH pmg-api v4 07/12] pmgqm: handle smtputf8 data Dominik Csapak
2022-11-24 12:21 ` [pmg-devel] [PATCH pmg-api v4 08/12] statistics: handle utf8 data Dominik Csapak
2022-11-24 12:21 ` [pmg-devel] [PATCH pmg-api v4 09/12] quarantine: fix adding non-ascii senders to wl/bl Dominik Csapak
2022-11-24 12:21 ` [pmg-devel] [PATCH pmg-api v4 10/12] utils: refactor rfc1522_to_html Dominik Csapak
2022-11-24 12:21 ` [pmg-devel] [PATCH pmg-api v4 11/12] ldap: improve unicode support Dominik Csapak
2022-11-24 12:21 ` [pmg-devel] [PATCH pmg-api v4 12/12] statistics: refactor filter_text generation Dominik Csapak
2022-11-24 15:45 ` [pmg-devel] applied-series: [PATCH pmg-api v4 00/12] ruledb - improve experience for non-ascii tests and mails 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=20221124122112.666868-3-d.csapak@proxmox.com \
--to=d.csapak@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