summaryrefslogtreecommitdiffstats
path: root/thread.c
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>2001-11-08 08:56:48 +0000
committerThomas Roessler <roessler@does-not-exist.org>2001-11-08 08:56:48 +0000
commit04f16e2da44e3ffb8af024cf8e6b16c769b4fff3 (patch)
treec800a91edd83bee9a348a0a18150c0964489d368 /thread.c
parent3381330a9ac5b7bf0bb812fb4fa8fde0f14d769d (diff)
patch-1.3.23.1-de-new_threads.3-4
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c110
1 files changed, 63 insertions, 47 deletions
diff --git a/thread.c b/thread.c
index 3047519b..e6df19ad 100644
--- a/thread.c
+++ b/thread.c
@@ -476,7 +476,7 @@ int compare_threads (const void *a, const void *b)
THREAD *mutt_sort_subthreads (THREAD *thread, int init)
{
- THREAD **array, *sort_key, *top;
+ THREAD **array, *sort_key, *top, *tmp;
HEADER *oldsort_key;
int i, array_size, sort_top = 0;
@@ -496,6 +496,8 @@ THREAD *mutt_sort_subthreads (THREAD *thread, int init)
{
if (init || !thread->sort_key)
{
+ thread->sort_key = NULL;
+
if (thread->parent)
thread->parent->sort_children = 1;
else
@@ -555,20 +557,20 @@ THREAD *mutt_sort_subthreads (THREAD *thread, int init)
if (thread->parent)
{
- if (!thread->parent->sort_key || thread->parent->sort_children)
+ tmp = thread;
+ thread = thread->parent;
+
+ if (!thread->sort_key || thread->sort_children)
{
/* make sort_key the first or last sibling, as appropriate */
- sort_key = (!(Sort & SORT_LAST) ^ !(Sort & SORT_REVERSE)) ? thread->parent->child : thread;
- thread->parent->sort_children = 0;
- }
- else
- sort_key = NULL;
+ sort_key = (!(Sort & SORT_LAST) ^ !(Sort & SORT_REVERSE)) ? thread->child : tmp;
- thread = thread->parent;
+ /* we just sorted its children */
+ thread->sort_children = 0;
- if (sort_key)
- {
oldsort_key = thread->sort_key;
+ thread->sort_key = thread->message;
+
if (Sort & SORT_LAST)
{
if (!thread->sort_key
@@ -578,7 +580,7 @@ THREAD *mutt_sort_subthreads (THREAD *thread, int init)
> 0))
thread->sort_key = sort_key->sort_key;
}
- else if (!thread->sort_key || !thread->message)
+ else if (!thread->sort_key)
thread->sort_key = sort_key->sort_key;
/* if its sort_key has changed, we need to resort it and siblings */
@@ -603,6 +605,38 @@ THREAD *mutt_sort_subthreads (THREAD *thread, int init)
}
}
+static void check_subjects (CONTEXT *ctx, int init)
+{
+ HEADER *cur;
+ THREAD *tmp;
+ int i;
+
+ for (i = 0; i < ctx->msgcount; i++)
+ {
+ cur = ctx->hdrs[i];
+ if (cur->thread->check_subject)
+ cur->thread->check_subject = 0;
+ else if (!init)
+ continue;
+
+ /* figure out which messages have subjects different than their parents' */
+ tmp = cur->thread->parent;
+ while (tmp && !tmp->message)
+ {
+ tmp = tmp->parent;
+ }
+
+ if (!tmp)
+ cur->subject_changed = 1;
+ else if (cur->env->real_subj && tmp->message->env->real_subj)
+ cur->subject_changed = mutt_strcmp (cur->env->real_subj,
+ tmp->message->env->real_subj) ? 1 : 0;
+ else
+ cur->subject_changed = (cur->env->real_subj
+ || tmp->message->env->real_subj) ? 1 : 0;
+ }
+}
+
void mutt_sort_threads (CONTEXT *ctx, int init)
{
HEADER *cur;
@@ -644,10 +678,10 @@ void mutt_sort_threads (CONTEXT *ctx, int init)
if (!cur->thread)
{
- thread = (((!init || option (OPTDUPTHREADS)) && cur->env->message_id)
- ? hash_find (ctx->thread_hash, cur->env->message_id) : NULL);
-
- new = (option (OPTDUPTHREADS) ? thread : NULL);
+ if ((!init || option (OPTDUPTHREADS)) && cur->env->message_id)
+ thread = hash_find (ctx->thread_hash, cur->env->message_id);
+ else
+ thread = NULL;
if (thread && !thread->message)
{
@@ -681,12 +715,15 @@ void mutt_sort_threads (CONTEXT *ctx, int init)
unlink_message (&tmp->child, thread);
thread->parent = NULL;
thread->sort_key = NULL;
+ thread->fake_thread = 0;
thread = tmp;
} while (thread != &top && !thread->child && !thread->message);
}
}
else
{
+ new = (option (OPTDUPTHREADS) ? thread : NULL);
+
thread = safe_calloc (1, sizeof (THREAD));
thread->message = cur;
thread->check_subject = 1;
@@ -694,16 +731,18 @@ void mutt_sort_threads (CONTEXT *ctx, int init)
hash_insert (ctx->thread_hash,
cur->env->message_id ? cur->env->message_id : "",
thread, 1);
- }
- if (new && new->message)
- {
- if (new->duplicate_thread)
- new = new->parent;
+ if (new)
+ {
+ if (new->duplicate_thread)
+ new = new->parent;
+
+ thread = cur->thread;
- insert_message (&new->child, new, thread);
- thread->duplicate_thread = 1;
- thread->message->threaded = 1;
+ insert_message (&new->child, new, thread);
+ thread->duplicate_thread = 1;
+ thread->message->threaded = 1;
+ }
}
}
else
@@ -807,30 +846,7 @@ void mutt_sort_threads (CONTEXT *ctx, int init)
}
ctx->tree = top.child;
- for (i = 0; i < ctx->msgcount; i++)
- {
- cur = ctx->hdrs[i];
- if (cur->thread->check_subject)
- cur->thread->check_subject = 0;
- else if (!init)
- continue;
-
- /* figure out which messages have subjects different than their parents' */
- tmp = cur->thread->parent;
- while (tmp && !tmp->message)
- {
- tmp = tmp->parent;
- }
-
- if (!tmp)
- cur->subject_changed = 1;
- else if (cur->env->real_subj && tmp->message->env->real_subj)
- cur->subject_changed = mutt_strcmp (cur->env->real_subj,
- tmp->message->env->real_subj) ? 1 : 0;
- else
- cur->subject_changed = (cur->env->real_subj
- || tmp->message->env->real_subj) ? 1 : 0;
- }
+ check_subjects (ctx, init);
if (!option (OPTSTRICTTHREADS))
pseudo_threads (ctx);