[exim-cvs] Cmdine option for only IDs of queue

Top Page
Delete this message
Reply to this message
Author: Exim Git Commits Mailing List
Date:  
To: exim-cvs
Subject: [exim-cvs] Cmdine option for only IDs of queue
Gitweb: https://git.exim.org/exim.git/commitdiff/8ff2ba119ba654e9238f157f94bf10ed640ed877
Commit:     8ff2ba119ba654e9238f157f94bf10ed640ed877
Parent:     1d904e0470fed2e5c7a867f63d39ee44dbe80a2a
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Sun Mar 12 20:57:40 2023 +0000
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Sun Mar 12 20:57:40 2023 +0000


    Cmdine option for only IDs of queue
---
 doc/doc-docbook/spec.xfpt    |  9 +++++++++
 doc/doc-txt/NewStuff         |  2 ++
 src/src/exim.c               | 18 ++++++++++--------
 src/src/macros.h             |  7 +++++++
 src/src/queue.c              | 36 ++++++++++++++++++++----------------
 test/scripts/0000-Basic/0155 |  4 ++++
 test/stdout/0155             | 16 ++++++++++++++++
 7 files changed, 68 insertions(+), 24 deletions(-)


diff --git a/doc/doc-docbook/spec.xfpt b/doc/doc-docbook/spec.xfpt
index 8e2e1d142..0ba62ce5e 100644
--- a/doc/doc-docbook/spec.xfpt
+++ b/doc/doc-docbook/spec.xfpt
@@ -3272,6 +3272,12 @@ to the standard output. It is restricted to admin users, unless
&%queue_list_requires_admin%& is set false.


+.cmdopt -bpi
+.cindex queue "list of message IDs"
+This option operates like &%-bp%&, but only outputs message ids
+(one per line).
+
+
.cmdopt -bpr
This option operates like &%-bp%&, but the output is not sorted into
chronological order of message arrival. This can speed it up when there are
@@ -3281,6 +3287,9 @@ going to be post-processed in a way that doesn't need the sorting.
.cmdopt -bpra
This option is a combination of &%-bpr%& and &%-bpa%&.

+.cmdopt -bpri
+This option is a combination of &%-bpr%& and &%-bpi%&.
+
.cmdopt -bpru
This option is a combination of &%-bpr%& and &%-bpu%&.

diff --git a/doc/doc-txt/NewStuff b/doc/doc-txt/NewStuff
index ba204c040..d12246e03 100644
--- a/doc/doc-txt/NewStuff
+++ b/doc/doc-txt/NewStuff
@@ -27,6 +27,8 @@ Version 4.97

9. An expansion operator for wrapping long header lines.

+ 10. A commandline option to print just the message IDs of the queue
+
Version 4.96
------------

diff --git a/src/src/exim.c b/src/src/exim.c
index 8d13bd478..c16beb1af 100644
--- a/src/src/exim.c
+++ b/src/src/exim.c
@@ -1745,7 +1745,7 @@ int  filter_sfd = -1;
 int  filter_ufd = -1;
 int  group_count;
 int  i, rv;
-int  list_queue_option = 0;
+int  list_queue_option = QL_BASIC;
 int  msg_action = 0;
 int  msg_action_arg = -1;
 int  namelen = argv[0] ? Ustrlen(argv[0]) : 0;
@@ -2388,11 +2388,9 @@ on the second character (the one after '-'), to save some effort. */
         }


       if (*argrest == 'r')
-        {
-        list_queue_option = 8;
-        argrest++;
-        }
-      else list_queue_option = 0;
+        list_queue_option = QL_UNSORTED, argrest++;
+      else
+        list_queue_option = QL_BASIC;


       list_queue = TRUE;


@@ -2402,11 +2400,15 @@ on the second character (the one after '-'), to save some effort. */

       /* -bpu: List the contents of the mail queue, top-level undelivered */


-      else if (Ustrcmp(argrest, "u") == 0) list_queue_option += 1;
+      else if (Ustrcmp(argrest, "u") == 0) list_queue_option |= QL_UNDELIVERED_ONLY;


       /* -bpa: List the contents of the mail queue, including all delivered */


-      else if (Ustrcmp(argrest, "a") == 0) list_queue_option += 2;
+      else if (Ustrcmp(argrest, "a") == 0) list_queue_option |= QL_PLUS_GENERATED;
+
+      /* -bpi: List only message IDs */
+
+      else if (Ustrcmp(argrest, "i") == 0) list_queue_option |= QL_MSGID_ONLY;


       /* Unknown after -bp[r] */


