all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pmg-devel] [PATCH pmg-api/pmg-gui 0/2] add support to delete multiple queue entries at once
@ 2025-09-19 14:50 Hannes Laimer
  2025-09-19 14:50 ` [pmg-devel] [PATCH pmg-api 1/1] fix #3450: api: add 'filter' parameter to queue DELETE endpoint Hannes Laimer
  2025-09-19 14:50 ` [pmg-devel] [PATCH pmg-gui 1/1] fix #3450: ui: add button to delete all queue entries matching a filter Hannes Laimer
  0 siblings, 2 replies; 8+ messages in thread
From: Hannes Laimer @ 2025-09-19 14:50 UTC (permalink / raw)
  To: pmg-devel

This fixes #3450 by adding a 'filter' parameter to the queue DELETE
endpoint. This filter matches for both for recipient and sender.

https://bugzilla.proxmox.com/show_bug.cgi?id=3450

pmg-api:

Hannes Laimer (1):
  fix #3450: api: add 'filter' parameter to queue DELETE endpoint

 src/PMG/API2/Postfix.pm | 14 ++++++++++++--
 src/PMG/Postfix.pm      | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 2 deletions(-)


pmg-gui:

Hannes Laimer (1):
  fix #3450: ui: add button to delete all queue entries matching a
    filter

 js/PostfixMailQueue.js | 46 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)


Summary over all repositories:
  3 files changed, 98 insertions(+), 2 deletions(-)

-- 
Generated by git-murpp 0.8.1


_______________________________________________
pmg-devel mailing list
pmg-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pmg-devel] [PATCH pmg-api 1/1] fix #3450: api: add 'filter' parameter to queue DELETE endpoint
  2025-09-19 14:50 [pmg-devel] [PATCH pmg-api/pmg-gui 0/2] add support to delete multiple queue entries at once Hannes Laimer
@ 2025-09-19 14:50 ` Hannes Laimer
  2025-09-22  8:58   ` Dominik Csapak
  2025-09-22  9:19   ` Thomas Lamprecht
  2025-09-19 14:50 ` [pmg-devel] [PATCH pmg-gui 1/1] fix #3450: ui: add button to delete all queue entries matching a filter Hannes Laimer
  1 sibling, 2 replies; 8+ messages in thread
From: Hannes Laimer @ 2025-09-19 14:50 UTC (permalink / raw)
  To: pmg-devel

This allows to delete all mails in the queue which have a
sender/recipient that matches the passed filter.

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
 src/PMG/API2/Postfix.pm | 14 ++++++++++++--
 src/PMG/Postfix.pm      | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/src/PMG/API2/Postfix.pm b/src/PMG/API2/Postfix.pm
