]> granicus.if.org Git - neomutt/commitdiff
Recompute and re-thread everything in mx_update_context
authorPietro Cerutti <gahr@gahr.ch>
Mon, 3 Dec 2018 15:25:01 +0000 (15:25 +0000)
committerRichard Russon <rich@flatcap.org>
Tue, 4 Dec 2018 13:34:49 +0000 (13:34 +0000)
This allows us to be less strict about calling mx_update_context, e.g.,
by calling it twice if it so happens within a code path.

maildir/maildir.c
maildir/mh.c
mbox/mbox.c
mx.c
mx.h
nntp/nntp.c
notmuch/mutt_notmuch.c
pop/pop.c

index 306afe63bd8c74de1237396afc590aca234839fb..53cdba349944b91245986f1c6c4a458a832843c3 100644 (file)
@@ -530,7 +530,7 @@ int maildir_mbox_check(struct Context *ctx, int *index_hint)
   /* Incorporate new messages */
   num_new = maildir_move_to_context(m, &md);
   if (num_new > 0)
-    mx_update_context(ctx, num_new);
+    mx_update_context(ctx);
 
   mutt_buffer_pool_release(&buf);
 
index d1c4e351083fee47811c1019aac96c5a8d1fa694..4fa77503d31ed94f51b1f24f42380834c27f7a2d 100644 (file)
@@ -720,7 +720,7 @@ int mh_mbox_check(struct Context *ctx, int *index_hint)
   /* Incorporate new messages */
   num_new = maildir_move_to_context(m, &md);
   if (num_new > 0)
-    mx_update_context(ctx, num_new);
+    mx_update_context(ctx);
 
   if (occult)
     return MUTT_REOPENED;
index 0ce572681fa6b9cf6cce71ee54ff639637b8da98..4f4b22410eaf721aafabf7e38e9e124cbce4cd1c 100644 (file)
@@ -1031,7 +1031,7 @@ static int mbox_mbox_check(struct Context *ctx, int *index_hint)
   {
     if (mbox_mbox_open(m, ctx) < 0)
       return -1;
-    mx_update_context(ctx, m->msg_count);
+    mx_update_context(ctx);
   }
 
   struct stat st;
@@ -1094,7 +1094,7 @@ static int mbox_mbox_check(struct Context *ctx, int *index_hint)
             mmdf_parse_mailbox(ctx);
 
           if (m->msg_count > old_msg_count)
-            mx_update_context(ctx, m->msg_count > old_msg_count);
+            mx_update_context(ctx);
 
           /* Only unlock the folder if it was locked inside of this routine.
            * It may have been locked elsewhere, like in
@@ -1124,7 +1124,7 @@ static int mbox_mbox_check(struct Context *ctx, int *index_hint)
   {
     if (reopen_mailbox(ctx, index_hint) != -1)
     {
-      mx_update_context(ctx, m->msg_count);
+      mx_update_context(ctx);
       if (unlock)
       {
         mbox_unlock_mailbox(m);
diff --git a/mx.c b/mx.c
index 2d6b0bbe621c15d96004f57d1eafb5c697f226f0..e9e649da6c73913db28fbe40cafc4c71ecdb09d3 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -370,7 +370,7 @@ struct Context *mx_mbox_open(struct Mailbox *m, const char *path, int flags)
   int rc = m->mx_ops->mbox_open(ctx->mailbox, ctx);
   m->opened++;
   if (rc == 0)
-    mx_update_context(ctx, ctx->mailbox->msg_count);
+    mx_update_context(ctx);
 
   if ((rc == 0) || (rc == -2))
   {
@@ -1236,20 +1236,44 @@ void mx_alloc_memory(struct Mailbox *m)
 /**
  * mx_update_context - Update the Context's message counts
  * @param ctx          Mailbox
- * @param new_messages Number of new messages
  *
- * this routine is called to update the counts in the context structure for the
- * last message header parsed.
+ * this routine is called to update the counts in the context structure
  */
-void mx_update_context(struct Context *ctx, int new_messages)
+void mx_update_context(struct Context *ctx)
 {
   if (!ctx || !ctx->mailbox)
     return;
 
   struct Mailbox *m = ctx->mailbox;
 
+  if (!m)
+    return;
+
+  if (m->subj_hash)
+  {
+    mutt_hash_destroy(&m->subj_hash);
+  }
+  m->subj_hash = NULL;
+
+  if (m->id_hash)
+  {
+    mutt_hash_destroy(&m->id_hash);
+  }
+  m->id_hash = NULL;
+
+  /* reset counters */
+  m->msg_unread = 0;
+  m->msg_flagged = 0;
+  m->msg_new = 0;
+  m->msg_deleted = 0;
+  m->msg_tagged = 0;
+  m->vcount = 0;
+  m->changed = false;
+
+  mutt_clear_threads(ctx);
+
   struct Email *e = NULL;
-  for (int msgno = m->msg_count - new_messages; msgno < m->msg_count; msgno++)
+  for (int msgno = 0; msgno < m->msg_count; msgno++)
   {
     e = m->hdrs[msgno];
 
@@ -1307,6 +1331,8 @@ void mx_update_context(struct Context *ctx, int new_messages)
         m->msg_new++;
     }
   }
