From d616867d42e9a66b08833080018c4ce9da4bfd69 Mon Sep 17 00:00:00 2001 From: Stoiko Ivanov Date: Fri, 17 Mar 2023 19:44:54 +0100 Subject: [PATCH] api: quarantine: decode addresses before delivery/userlisting MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit With the change of using reinject_local_mail for the quarantine delivery the issue of not properly decoding the entries we get from the database before delivering became apparent The database returns utf-8 encoded strings, reinject_local_mail and add_to_blackwhite expects perl-strings (with wide characters) and encodes them (a second time) - this patch decodes the database strings before passing it on. add_to_black_white is used in a few API calls (via read_or_modify_user_bw_list), therefore the approach of decode (from database), and encode (for database) was chosen. Reported-by: Dominik Csapak Signed-off-by: Stoiko Ivanov Reviewed-by: Dominik Csapak Tested-by:  Dominik Csapak --- src/PMG/API2/Quarantine.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/PMG/API2/Quarantine.pm b/src/PMG/API2/Quarantine.pm index 6318082..7101795 100644 --- a/src/PMG/API2/Quarantine.pm +++ b/src/PMG/API2/Quarantine.pm @@ -1182,15 +1182,17 @@ __PACKAGE__->register_method ({ my $ref = $get_and_check_mail->($id, $rpcenv, $dbh); my $sender = try_decode_utf8($get_real_sender->($ref)); + my $pmail = try_decode_utf8($ref->{pmail}); + my $receiver = try_decode_utf8($ref->{receiver} // $ref->{pmail}); if ($action eq 'whitelist') { - PMG::Quarantine::add_to_blackwhite($dbh, $ref->{pmail}, 'WL', [ $sender ]); - PMG::Quarantine::deliver_quarantined_mail($dbh, $ref, $ref->{receiver} // $ref->{pmail}); + PMG::Quarantine::add_to_blackwhite($dbh, $pmail, 'WL', [ $sender ]); + PMG::Quarantine::deliver_quarantined_mail($dbh, $ref, $receiver); } elsif ($action eq 'blacklist') { - PMG::Quarantine::add_to_blackwhite($dbh, $ref->{pmail}, 'BL', [ $sender ]); + PMG::Quarantine::add_to_blackwhite($dbh, $pmail, 'BL', [ $sender ]); PMG::Quarantine::delete_quarantined_mail($dbh, $ref); } elsif ($action eq 'deliver') { - PMG::Quarantine::deliver_quarantined_mail($dbh, $ref, $ref->{receiver} // $ref->{pmail}); + PMG::Quarantine::deliver_quarantined_mail($dbh, $ref, $receiver); } elsif ($action eq 'delete') { PMG::Quarantine::delete_quarantined_mail($dbh, $ref); } else { -- 2.39.2