From 8ff2ba119ba654e9238f157f94bf10ed640ed877 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Sun, 12 Mar 2023 20:57:40 +0000 Subject: Cmdine option for only IDs of queue --- src/src/exim.c | 18 ++++++++++-------- src/src/macros.h | 7 +++++++ src/src/queue.c | 36 ++++++++++++++++++++---------------- 3 files changed, 37 insertions(+), 24 deletions(-) (limited to 'src') 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"); } -- cgit v1.2.1