]> granicus.if.org Git - mutt/commitdiff
patch-1.3.23.1-de-new_threads.3-4
authorThomas Roessler <roessler@does-not-exist.org>
Thu, 8 Nov 2001 08:56:48 +0000 (08:56 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Thu, 8 Nov 2001 08:56:48 +0000 (08:56 +0000)
commands.c
curs_main.c
init.c
init.h
mutt.h
sort.c
thread.c

index 92e5562713d736217c126af2efe73e78f9102063..632970acc6efc88b7fdccd5792ba21036d9a90c9 100644 (file)
@@ -535,11 +535,6 @@ void mutt_enter_command (void)
   BUFFER err, token;
   char buffer[LONG_STRING], errbuf[SHORT_STRING];
   int r;
-  int old_strictthreads  = option (OPTSTRICTTHREADS);
-  int old_sortre        = option (OPTSORTRE);
-  int old_hidemissing   = option (OPTHIDEMISSING);
-  int old_threadreceived = option (OPTTHREADRECEIVED);
-  int old_dupthreads    = option (OPTDUPTHREADS);
 
   buffer[0] = 0;
   if (mutt_get_field (":", buffer, sizeof (buffer), M_COMMAND) != 0 || !buffer[0])
@@ -559,12 +554,6 @@ void mutt_enter_command (void)
     else
       mutt_error ("%s", errbuf);
   }
-  if (option (OPTSTRICTTHREADS) != old_strictthreads ||
-      option (OPTSORTRE) != old_sortre ||
-      option (OPTHIDEMISSING) != old_hidemissing ||
-      option (OPTTHREADRECEIVED) != old_threadreceived ||
-      option (OPTDUPTHREADS) != old_dupthreads)
-    set_option (OPTNEEDRESORT);
 }
 
 void mutt_display_address (ENVELOPE *env)
index 32a122110648175a4d8f4ff70acd409a72886f7e..47fedf682d59f39d7c991f17f4fabd9e9cebd987 100644 (file)
@@ -799,7 +799,7 @@ int mutt_index_menu (void)
          else
            menu->current = 0;
          menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
-         if (Sort & SORT_THREADS)
+         if ((Sort & SORT_MASK) == SORT_THREADS)
            mutt_linearize_tree (Context, 0);
        }
        break;    
diff --git a/init.c b/init.c
index 06974c39791fbd92abf76f271b337d87dd84d769..752e09e92b68a1e9b874a3449b64f563bed15540 100644 (file)
--- a/init.c
+++ b/init.c
@@ -760,6 +760,8 @@ static void mutt_restore_default (struct option_t *p)
     set_option (OPTSORTSUBTHREADS);
   if (p->flags & R_RESORT)
     set_option (OPTNEEDRESORT);
+  if (p->flags & R_RESORT_INIT)
+    set_option (OPTRESORTINIT);
 }
 
 static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
@@ -1203,6 +1205,8 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
       set_option (OPTSORTSUBTHREADS);
     if (MuttVars[idx].flags & R_RESORT)
       set_option (OPTNEEDRESORT);
+    if (MuttVars[idx].flags & R_RESORT_INIT)
+      set_option (OPTRESORTINIT);
   }
   return (r);
 }
diff --git a/init.h b/init.h
index 99673a8414df4bd7ca76a9bc7a06ae679d98f438..8b3176d4b966cd97d7bf01b0db507f895182cd5b 100644 (file)
--- a/init.h
+++ b/init.h
@@ -57,6 +57,7 @@
 #define R_PAGER                (1<<1)
 #define R_RESORT       (1<<2)  /* resort the mailbox */
 #define R_RESORT_SUB   (1<<3)  /* resort subthreads */
+#define R_RESORT_INIT  (1<<4)  /* resort from scratch */
 #define R_BOTH         (R_INDEX | R_PAGER)
 #define R_RESORT_BOTH  (R_RESORT | R_RESORT_SUB)
 
@@ -426,7 +427,7 @@ struct option_t MuttVars[] = {
   ** .pp
   ** Example: set dsn_return=hdrs
   */
-  { "duplicate_threads",       DT_BOOL, R_NONE, OPTDUPTHREADS, 1 },
+  { "duplicate_threads",       DT_BOOL, R_RESORT|R_RESORT_INIT|R_INDEX, OPTDUPTHREADS, 1 },
   /*
   ** .pp
   ** This variable controls whether mutt, when sorting by threads, threads
@@ -648,7 +649,7 @@ struct option_t MuttVars[] = {
   ** affect the generation of Message-IDs, and it will not lead to the 
   ** cut-off of first-level domains.
   */
-  { "hide_missing",    DT_BOOL, R_NONE, OPTHIDEMISSING, 1 },
+  { "hide_missing",    DT_BOOL, R_RESORT|R_INDEX, OPTHIDEMISSING, 1 },
   /*
   ** .pp
   ** When set, mutt will not indicate the presence of missing messages
@@ -2043,7 +2044,7 @@ struct option_t MuttVars[] = {
   ** You may optionally use the reverse- prefix to specify reverse sorting
   ** order (example: set sort_browser=reverse-date).
   */
-  { "sort_re",         DT_BOOL, R_INDEX|R_RESORT_BOTH, OPTSORTRE, 1 },
+  { "sort_re",         DT_BOOL, R_INDEX|R_RESORT|R_RESORT_INIT, OPTSORTRE, 1 },
   /*
   ** .pp
   ** This variable is only useful when sorting by threads with
@@ -2148,7 +2149,7 @@ struct option_t MuttVars[] = {
   ** Setting this variable causes the ``status bar'' to be displayed on
   ** the first line of the screen rather than near the bottom.
   */
-  { "strict_threads",  DT_BOOL, R_RESORT|R_INDEX, OPTSTRICTTHREADS, 0 },
+  { "strict_threads",  DT_BOOL, R_RESORT|R_RESORT_INIT|R_INDEX, OPTSTRICTTHREADS, 0 },
   /*
   ** .pp
   ** If set, threading will only make use of the ``In-Reply-To'' and
@@ -2175,7 +2176,7 @@ struct option_t MuttVars[] = {
   ** .pp
   ** Note that $$indent_string is ignored when this option is set.
   */
-  { "thread_received", DT_BOOL, R_NONE, OPTTHREADRECEIVED, 0 },
+  { "thread_received", DT_BOOL, R_RESORT|R_RESORT_INIT|R_INDEX, OPTTHREADRECEIVED, 0 },
   /*
   ** .pp
   ** When set, mutt uses the date received rather than the date sent
diff --git a/mutt.h b/mutt.h
index 8d1929b0e7014eba750a56f404f57be4132f2ad0..f90ade9619b4959913873cc741b25b8b284fba44 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -437,6 +437,7 @@ enum
   OPTSIGNALSBLOCKED,   /* (pseudo) using by mutt_block_signals () */
   OPTSYSSIGNALSBLOCKED,        /* (pseudo) using by mutt_block_signals_system () */
   OPTNEEDRESORT,       /* (pseudo) used to force a re-sort */
+  OPTRESORTINIT,       /* (pseudo) used to force the next resort to be from scratch */
   OPTVIEWATTACH,       /* (pseudo) signals that we are viewing attachments */
   OPTFORCEREDRAWINDEX, /* (pseudo) used to force a redraw in the main index */
   OPTFORCEREDRAWPAGER, /* (pseudo) used to force a redraw in the pager */
diff --git a/sort.c b/sort.c
index 1806ee9851a94dba45b538277eb9122818b1a3dc..2792da2b722afaadda4abd5ab00753511d92e222 100644 (file)
--- a/sort.c
+++ b/sort.c
@@ -222,6 +222,11 @@ void mutt_sort_headers (CONTEXT *ctx, int init)
       Sort = i;
       unset_option (OPTSORTSUBTHREADS);
     }
+    if (option (OPTRESORTINIT))
+    {
+      unset_option (OPTRESORTINIT);
+      init = 1;
+    }
     mutt_sort_threads (ctx, init);
   }
   else if ((sortfunc = mutt_get_sort_func (Sort)) == NULL ||
index 3047519bf4e1c5b5c7e3128ae8314853f03a02a7..e6df19ad7a3e51f3e89511a39defcef38b0dfd64 100644 (file)
--- 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);