[pmg-devel] [PATCH pmg-api] allow multiple ids for one action

Dominik Csapak d.csapak at proxmox.com
Wed Mar 28 10:26:33 CEST 2018


so that we can easily do an action for multiple e-mails simultaniously

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
best viewed with '-w' to ignore whitespace,
since the indentation changed
 PMG/API2/Quarantine.pm | 55 ++++++++++++++++++++++++++------------------------
 1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/PMG/API2/Quarantine.pm b/PMG/API2/Quarantine.pm
index 2863874..f4bc32c 100644
--- a/PMG/API2/Quarantine.pm
+++ b/PMG/API2/Quarantine.pm
@@ -892,10 +892,10 @@ __PACKAGE__->register_method ({
 	additionalProperties => 0,
 	properties => {
 	    id => {
-		description => 'Unique ID',
+		description => 'Unique IDs, seperate with ;',
 		type => 'string',
-		pattern => 'C\d+R\d+T\d+',
-		maxLength => 60,
+		pattern => 'C\d+R\d+T\d+(;C\d+R\d+T\d+)*',
+		maxLength => 600,
 	    },
 	    action => {
 		description => 'Action - specify what you want to do with the mail.',
@@ -912,34 +912,37 @@ __PACKAGE__->register_method ({
 	my $authuser = $rpcenv->get_user();
 	my $role = $rpcenv->get_role();
 	my $action = $param->{action};
+	my @idlist = split(';', $param->{id});
 
-	my ($cid, $rid, $tid) = $param->{id} =~ m/^C(\d+)R(\d+)T(\d+)$/;
-	$cid = int($cid);
-	$rid = int($rid);
-	$tid = int($tid);
+	for my $id (@idlist) {
+	    my ($cid, $rid, $tid) = $id =~ m/^C(\d+)R(\d+)T(\d+)$/;
+	    $cid = int($cid);
+	    $rid = int($rid);
+	    $tid = int($tid);
 
-	my $dbh = PMG::DBTools::open_ruledb();
+	    my $dbh = PMG::DBTools::open_ruledb();
 
-	my $ref = PMG::DBTools::load_mail_data($dbh, $cid, $rid, $tid);
+	    my $ref = PMG::DBTools::load_mail_data($dbh, $cid, $rid, $tid);
 
-	if ($role eq 'quser') {
-	    my $quar_username = $ref->{pmail} . '@quarantine';
-	    raise_perm_exc("mail does not belong to user '$authuser' ($ref->{pmail})")
+	    if ($role eq 'quser') {
+		my $quar_username = $ref->{pmail} . '@quarantine';
+		raise_perm_exc("mail does not belong to user '$authuser' ($ref->{pmail})")
 		if $authuser ne $quar_username;
-	}
-
-	my $sender = $get_real_sender->($ref);
-
-	if ($action eq 'whitelist') {
-	    PMG::Quarantine::add_to_blackwhite($dbh, $ref->{pmail}, 'WL', [ $sender ]);
-	} elsif ($action eq 'blacklist') {
-	    PMG::Quarantine::add_to_blackwhite($dbh, $ref->{pmail}, 'BL', [ $sender ]);
-	} elsif ($action eq 'deliver') {
-	    PMG::Quarantine::deliver_quarantined_mail($dbh, $ref, $ref->{receiver} // $ref->{pmail});
-	} elsif ($action eq 'delete') {
-	    PMG::Quarantine::delete_quarantined_mail($dbh, $ref);
-	} else {
-	    die "internal error"; # should not be reached
+	    }
+
+	    my $sender = $get_real_sender->($ref);
+
+	    if ($action eq 'whitelist') {
+		PMG::Quarantine::add_to_blackwhite($dbh, $ref->{pmail}, 'WL', [ $sender ]);
+	    } elsif ($action eq 'blacklist') {
+		PMG::Quarantine::add_to_blackwhite($dbh, $ref->{pmail}, 'BL', [ $sender ]);
+	    } elsif ($action eq 'deliver') {
+		PMG::Quarantine::deliver_quarantined_mail($dbh, $ref, $ref->{receiver} // $ref->{pmail});
+	    } elsif ($action eq 'delete') {
+		PMG::Quarantine::delete_quarantined_mail($dbh, $ref);
+	    } else {
+		die "internal error"; # should not be reached
+	    }
 	}
 
 	return undef;
-- 
2.11.0




More information about the pmg-devel mailing list