]> granicus.if.org Git - mutt/commitdiff
Add a %e option for thread-relative message numbers. From Markus
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 9 May 2000 15:51:54 +0000 (15:51 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 9 May 2000 15:51:54 +0000 (15:51 +0000)
Holmberg <markush@acc.umu.se>.

hdrline.c
init.h
protos.h
thread.c

index 9ace2ca655d3becb5995908eb6581b40c90139bf..50e635a4a0c1de2347b05e9a17bdd36b9c512f81 100644 (file)
--- 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 0ce81a474da3d2067c6f848c0cb58c52d42741ff..4ef6e5d7c03cd649769105e4d4c5ed21407e83ab 100644 (file)
--- 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
index e03c232646068cf5ce6d8e2cf455b6b69b382056..84287d872ae7bcfc4b135536798e2c32d42ec123 100644 (file)
--- 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);
index 34af7446ed983a9807c4e61a7a765261d2cb8441..37929a368bf0ff46266973aba417b5e391198c3d 100644 (file)
--- 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 */
+}