+
+  mutt_sort_headers(ctx, true); /* rethread from scratch */
 }
 
 /**
diff --git a/mx.h b/mx.h
index ecc7258c8d2587b59c615ac43866aeb362e32132..4e7ea1fa0d923edffe6cd86d8fae2030d6a792e4 100644 (file)
--- a/mx.h
+++ b/mx.h
@@ -282,7 +282,7 @@ int                 mx_check_empty      (const char *path);
 void                mx_fastclose_mailbox(struct Context *ctx);
 const struct MxOps *mx_get_ops          (enum MailboxType magic);
 bool                mx_tags_is_supported(struct Mailbox *m);
-void                mx_update_context   (struct Context *ctx, int new_messages);
+void                mx_update_context   (struct Context *ctx);
 void                mx_update_tables    (struct Context *ctx, bool committing);
 void                mx_cleanup_context  (struct Context *ctx);
 
index 0a0969a5bf638f417dcb3db8c99f1e98d9cd4938..22878b62510520aca0525e435773f02396ab6261 100644 (file)
@@ -1692,21 +1692,7 @@ static int check_mailbox(struct Context *ctx)
   /* some headers were removed, context must be updated */
   if (ret == MUTT_REOPENED)
   {
-    if (m->subj_hash)
-      mutt_hash_destroy(&m->subj_hash);
-    if (m->id_hash)
-      mutt_hash_destroy(&m->id_hash);
-    mutt_clear_threads(ctx);
-
-    m->vcount = 0;
-    m->msg_deleted = 0;
-    m->msg_new = 0;
-    m->msg_unread = 0;
-    m->msg_flagged = 0;
-    m->changed = false;
-    m->id_hash = NULL;
-    m->subj_hash = NULL;
-    mx_update_context(ctx, m->msg_count);
+    mx_update_context(ctx);
   }
 
   /* fetch headers of new articles */
@@ -1728,7 +1714,7 @@ static int check_mailbox(struct Context *ctx)
     if (rc == 0)
     {
       if (m->msg_count > old_msg_count)
-        mx_update_context(ctx, m->msg_count > old_msg_count);
+        mx_update_context(ctx);
       mdata->last_loaded = mdata->last_message;
     }
     if (ret == 0 && m->msg_count > oldmsgcount)
@@ -2297,7 +2283,7 @@ int nntp_check_msgid(struct Context *ctx, const char *msgid)
   e->changed = true;
   e->received = e->date_sent;
   e->index = m->msg_count++;
-  mx_update_context(ctx, 1);
+  mx_update_context(ctx);
   return 0;
 }
 
@@ -2367,7 +2353,7 @@ int nntp_check_children(struct Context *ctx, const char *msgid)
       break;
   }
   if (m->msg_count > old_msg_count)
-    mx_update_context(ctx, m->msg_count > old_msg_count);
+    mx_update_context(ctx);
 
 #ifdef USE_HCACHE
   mutt_hcache_close(hc);
index 7786ba861f5148569ed26a1ea828f40dbf47b529..253c8d7ac89ee135fefed33cb51ab32145c2962c 100644 (file)
@@ -1632,7 +1632,7 @@ int nm_read_entire_thread(struct Context *ctx, struct Email *e)
   rc = 0;
 
   if (m->msg_count > mdata->oldmsgcount)
-    mx_update_context(ctx, m->msg_count - mdata->oldmsgcount);
+    mx_update_context(ctx);
 done:
   if (q)
     notmuch_query_destroy(q);
@@ -2286,7 +2286,7 @@ static int nm_mbox_check(struct Context *ctx, int *index_hint)
   }
 
   if (m->msg_count > mdata->oldmsgcount)
-    mx_update_context(ctx, m->msg_count - mdata->oldmsgcount);
+    mx_update_context(ctx);
 done:
   if (q)
     notmuch_query_destroy(q);
index 8208df134b5cf6064f2732ec4599a987bbb1fa56..cc0d9c49a943372a73341321490bffd8e035afbd 100644 (file)
--- a/pop/pop.c
+++ b/pop/pop.c
@@ -928,7 +928,7 @@ static int pop_mbox_check(struct Context *ctx, int *index_hint)
   int ret = pop_fetch_headers(ctx);
   pop_clear_cache(adata);
   if (m->msg_count > old_msg_count)
-    mx_update_context(ctx, m->msg_count > old_msg_count);
+    mx_update_context(ctx);
 
   if (ret < 0)
     return -1;