From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id B9DAF1FF1BB for ; Wed, 24 Sep 2025 09:13:18 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id CCEBB1D755; Wed, 24 Sep 2025 09:13:49 +0200 (CEST) From: Hannes Laimer To: pmg-devel@lists.proxmox.com Date: Wed, 24 Sep 2025 09:13:13 +0200 Message-ID: <20250924071314.41917-2-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250924071314.41917-1-h.laimer@proxmox.com> References: <20250924071314.41917-1-h.laimer@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1758697983957 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.044 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [postfix.pm] Subject: [pmg-devel] [PATCH pmg-api v3 1/1] fix #3450: api: queue: add POST endpoint for batch deletion/delivery X-BeenThere: pmg-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Mail Gateway development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pmg-devel-bounces@lists.proxmox.com Sender: "pmg-devel" Delivery is done using `postqueue -i `, this is slower than using `postsuper -r -`. But `postsuper -r -` would only re-queue the mails, they'd also recieve new IDs. Flush should rather be an immediate delivery attempt. The flushing of 2000 mails took ~8s, since 2000 is the max amount possible through the UI this is ok I think. DELETE endpoints don't accept data, that is why we didn't extend the existing DELETE endpoint with an optional `ids` field. This is also how batch actions, including delete, are done for quarantine. Signed-off-by: Hannes Laimer --- src/PMG/API2/Postfix.pm | 40 ++++++++++++++++++++++++++++++++++++++++ src/PMG/Postfix.pm | 24 ++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/src/PMG/API2/Postfix.pm b/src/PMG/API2/Postfix.pm index ba0689c..a8f9995 100644 --- a/src/PMG/API2/Postfix.pm +++ b/src/PMG/API2/Postfix.pm @@ -335,6 +335,46 @@ __PACKAGE__->register_method({ }, }); +__PACKAGE__->register_method({ + name => 'queue_action', + path => 'queue/{queue}', + method => 'POST', + description => "Perform an action on the given queue IDs (delete/deliver).", + proxyto => 'node', + permissions => { check => ['admin'] }, + protected => 1, + parameters => { + additionalProperties => 0, + properties => { + node => get_standard_option('pve-node'), + queue => $queue_name_option, + action => { + description => 'Operation to perform on the given IDs.', + type => 'string', + enum => ['delete', 'deliver'], + }, + ids => { + description => 'Queue ID(s), separated by semicolons (;).', + type => 'string', + pattern => '[a-zA-Z0-9]{8,20}(;[a-zA-Z0-9]{8,20})*', + }, + }, + }, + returns => { type => 'null' }, + code => sub { + my ($param) = @_; + my @id_list = PVE::Tools::split_list($param->{ids}); + + if ($param->{action} eq 'delete') { + PMG::Postfix::delete_queue_ids($param->{queue}, \@id_list); + } elsif ($param->{action} eq 'deliver') { + PMG::Postfix::flush_queue_ids(\@id_list); + } + + return undef; + }, +}); + __PACKAGE__->register_method({ name => 'delete_queue', path => 'queue/{queue}', diff --git a/src/PMG/Postfix.pm b/src/PMG/Postfix.pm index 966130f..ca7ac40 100644 --- a/src/PMG/Postfix.pm +++ b/src/PMG/Postfix.pm @@ -221,6 +221,30 @@ sub delete_queue { PVE::Tools::run_command($cmd); } +# delete multiple mails by queue IDs +sub delete_queue_ids { + my ($queue, $ids) = @_; + + return if !$ids || ref($ids) ne 'ARRAY' || !@$ids; + + my $input = join("\n", @$ids) . "\n"; + my $cmd = ['/usr/sbin/postsuper', '-d', '-']; + push @$cmd, $queue if defined($queue); + + PVE::Tools::run_command($cmd, input => $input); +} + +# flush multiple mails by queue IDs +sub flush_queue_ids { + my ($ids) = @_; + + return if !$ids || ref($ids) ne 'ARRAY' || !@$ids; + + for my $qid (@$ids) { + PVE::Tools::run_command(['/usr/sbin/postqueue', '-i', $qid]); + } +} + sub discard_verify_cache { unlink "/var/lib/postfix/verify_cache.db"; -- 2.47.3 _______________________________________________ pmg-devel mailing list pmg-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel