]> git.proxmox.com Git - pmg-api.git/commitdiff
api: quarantine: decode addresses before delivery/userlisting
authorStoiko Ivanov <s.ivanov@proxmox.com>
Fri, 17 Mar 2023 18:44:54 +0000 (19:44 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 23 Mar 2023 16:25:27 +0000 (17:25 +0100)
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 <d.csapak@proxomox.com>
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>
src/PMG/API2/Quarantine.pm

index 6318082b150adc99fc026d09e708f1ef1738daea..71017955f64cb0a0cd558cf29261261b6f31a93a 100644 (file)
@@ -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 {