[pmg-devel] [PATCH pmg-api] ruledb: modfield: properly handle fields spanning multiple lines
Stoiko Ivanov
s.ivanov at proxmox.com
Tue Nov 15 13:40:14 CET 2022
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 at 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
More information about the pmg-devel
mailing list