From 17be89b621d51feb5c3dd499e8b41ddc4a0df3ad Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Tue, 9 May 2000 15:51:54 +0000 Subject: [PATCH] Add a %e option for thread-relative message numbers. From Markus Holmberg . --- hdrline.c | 10 ++++++ init.h | 2 ++ protos.h | 2 ++ thread.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+) diff --git a/hdrline.c b/hdrline.c index 9ace2ca65..50e635a4a 100644 --- a/hdrline.c +++ b/hdrline.c @@ -432,6 +432,16 @@ hdr_format_str (char *dest, } break; + case 'e': + snprintf (fmt, sizeof (fmt), "%%%sd", prefix); + snprintf (dest, destlen, fmt, mutt_msgno_in_thread(hdr) + 1); + break; + + case 'E': + snprintf (fmt, sizeof (fmt), "%%%sd", prefix); + snprintf (dest, destlen, fmt, mutt_messages_in_thread(hdr)); + break; + case 'f': buf2[0] = 0; rfc822_write_address (buf2, sizeof (buf2), hdr->env->from); diff --git a/init.h b/init.h index 0ce81a474..4ef6e5d7c 100644 --- a/init.h +++ b/init.h @@ -783,6 +783,8 @@ struct option_t MuttVars[] = { ** %D date and time of the message in the format ** . specified by ``date_format'' converted to ** . the local time zone + ** %e current message number in thread + ** %E number of messages in current thread ** %f entire From: line (address + real name) ** %F author name, or recipient name if the ** . message is from you diff --git a/protos.h b/protos.h index e03c23264..84287d872 100644 --- a/protos.h +++ b/protos.h @@ -263,6 +263,8 @@ int mutt_is_list_recipient (int, ADDRESS *, ADDRESS *); int mutt_is_subscribed_list (ADDRESS *); int mutt_is_text_type (int, char *); int mutt_is_valid_mailbox (const char *); +int mutt_messages_in_thread (HEADER *); +int mutt_msgno_in_thread (HEADER *); int mutt_multi_choice (char *prompt, char *letters); int mutt_needs_mailcap (BODY *); int mutt_num_postponed (int); diff --git a/thread.c b/thread.c index 34af7446e..37929a368 100644 --- a/thread.c +++ b/thread.c @@ -888,3 +888,97 @@ int _mutt_traverse_thread (CONTEXT *ctx, HEADER *cur, int flag) #undef CHECK_LIMIT } +int mutt_messages_in_thread (HEADER *cur) +{ + HEADER *top; + int n = 1; + + if ((Sort & SORT_MASK) != SORT_THREADS) + { + mutt_error _("Threading is not enabled."); + return (-1); + } + + /* find top parent */ + while (cur->parent) + cur = cur->parent; + top = cur; + + /* return if there are no children at all */ + if ((cur = cur->child) == NULL) + return n; + + FOREVER + { + n++; + if (cur->child) + cur = cur->child; + else if (cur->next) + cur = cur->next; + else + { + while (!cur->next) + { + cur = cur->parent; + if (cur == top) + return n; + } + cur = cur->next; + } + } + /* not reached */ +} + +int mutt_msgno_in_thread (HEADER *cur) +{ + HEADER *top; + HEADER *target; + int n = 0; + + if ((Sort & SORT_MASK) != SORT_THREADS) + { + mutt_error _("Threading is not enabled."); + return (-1); + } + + /* save target */ + target = cur; + + /* find top parent */ + while (cur->parent) + cur = cur->parent; + top = cur; + + /* return if single message */ + if (top == target) + return n; + + /* return if there are no children at all */ + if ((cur = cur->child) == NULL) + return n; + + FOREVER + { + n++; + if (cur == target) + return n; + if (cur->child) + cur = cur->child; + else if (cur->next) + cur = cur->next; + else + { + while (!cur->next) + { + cur = cur->parent; + if (cur == top) + { + mutt_error _("Target message not found while counting messages in thread."); + return (-1); + } + } + cur = cur->next; + } + } + /* not reached */ +} -- 2.40.0