]> granicus.if.org Git - neomutt/commitdiff
Fix sidebar count updates when closing mailbox. (closes #3938)
authorKevin McCarthy <kevin@8t8.us>
Fri, 5 May 2017 01:05:06 +0000 (18:05 -0700)
committerRichard Russon <rich@flatcap.org>
Fri, 12 May 2017 13:08:59 +0000 (14:08 +0100)
The context unread and flagged counts were being updated too early in
mx_close_mailbox().  Cancelling at any of the following prompts would
leave them in an incorrect state.  Additionally, $move could increase
the delete count (for flagged messages), and $delete, if answered no,
could turn off message deletion.

Move all the sidebar buffy stat updating to the bottom of the
function, after all the prompts and processing.

mx.c

diff --git a/mx.c b/mx.c
index 07b96b0296412439d1dc4147b3340f86920ff491..b5716339fc072e715287b4374e9b7febd89f7296 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -850,12 +850,6 @@ int mx_close_mailbox(CONTEXT *ctx, int *index_hint)
     if (!ctx->hdrs[i]->deleted && ctx->hdrs[i]->read &&
         !(ctx->hdrs[i]->flagged && option(OPTKEEPFLAGGED)))
       read_msgs++;
-#ifdef USE_SIDEBAR
-    if (ctx->hdrs[i]->deleted && !ctx->hdrs[i]->read)
-      ctx->unread--;
-    if (ctx->hdrs[i]->deleted && ctx->hdrs[i]->flagged)
-      ctx->flagged--;
-#endif
   }
 
   if (read_msgs && quadoption(OPT_MOVE) != MUTT_NO && ctx->magic != MUTT_NNTP)
@@ -1038,7 +1032,17 @@ int mx_close_mailbox(CONTEXT *ctx, int *index_hint)
     mx_unlink_empty(ctx->path);
 
 #ifdef USE_SIDEBAR
-  ctx->msgcount -= ctx->deleted;
+  if (purge && ctx->deleted)
+  {
+    for (i = 0; i < ctx->msgcount; i++)
+    {
+      if (ctx->hdrs[i]->deleted && !ctx->hdrs[i]->read)
+        ctx->unread--;
+      if (ctx->hdrs[i]->deleted && ctx->hdrs[i]->flagged)
+        ctx->flagged--;
+    }
+    ctx->msgcount -= ctx->deleted;
+  }
   mutt_sb_set_buffystats(ctx);
 #endif