]> granicus.if.org Git - neomutt/commitdiff
mbox: factor out mx_update_context()
authorRichard Russon <rich@flatcap.org>
Tue, 20 Nov 2018 14:59:44 +0000 (14:59 +0000)
committerRichard Russon <rich@flatcap.org>
Thu, 29 Nov 2018 13:12:36 +0000 (13:12 +0000)
mbox/mbox.c

index f80c67cea4f4b4d0b8cce7bc4c928640a1bd7e40..0ce572681fa6b9cf6cce71ee54ff639637b8da98 100644 (file)
@@ -192,7 +192,7 @@ static int mmdf_parse_mailbox(struct Context *ctx)
 
   char buf[HUGE_STRING];
   char return_path[LONG_STRING];
-  int count = 0, oldmsgcount = m->msg_count;
+  int count = 0;
   int lines;
   time_t t;
   LOFF_T loc, tmploc;
@@ -324,9 +324,6 @@ static int mmdf_parse_mailbox(struct Context *ctx)
     }
   }
 
-  if (m->msg_count > oldmsgcount)
-    mx_update_context(ctx, m->msg_count - oldmsgcount);
-
   if (SigInt == 1)
   {
     SigInt = 0;
@@ -543,8 +540,6 @@ static int mbox_parse_mailbox(struct Context *ctx)
 
     if (!e->lines)
       e->lines = lines ? lines - 1 : 0;
-
-    mx_update_context(ctx, count);
   }
 
   if (SigInt == 1)
@@ -1032,8 +1027,12 @@ static int mbox_mbox_check(struct Context *ctx, int *index_hint)
   if (!adata)
     return -1;
 
-  if (!adata->fp && (mbox_mbox_open(m, ctx) < 0))
-    return -1;
+  if (!adata->fp)
+  {
+    if (mbox_mbox_open(m, ctx) < 0)
+      return -1;
+    mx_update_context(ctx, m->msg_count);
+  }
 
   struct stat st;
   bool unlock = false;
@@ -1087,16 +1086,19 @@ static int mbox_mbox_check(struct Context *ctx, int *index_hint)
         {
           if (fseeko(adata->fp, m->size, SEEK_SET) != 0)
             mutt_debug(1, "#2 fseek() failed\n");
+
+          int old_msg_count = m->msg_count;
           if (m->magic == MUTT_MBOX)
             mbox_parse_mailbox(ctx);
           else
             mmdf_parse_mailbox(ctx);
 
+          if (m->msg_count > old_msg_count)
+            mx_update_context(ctx, m->msg_count > old_msg_count);
+
           /* Only unlock the folder if it was locked inside of this routine.
            * It may have been locked elsewhere, like in
-           * mutt_checkpoint_mailbox().
-           */
-
+           * mutt_checkpoint_mailbox().  */
           if (unlock)
           {
             mbox_unlock_mailbox(m);
@@ -1122,6 +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);
       if (unlock)
       {
         mbox_unlock_mailbox(m);