]> granicus.if.org Git - mutt/commitdiff
Fix mutt_messages_in_thread(). From Daniel Eisenbud.
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 19 Nov 2001 10:37:38 +0000 (10:37 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 19 Nov 2001 10:37:38 +0000 (10:37 +0000)
(patch-1.3.23.2-de-new_threads.2-3.gz).

hdrline.c
protos.h
thread.c

index 54fae0fed0d6fb70e05cb84f256005bf3cc53824..1dcbe28914402d9974a20141f997c598c17dea4d 100644 (file)
--- a/hdrline.c
+++ b/hdrline.c
@@ -411,12 +411,12 @@ hdr_format_str (char *dest,
 
     case 'e':
       snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
-      snprintf (dest, destlen, fmt, mutt_messages_in_thread(hdr, 1));
+      snprintf (dest, destlen, fmt, mutt_messages_in_thread(ctx, hdr, 1));
       break;
 
     case 'E':
       snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
-      snprintf (dest, destlen, fmt, mutt_messages_in_thread(hdr, 0));
+      snprintf (dest, destlen, fmt, mutt_messages_in_thread(ctx, hdr, 0));
       break;
 
     case 'f':
index 361dc82b9a3c544f81b1ad07c1e81ed71c7dfbd7..9b7762de9dd0fe19877749cdc9e725546c1b379b 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -287,7 +287,7 @@ 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);
+int mutt_messages_in_thread (CONTEXT *, HEADER *, int);
 int mutt_multi_choice (char *prompt, char *letters);
 int mutt_needs_mailcap (BODY *);
 int mutt_num_postponed (int);
index f0392853d72cc9a5101a1e9a62d5d2227af490bc..1f48ef70a05eb73d009792f0a3bdcc1454532082 100644 (file)
--- a/thread.c
+++ b/thread.c
@@ -1156,10 +1156,10 @@ int _mutt_traverse_thread (CONTEXT *ctx, HEADER *cur, int flag)
 /* if flag is 0, we want to know how many messages
  * are in the thread.  if flag is 1, we want to know
  * our position in the thread. */
-int mutt_messages_in_thread (HEADER *hdr, int flag)
+int mutt_messages_in_thread (CONTEXT *ctx, HEADER *hdr, int flag)
 {
   THREAD *threads[2];
-  int i;
+  int i, rc;
 
   if ((Sort & SORT_MASK) != SORT_THREADS)
     return (1);
@@ -1167,24 +1167,27 @@ int mutt_messages_in_thread (HEADER *hdr, int flag)
   threads[0] = hdr->thread;
   while (threads[0]->parent)
     threads[0] = threads[0]->parent;
-  while (threads[0]->prev)
-    threads[0] = threads[0]->prev;
 
-  if (flag)
-    threads[1] = hdr->thread;
-  else
-    threads[1] = threads[0]->next;
+  threads[1] = flag ? hdr->thread : threads[0]->next;
 
-  for (i = 0; i < flag ? 1 : 2; i++)
+  for (i = 0; i < ((flag || !threads[1]) ? 1 : 2); i++)
   {
     while (!threads[i]->message)
       threads[i] = threads[i]->child;
   } 
 
-  return (((Sort & SORT_REVERSE ? -1 : 1)
-          * threads[1]->message->msgno - threads[0]->message->msgno) + (flag ? 1 : 0));
+  if (Sort & SORT_REVERSE)
+    rc = threads[0]->message->msgno - (threads[1] ? threads[1]->message->msgno : -1);
+  else
+    rc = (threads[1] ? threads[1]->message->msgno : ctx->msgcount) - threads[0]->message->msgno;
+  
+  if (flag)
+    rc += 1;
+  
+  return (rc);
 }
 
+
 HASH *mutt_make_id_hash (CONTEXT *ctx)
 {
   int i;