]> git.proxmox.com Git - pmg-api.git/commitdiff
fix #2525: encode notifications in UTF-8
authorStoiko Ivanov <s.ivanov@proxmox.com>
Mon, 24 Feb 2020 18:16:48 +0000 (19:16 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 3 Mar 2020 12:52:42 +0000 (13:52 +0100)
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 <s.ivanov@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PMG/RuleDB/Notify.pm

index 860b5ce4e5f23041e704273de1294cb2c302014b..ec18a7e5eafc7669b18c0e6db24d8fb9c4893c4f 100644 (file)
@@ -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