From: Stoiko Ivanov Date: Mon, 24 Feb 2020 18:16:48 +0000 (+0100) Subject: fix #2525: encode notifications in UTF-8 X-Git-Url: https://git.proxmox.com/?p=pmg-api.git;a=commitdiff_plain;h=45102dfdc71ad50709e82ccb5911fadd7bd6e67f;hp=f7f689cecd05e64bd2a19e5b3f394dea2d3901b8 fix #2525: encode notifications in UTF-8 the Notify action is one of the places where we already encode the data as UTF-8, before writing it to the DB (and decoding it when reading). as laid out in rt.cpan.org [0] Mime::Body does expect encoded bytes, and not perl characters. Tested by creating a notification with the body supplied in #2591 (which is a duplicate of #2525) and additionally with cyrillic characters in the subject. A minimal test case is a body consisting of a Euro sign (since its Unicode codepoint is larger than one byte). Should the table contain invalid UTF-8 sequences (AFAIU only possible by direct DB-manipulation) the byte gets replaced with \x{fffd} (Unicode replacement character). [0] https://rt.cpan.org/Public/Bug/Display.html?id=105377#txn-1762112 Signed-off-by: Stoiko Ivanov Reviewed-by: Dominik Csapak Tested-by: Dominik Csapak Signed-off-by: Thomas Lamprecht --- diff --git a/src/PMG/RuleDB/Notify.pm b/src/PMG/RuleDB/Notify.pm index 860b5ce..ec18a7e 100644 --- a/src/PMG/RuleDB/Notify.pm +++ b/src/PMG/RuleDB/Notify.pm @@ -224,10 +224,12 @@ sub execute { $to =~ s/\s+/,/g; my $top = MIME::Entity->build( + Encoding => 'quoted-printable', + Charset => 'UTF-8', From => $from, To => $to, - Subject => $subject, - Data => $body); + Subject => encode('UTF-8', $subject), + Data => encode('UTF-8', $body)); if ($self->{attach} eq 'O') { # attach original mail