[pmg-devel] [PATCH pmg-api v4 09/12] quarantine: fix adding non-ascii senders to wl/bl

Dominik Csapak d.csapak at proxmox.com
Thu Nov 24 13:21:09 CET 2022


by trying to decode them since they maybe were sent with SMTPUTF8
also make 'try_decode_utf8' an export of Utils and use that

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/PMG/API2/Quarantine.pm | 8 ++++----
 src/PMG/Utils.pm           | 1 +
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/PMG/API2/Quarantine.pm b/src/PMG/API2/Quarantine.pm
index 819c78c..f9e3e3d 100644
--- a/src/PMG/API2/Quarantine.pm
+++ b/src/PMG/API2/Quarantine.pm
@@ -24,7 +24,7 @@ use PVE::RESTHandler;
 use PVE::INotify;
 use PVE::APIServer::Formatter;
 
-use PMG::Utils;
+use PMG::Utils qw(try_decode_utf8);
 use PMG::AccessControl;
 use PMG::Config;
 use PMG::DBTools;
@@ -141,8 +141,8 @@ my $parse_header_info = sub {
     my $sender = PMG::Utils::decode_rfc1522(PVE::Tools::trim($head->get('sender')));
     $res->{sender} = $sender if $sender && ($sender ne $res->{from});
 
-    $res->{envelope_sender} = PMG::Utils::try_decode_utf8($ref->{sender});
-    $res->{receiver} = PMG::Utils::try_decode_utf8($ref->{receiver} // $ref->{pmail});
+    $res->{envelope_sender} = try_decode_utf8($ref->{sender});
+    $res->{receiver} = try_decode_utf8($ref->{receiver} // $ref->{pmail});
     $res->{id} = 'C' . $ref->{cid} . 'R' . $ref->{rid} . 'T' . $ref->{ticketid};
     $res->{time} = $ref->{time};
     $res->{bytes} = $ref->{bytes};
@@ -1164,7 +1164,7 @@ __PACKAGE__->register_method ({
 	for my $id (@idlist) {
 
 	    my $ref = $get_and_check_mail->($id, $rpcenv, $dbh);
-	    my $sender = $get_real_sender->($ref);
+	    my $sender = try_decode_utf8($get_real_sender->($ref));
 
 	    if ($action eq 'whitelist') {
 		PMG::Quarantine::add_to_blackwhite($dbh, $ref->{pmail}, 'WL', [ $sender ]);
diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm
index 5c9e873..463de6d 100644
--- a/src/PMG/Utils.pm
+++ b/src/PMG/Utils.pm
@@ -45,6 +45,7 @@ use base 'Exporter';
 
 our @EXPORT_OK = qw(
 postgres_admin_cmd
+try_decode_utf8
 );
 
 my $valid_pmg_realms = ['pam', 'pmg', 'quarantine'];
-- 
2.30.2





More information about the pmg-devel mailing list