diff --git a/src/src/macros.h b/src/src/macros.h
index 3b0293b97..9f3a7b06a 100644
--- a/src/src/macros.h
+++ b/src/src/macros.h
@@ -1140,4 +1140,11 @@ typedef unsigned mcs_flags;
 /* A big number for (effectively) unlimited envelope addresses */
 #define UNLIMITED_ADDRS        999999


+/* Flags for queue_list() */
+#define QL_BASIC        0
+#define QL_UNDELIVERED_ONLY    1
+#define QL_PLUS_GENERATED    2
+#define QL_MSGID_ONLY        3
+#define QL_UNSORTED        8
+
 /* End of macros.h */
diff --git a/src/src/queue.c b/src/src/queue.c
index d01cde655..b6e7907d7 100644
--- a/src/src/queue.c
+++ b/src/src/queue.c
@@ -913,7 +913,7 @@ Returns:      nothing
 */


void
-queue_list(int option, uschar **list, int count)
+queue_list(int option, uschar ** list, int count)
{
int subcount;
int now = (int)time(NULL);
@@ -942,21 +942,25 @@ if (count > 0)

 else
   qf = queue_get_spool_list(
-          -1,             /* entire queue */
-          subdirs,        /* for holding sub list */
-          &subcount,      /* for subcount */
-          option >= 8,      /* randomize if required */
-      NULL);      /* don't just count */
+          -1,                /* entire queue */
+          subdirs,            /* for holding sub list */
+          &subcount,            /* for subcount */
+          option >= QL_UNSORTED,    /* randomize if required */
+      NULL);            /* don't just count */


-if (option >= 8) option -= 8;
+option &= ~QL_UNSORTED;

/* Now scan the chain and print information, resetting store used
each time. */

-for (;
-    qf && (reset_point = store_mark());
-    spool_clear_header_globals(), store_reset(reset_point), qf = qf->next
-    )
+if (option == QL_MSGID_ONLY)    /* Print only the message IDs from the chain */
+  for (; qf; qf = qf->next)
+    fprintf(stdout, "%.*s\n", MESSAGE_ID_LENGTH, qf->text);
+
+else for (;
+      qf && (reset_point = store_mark());
+      spool_clear_header_globals(), store_reset(reset_point), qf = qf->next
+     )
   {
   int rc, save_errno;
   int size = 0;
@@ -1010,8 +1014,8 @@ for (;
       }
     }


-  fprintf(stdout, "%s ", string_format_size(size, big_buffer));
-  for (int i = 0; i < 16; i++) fputc(qf->text[i], stdout);
+  fprintf(stdout, "%s %.*s",
+    string_format_size(size, big_buffer), MESSAGE_ID_LENGTH, qf->text);


   if (env_read && sender_address)
     {
@@ -1048,14 +1052,14 @@ for (;
     {
     for (int i = 0; i < recipients_count; i++)
       {
-      tree_node *delivered =
+      tree_node * delivered =
         tree_search(tree_nonrecipients, recipients_list[i].address);
-      if (!delivered || option != 1)
+      if (!delivered || option != QL_UNDELIVERED_ONLY)
         printf("        %s %s\n",
       delivered ? "D" : " ", recipients_list[i].address);
       if (delivered) delivered->data.val = TRUE;
       }
-    if (option == 2 && tree_nonrecipients)
+    if (option == QL_PLUS_GENERATED && tree_nonrecipients)
       queue_list_extras(tree_nonrecipients);
     printf("\n");
     }
diff --git a/test/scripts/0000-Basic/0155 b/test/scripts/0000-Basic/0155
index 3cf45f8af..b221707f2 100644
--- a/test/scripts/0000-Basic/0155
+++ b/test/scripts/0000-Basic/0155
@@ -28,8 +28,12 @@ exim -odq i@???
 millisleep 500
 exim -odq j@???
 ****
+### exim -bp
 exim -bp
 ****
+### exim -bpi
+exim -bpi
+****
 exim -q
 ****
 no_msglog_check
diff --git a/test/stdout/0155 b/test/stdout/0155
index 272078b57..3ec38cf41 100644
--- a/test/stdout/0155
+++ b/test/stdout/0155
@@ -1,3 +1,4 @@
+### exim -bp
  0m   sss 10HmaX-0005vi-00 <CALLER@???>
           a@???


@@ -28,3 +29,18 @@
  0m   sss 10HmbG-0005vi-00 <CALLER@???>
           j@???


+### exim -bpi
+10HmaX-0005vi-00
+10HmaY-0005vi-00
+10HmaZ-0005vi-00
+10HmbA-0005vi-00
+10HmbB-0005vi-00
+10HmbC-0005vi-00
+10HmbD-0005vi-00
+10HmbE-0005vi-00
+10HmbF-0005vi-00
+10HmbG-0005vi-00
+
+******** SERVER ********
+### exim -bp
+### exim -bpi