index ba0689c..31f7449 100644
--- a/src/PMG/API2/Postfix.pm
+++ b/src/PMG/API2/Postfix.pm
@@ -339,7 +339,7 @@ __PACKAGE__->register_method({
     name => 'delete_queue',
     path => 'queue/{queue}',
     method => 'DELETE',
-    description => "Delete all mails in the queue.",
+    description => "Delete all mails in the queue, or only those matching an optional filter.",
     proxyto => 'node',
     permissions => { check => ['admin'] },
     protected => 1,
@@ -348,13 +348,23 @@ __PACKAGE__->register_method({
         properties => {
             node => get_standard_option('pve-node'),
             queue => $queue_name_option,
+            filter => {
+                description => "Filter string (matches sender and recipients).",
+                type => 'string',
+                maxLength => 64,
+                optional => 1,
+            },
         },
     },
     returns => { type => 'null' },
     code => sub {
         my ($param) = @_;
 
-        PMG::Postfix::delete_queue($param->{queue});
+        if (defined($param->{filter}) && $param->{filter} ne '') {
+            PMG::Postfix::delete_queue_filtered($param->{queue}, $param->{filter});
+        } else {
+            PMG::Postfix::delete_queue($param->{queue});
+        }
 
         return undef;
     },
diff --git a/src/PMG/Postfix.pm b/src/PMG/Postfix.pm
index 966130f..7c7869e 100644
--- a/src/PMG/Postfix.pm
+++ b/src/PMG/Postfix.pm
@@ -221,6 +221,46 @@ sub delete_queue {
     PVE::Tools::run_command($cmd);
 }
 
+# delete mails in a queue matching a sender/recipient filter
+sub delete_queue_filtered {
+    my ($queue, $filter) = @_;
+
+    die "no filter specified\n" if !defined($filter) || $filter eq '';
+
+    open(my $fh, '-|', '/usr/sbin/postqueue', '-j') || die "ERROR: unable to run postqueue - $!\n";
+
+    my %seen;
+    my @queue_ids;
+    my $line;
+    while (defined($line = <$fh>)) {
+        my $rec = decode_json($line);
+        next if $rec->{queue_name} ne $queue;
+
+        my $match = 0;
+        my $sender = $rec->{sender} // '';
+        if ($sender =~ m/$filter/i) {
+            $match = 1;
+        } else {
+            my $recipients = $rec->{recipients} // [];
+            foreach my $entry (@$recipients) {
+                if (($entry->{address} // '') =~ m/$filter/i) { $match = 1; last; }
+            }
+        }
+
+        next if !$match;
+
+        my $qid = $rec->{queue_id};
+        next if !$qid || $seen{$qid}++;
+        push @queue_ids, $qid;
+    }
+
+    return if !@queue_ids;
+
+    my $input = join("\n", @queue_ids) . "\n";
+    my $cmd = ['/usr/sbin/postsuper', '-d', '-', $queue];
+    PVE::Tools::run_command($cmd, input => $input);
+}
+
 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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [pmg-devel] [PATCH pmg-gui 1/1] fix #3450: ui: add button to delete all queue entries matching a filter
  2025-09-19 14:50 [pmg-devel] [PATCH pmg-api/pmg-gui 0/2] add support to delete multiple queue entries at once Hannes Laimer
  2025-09-19 14:50 ` [pmg-devel] [PATCH pmg-api 1/1] fix #3450: api: add 'filter' parameter to queue DELETE endpoint Hannes Laimer
@ 2025-09-19 14:50 ` Hannes Laimer
  1 sibling, 0 replies; 8+ messages in thread
From: Hannes Laimer @ 2025-09-19 14:50 UTC (permalink / raw)
  To: pmg-devel

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
 js/PostfixMailQueue.js | 46 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/js/PostfixMailQueue.js b/js/PostfixMailQueue.js
index 17c7d05..f51fb40 100644
--- a/js/PostfixMailQueue.js
+++ b/js/PostfixMailQueue.js
@@ -112,6 +112,45 @@ Ext.define('PMG.Postfix.MailQueue', {
             win.show();
         },
 
+        onDeleteFilter: function (button, event, rec) {
+            let view = this.getView();
+            let filter = view.lookupReference('filter').getValue();
+
+            if (!filter) {
+                Ext.Msg.alert(gettext('Error'), gettext('Please enter a filter first.'));
+                return;
+            }
+
+            Ext.Msg.show({
+                title: gettext('Confirm'),
+                message: Ext.String.format(
+                    gettext('Delete all mails in {0} queue matching filter: \'{1}\'?'),
+                    view.queuename,
+                    Ext.htmlEncode(filter)
+                ),
+                buttons: Ext.Msg.YESNO,
+                icon: Ext.Msg.WARNING,
+                fn: function (btn) {
+                    if (btn !== 'yes') { return; }
+                    let url =
+                        '/api2/extjs/nodes/' +
+                        view.nodename +
+                        '/postfix/queue/' +
+                        view.queuename +
+                        '?filter=' + encodeURIComponent(filter);
+                    Proxmox.Utils.API2Request({
+                        url: url,
+                        method: 'DELETE',
+                        waitMsgTarget: view,
+                        success: function () { view.store.load(); },
+                        failure: function (response) {
+                            Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+                        },
+                    });
+                },
+            });
+        },
+
         control: {
             '#': {
                 activate: function () {
@@ -144,6 +183,13 @@ Ext.define('PMG.Postfix.MailQueue', {
             xtype: 'proxmoxStdRemoveButton',
             handler: 'onRemove',
         },
+        '-',
+        {
+            xtype: 'proxmoxButton',
+            text: gettext('Delete Matching Filter'),
+            selModel: null,
+            handler: 'onDeleteFilter',
+        },
         {
             xtype: 'label',
             html: gettext('Filter') + ':',
-- 
2.47.3



_______________________________________________
pmg-devel mailing list
pmg-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [pmg-devel] [PATCH pmg-api 1/1] fix #3450: api: add 'filter' parameter to queue DELETE endpoint
  2025-09-19 14:50 ` [pmg-devel] [PATCH pmg-api 1/1] fix #3450: api: add 'filter' parameter to queue DELETE endpoint Hannes Laimer
@ 2025-09-22  8:58   ` Dominik Csapak
  2025-09-22  9:18     ` Thomas Lamprecht
  2025-09-22  9:19   ` Thomas Lamprecht
  1 sibling, 1 reply; 8+ messages in thread
From: Dominik Csapak @ 2025-09-22  8:58 UTC (permalink / raw)
  To: Hannes Laimer, pmg-devel

one high level comment and a few comments inline

i get what you want to achieve here and this is what stoiko wrote in the
bugreport, but from an UX perspective this could be bad. Since the
mails shown on the gui might not match what will be deleted (e.g. new 
mails came in, in the meantime)

would it maybe make more sense to have an approach with giving a list
of ids to the backend? (@stoiko ?)

On 9/19/25 4:51 PM, Hannes Laimer wrote:
> This allows to delete all mails in the queue which have a
> sender/recipient that matches the passed filter.
> 
> Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
> ---
>   src/PMG/API2/Postfix.pm | 14 ++++++++++++--
>   src/PMG/Postfix.pm      | 40 ++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 52 insertions(+), 2 deletions(-)
> 
> diff --git a/src/PMG/API2/Postfix.pm b/src/PMG/API2/Postfix.pm
> index ba0689c..31f7449 100644
> --- a/src/PMG/API2/Postfix.pm
> +++ b/src/PMG/API2/Postfix.pm
> @@ -339,7 +339,7 @@ __PACKAGE__->register_method({
>       name => 'delete_queue',
>       path => 'queue/{queue}',
>       method => 'DELETE',
> -    description => "Delete all mails in the queue.",
> +    description => "Delete all mails in the queue, or only those matching an optional filter.",
>       proxyto => 'node',
>       permissions => { check => ['admin'] },
>       protected => 1,
> @@ -348,13 +348,23 @@ __PACKAGE__->register_method({
>           properties => {
>               node => get_standard_option('pve-node'),
>               queue => $queue_name_option,
> +            filter => {
> +                description => "Filter string (matches sender and recipients).",
> +                type => 'string',
> +                maxLength => 64,
> +                optional => 1,
> +            },
>           },
>       },
>       returns => { type => 'null' },
>       code => sub {
>           my ($param) = @_;
>   
> -        PMG::Postfix::delete_queue($param->{queue});
> +        if (defined($param->{filter}) && $param->{filter} ne '') {
> +            PMG::Postfix::delete_queue_filtered($param->{queue}, $param->{filter});
> +        } else {
> +            PMG::Postfix::delete_queue($param->{queue});
> +        }
>   
>           return undef;
>       },
> diff --git a/src/PMG/Postfix.pm b/src/PMG/Postfix.pm
> index 966130f..7c7869e 100644
> --- a/src/PMG/Postfix.pm
> +++ b/src/PMG/Postfix.pm
> @@ -221,6 +221,46 @@ sub delete_queue {
>       PVE::Tools::run_command($cmd);
>   }
>   
> +# delete mails in a queue matching a sender/recipient filter
> +sub delete_queue_filtered {
> +    my ($queue, $filter) = @_;
> +
> +    die "no filter specified\n" if !defined($filter) || $filter eq '';
> +
> +    open(my $fh, '-|', '/usr/sbin/postqueue', '-j') || die "ERROR: unable to run postqueue - $!\n";
> +
> +    my %seen;
> +    my @queue_ids;
> +    my $line;
> +    while (defined($line = <$fh>)) {
> +        my $rec = decode_json($line);
> +        next if $rec->{queue_name} ne $queue;
> +
> +        my $match = 0;
> +        my $sender = $rec->{sender} // '';
> +        if ($sender =~ m/$filter/i) {

if we accept any characters in the api, we must escape the regex string 
here, otherwise e.g. the filter '.' matches every thing with at least
one character, not only those things with one dot.

(same would actually go for the listing itself, alternatively we could
document it as a 'regex' string? )


> +            $match = 1;
> +        } else {
> +            my $recipients = $rec->{recipients} // [];
> +            foreach my $entry (@$recipients) {
> +                if (($entry->{address} // '') =~ m/$filter/i) { $match = 1; last; }

same here

> +            }
> +        }
> +
> +        next if !$match;
> +
> +        my $qid = $rec->{queue_id};
> +        next if !$qid || $seen{$qid}++;
> +        push @queue_ids, $qid;
> +    }
> +
> +    return if !@queue_ids;
> +
> +    my $input = join("\n", @queue_ids) . "\n";
> +    my $cmd = ['/usr/sbin/postsuper', '-d', '-', $queue];
> +    PVE::Tools::run_command($cmd, input => $input);
> +}
> +
>   sub discard_verify_cache {
>       unlink "/var/lib/postfix/verify_cache.db";
>   



_______________________________________________
pmg-devel mailing list
pmg-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [pmg-devel] [PATCH pmg-api 1/1] fix #3450: api: add 'filter' parameter to queue DELETE endpoint
  2025-09-22  8:58   ` Dominik Csapak
@ 2025-09-22  9:18     ` Thomas Lamprecht
  2025-09-22 10:09       ` Stoiko Ivanov
  0 siblings, 1 reply; 8+ messages in thread
From: Thomas Lamprecht @ 2025-09-22  9:18 UTC (permalink / raw)
  To: Dominik Csapak, Hannes Laimer, pmg-devel

Am 22.09.25 um 10:58 schrieb Dominik Csapak:
> one high level comment and a few comments inline
> 
> i get what you want to achieve here and this is what stoiko wrote in the
> bugreport, but from an UX perspective this could be bad. Since the
> mails shown on the gui might not match what will be deleted (e.g. new mails came in, in the meantime)
> 
> would it maybe make more sense to have an approach with giving a list
> of ids to the backend? (@stoiko ?)

That would be safer, as long as it can also handle at least 1k of mails
being processed I'd be fine with that.

An alternative could be passing a cutoff timestamp from the newest mail
selected along, but an explicit list naturally is slightly simpler to
handle and to debug, so mostly just mentioning it for the sake of
completeness.


_______________________________________________
pmg-devel mailing list
pmg-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [pmg-devel] [PATCH pmg-api 1/1] fix #3450: api: add 'filter' parameter to queue DELETE endpoint
  2025-09-19 14:50 ` [pmg-devel] [PATCH pmg-api 1/1] fix #3450: api: add 'filter' parameter to queue DELETE endpoint Hannes Laimer
  2025-09-22  8:58   ` Dominik Csapak
@ 2025-09-22  9:19   ` Thomas Lamprecht
  1 sibling, 0 replies; 8+ messages in thread
From: Thomas Lamprecht @ 2025-09-22  9:19 UTC (permalink / raw)
  To: Hannes Laimer, pmg-devel

Am 19.09.25 um 16:51 schrieb Hannes Laimer:
> This allows to delete all mails in the queue which have a
> sender/recipient that matches the passed filter.

high-level: would then be naturally also nice to have for
delivering a (filtered) list of mails, or does anything speak
against that?


_______________________________________________
pmg-devel mailing list
pmg-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [pmg-devel] [PATCH pmg-api 1/1] fix #3450: api: add 'filter' parameter to queue DELETE endpoint
  2025-09-22  9:18     ` Thomas Lamprecht
@ 2025-09-22 10:09       ` Stoiko Ivanov
  2025-09-22 10:15         ` Hannes Laimer
  0 siblings, 1 reply; 8+ messages in thread
From: Stoiko Ivanov @ 2025-09-22 10:09 UTC (permalink / raw)
  To: Thomas Lamprecht; +Cc: pmg-devel

Thanks for the patches, reviews and suggestions!


On Mon, 22 Sep 2025 11:18:10 +0200
Thomas Lamprecht <t.lamprecht@proxmox.com> wrote:

> Am 22.09.25 um 10:58 schrieb Dominik Csapak:
> > one high level comment and a few comments inline
> > 
> > i get what you want to achieve here and this is what stoiko wrote in the
> > bugreport, but from an UX perspective this could be bad. Since the
> > mails shown on the gui might not match what will be deleted (e.g. new mails came in, in the meantime)
> > 
> > would it maybe make more sense to have an approach with giving a list
> > of ids to the backend? (@stoiko ?)  
> 
> That would be safer, as long as it can also handle at least 1k of mails
> being processed I'd be fine with that.
> 
> An alternative could be passing a cutoff timestamp from the newest mail
> selected along, but an explicit list naturally is slightly simpler to
> handle and to debug, so mostly just mentioning it for the sake of
> completeness.
looked at bugreport and the Queue GUI again - I think my idea back then
was:
* we already have a filter in the Deferred Mail panel
* adding a checkbox for selection of multiple mails + one for all mail
  (that is displayed after the filter) and Removing the selected ones
  should help most users who need to clear up a queue most.
AFICT - sending a list to the backend seems a sensible way to achieve that.


> high-level: would then be naturally also nice to have for
> delivering a (filtered) list of mails, or does anything speak
> against that?

That seems a worth-while addition as well!





_______________________________________________
pmg-devel mailing list
pmg-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [pmg-devel] [PATCH pmg-api 1/1] fix #3450: api: add 'filter' parameter to queue DELETE endpoint
  2025-09-22 10:09       ` Stoiko Ivanov
@ 2025-09-22 10:15         ` Hannes Laimer
  0 siblings, 0 replies; 8+ messages in thread
From: Hannes Laimer @ 2025-09-22 10:15 UTC (permalink / raw)
  To: Stoiko Ivanov, Thomas Lamprecht; +Cc: pmg-devel



On 22.09.25 12:09, Stoiko Ivanov wrote:
> Thanks for the patches, reviews and suggestions!
> 
> 
> On Mon, 22 Sep 2025 11:18:10 +0200
> Thomas Lamprecht <t.lamprecht@proxmox.com> wrote:
> 
>> Am 22.09.25 um 10:58 schrieb Dominik Csapak:
>>> one high level comment and a few comments inline
>>>
>>> i get what you want to achieve here and this is what stoiko wrote in the
>>> bugreport, but from an UX perspective this could be bad. Since the
>>> mails shown on the gui might not match what will be deleted (e.g. new mails came in, in the meantime)
>>>
>>> would it maybe make more sense to have an approach with giving a list
>>> of ids to the backend? (@stoiko ?)
>>
>> That would be safer, as long as it can also handle at least 1k of mails
>> being processed I'd be fine with that.
>>
>> An alternative could be passing a cutoff timestamp from the newest mail
>> selected along, but an explicit list naturally is slightly simpler to
>> handle and to debug, so mostly just mentioning it for the sake of
>> completeness.
> looked at bugreport and the Queue GUI again - I think my idea back then
> was:
> * we already have a filter in the Deferred Mail panel
> * adding a checkbox for selection of multiple mails + one for all mail
>    (that is displayed after the filter) and Removing the selected ones
>    should help most users who need to clear up a queue most.
> AFICT - sending a list to the backend seems a sensible way to achieve that.
> 

yes

so the "all" would be for the paginated list, right? I am not sure if
having 10-20+ pages worth of mail is realistic here

> 
>> high-level: would then be naturally also nice to have for
>> delivering a (filtered) list of mails, or does anything speak
>> against that?
> 
> That seems a worth-while addition as well!
> 
> 
> 



_______________________________________________
pmg-devel mailing list
pmg-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-09-22 10:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-19 14:50 [pmg-devel] [PATCH pmg-api/pmg-gui 0/2] add support to delete multiple queue entries at once Hannes Laimer
2025-09-19 14:50 ` [pmg-devel] [PATCH pmg-api 1/1] fix #3450: api: add 'filter' parameter to queue DELETE endpoint Hannes Laimer
2025-09-22  8:58   ` Dominik Csapak
2025-09-22  9:18     ` Thomas Lamprecht
2025-09-22 10:09       ` Stoiko Ivanov
2025-09-22 10:15         ` Hannes Laimer
2025-09-22  9:19   ` Thomas Lamprecht
2025-09-19 14:50 ` [pmg-devel] [PATCH pmg-gui 1/1] fix #3450: ui: add button to delete all queue entries matching a filter Hannes Laimer

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