all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api v3 1/1] fix #3450: api: queue: add POST endpoint for batch deletion/delivery
Date: Wed, 24 Sep 2025 09:13:13 +0200	[thread overview]
Message-ID: <20250924071314.41917-2-h.laimer@proxmox.com> (raw)
In-Reply-To: <20250924071314.41917-1-h.laimer@proxmox.com>

Delivery is done using `postqueue -i <id>`, 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 <h.laimer@proxmox.com>
---
 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


  reply	other threads:[~2025-09-24  7:13 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-24  7:13 [pmg-devel] [PATCH pmg-api/pmg-gui v3 0/2] fix #3450: batch deletion/delivery for postfix queue Hannes Laimer
2025-09-24  7:13 ` Hannes Laimer [this message]
2025-09-24  7:13 ` [pmg-devel] [PATCH pmg-gui v3 1/1] fix #3450: ui: queue: multi-select for item deletion/delivery Hannes Laimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250924071314.41917-2-h.laimer@proxmox.com \
    --to=h.laimer@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal