if ((Sort & SORT_MASK) == SORT_THREADS) Sort = (Sort & ~SORT_MASK) | SORT_DATE;
void mutt_sort_threads (CONTEXT *ctx, int init){  sort_t *usefunc = NULL;  HEADER *tmp, *CUR;  int i, oldsort;    /* set Sort to the secondary method to support the set sort_aux=reverse-*   * settings.  The sorting functions just look at the value of   * SORT_REVERSE   */  oldsort = Sort;  Sort = SortAux;    /* get secondary sorting method.  we can't have threads, so use the date   * if the user specified it   */  if ((Sort & SORT_MASK) == SORT_THREADS)    Sort = (Sort & ~SORT_MASK) | SORT_DATE;    /* if the SORT_LAST bit is set, we save sorting for later */  if (!(Sort & SORT_LAST))    usefunc = mutt_get_sort_func (Sort);  for (i = 0; i < ctx->msgcount; i++)  {    CUR = ctx->hdrs[i];    if (CUR->fake_thread)    {      /* Move pseudo threads back to the top level thread so that they can       * can be moved later if they are descendants of messages that were       * just delivered.       */      CUR->fake_thread = 0;      CUR->subject_changed = 1;      unlink_message (&CUR->parent->child, CUR);      CUR->parent = NULL;      insert_message (&ctx->tree, CUR, usefunc);    }    else if (!CUR->threaded)    {      if ((tmp = find_reference (CUR, ctx)) != NULL)      {	CUR->parent = tmp;	if (CUR->env->real_subj && tmp->env->real_subj)	  CUR->subject_changed = mutt_strcmp (tmp->env->real_subj, CUR->env->real_subj) ? 1 : 0;	else	  CUR->subject_changed = (CUR->env->real_subj || tmp->env->real_subj) ? 1 : 0;      }      else	CUR->subject_changed = 1;      if (!init)      {	/* Search the children of `tmp' for decendants of `cur'.  This is only	 * done when the mailbox has already been threaded since we don't have	 * to worry about the tree being threaded wrong (because of a missing	 * parent) during the initial threading.	 */	if (CUR->env->message_id)	  move_descendants (tmp ? &tmp->child : &ctx->tree, CUR, usefunc);      }      insert_message (tmp ? &tmp->child : &ctx->tree, CUR, usefunc);      CUR->threaded = 1;    }  }  if (!option (OPTSTRICTTHREADS))    pseudo_threads (ctx, usefunc);  /* now that the whole tree is put together, we can sort by last-* */  if (Sort & SORT_LAST)  {    for (i = 0; i < ctx->msgcount; i++)      ctx->hdrs[i]->last_sort = ctx->hdrs[i];    ctx->tree = sort_last (ctx->tree);  }    /* restore the oldsort order. */  Sort = oldsort;  /* Put the list into an array.  If we are reverse sorting, give the   * offset of the last message, and work backwards (tested for and   * done inside the function), so that the threads go backwards.    * This, of course, means the auxillary sort has to go forwards   * because we map it backwards here.   */  mutt_linearize_tree (ctx, 1);}