]> granicus.if.org Git - neomutt/commitdiff
Detect thread loops.
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 16 Mar 1999 21:41:50 +0000 (21:41 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 16 Mar 1999 21:41:50 +0000 (21:41 +0000)
thread.c

index 33aeae71f1e43251230e5fb8dd8d8277fbce5b05..9b6fdeac5c8c29c398d53fe953d84c6dc2d93a8a 100644 (file)
--- a/thread.c
+++ b/thread.c
 #include <string.h>
 #include <ctype.h>
 
+/* returns 1 if `a' is a descendant (child) of thread `b' */
+static int is_descendant (HEADER *a, HEADER *b)
+{
+  /* find the top parent of the thread */
+  while (a->parent)
+    a = a->parent;
+  return (a == b);
+}
+
 /* This function makes use of the fact that Mutt stores message references in
  * reverse order (i.e., last to first).  This is optiminal since we would like
  * to find the most recent message to which "cur" refers itself.  
@@ -40,12 +49,16 @@ static HEADER *find_reference (HEADER *cur, CONTEXT *ctx)
   for (; refs; refs = refs->next)
   {
     /* ups, this message is in a reference loop. bad. */
-
     if (cur->env->message_id && !strcmp (cur->env->message_id, refs->data))
       continue;
-
+    
     if ((ptr = hash_find (ctx->id_hash, refs->data)))
+    {
+      if (is_descendant (ptr, cur))
+       continue;
+
       return ptr;
+    }
   }
   
   return NULL;
@@ -88,7 +101,9 @@ static int need_display_subject (CONTEXT *ctx, HEADER *tree)
 }
 
 /* determines whether a later sibling or the child of a later 
-   sibling is displayed.  */
+ * sibling is displayed.  
+ */
+
 static int is_next_displayed (CONTEXT *ctx, HEADER *tree)
 {
   int depth = 0;
@@ -139,7 +154,8 @@ void mutt_linearize_tree (CONTEXT *ctx, int linearize)
   HEADER **array = ctx->hdrs + (Sort & SORT_REVERSE ? ctx->msgcount - 1 : 0);
 
   /* A NULL tree should never be passed here, but may occur if there is
-     a cycle.  */
+   * a cycle.  
+   */
   if (!tree)
     return;
 
@@ -281,18 +297,12 @@ static void insert_message (HEADER **tree, HEADER *msg, sort_t *sortFunc)
   msg->next = NULL;
 }
 
-/* returns 1 if `a' is a descendant (child) of thread `b' */
-static int is_descendant (HEADER *a, HEADER *b)
-{
-  /* find the top parent of the thread */
-  while (a->parent)
-    a = a->parent;
-  return (a == b);
-}
 
 /* find the best possible match for a parent mesage based upon subject.
-   if there are multiple matches, the one which was sent the latest, but
-   before the current message, is used. */
+ * if there are multiple matches, the one which was sent the latest, but
+ * before the current message, is used. 
+ */
+
 static HEADER *find_subject (CONTEXT *ctx, HEADER *cur)
 {
   struct hash_elem *ptr;