From: Thomas Roessler Date: Tue, 16 Mar 1999 21:41:50 +0000 (+0000) Subject: Detect thread loops. X-Git-Tag: mutt-0-96-2-slightly-post-release~25 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=310af6ea7cec0a781acdd7ca6f9ca087a5c3d3ad;p=mutt Detect thread loops. --- diff --git a/thread.c b/thread.c index 33aeae71..9b6fdeac 100644 --- a/thread.c +++ b/thread.c @@ -27,6 +27,15 @@ #include #include +/* 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;