]> granicus.if.org Git - neomutt/commitdiff
imap: remove MESSAGES count optimization
authorMehdi Abaakouk <sileht@sileht.net>
Mon, 19 Nov 2018 12:38:32 +0000 (13:38 +0100)
committerRichard Russon <rich@flatcap.org>
Tue, 20 Nov 2018 10:58:29 +0000 (10:58 +0000)
This optimization is buggy, it puts sometimes mdata->messages out of
sync with m->msg_count;

This optimization links in an not obvious way the cmd_parse_status and
mx_mailbox_check().

This change removes this useless optimization and just always asks for
MESSAGES during STATUS.

imap/command.c
imap/imap.c
imap/imap.h
mailbox.c

index ae88d42275f11323685a5cf7f672e9fa4c94f6ee..fb4a812fda290a57d41481fdcec12d8c41361d88 100644 (file)
@@ -784,7 +784,6 @@ static void cmd_parse_status(struct ImapAccountData *adata, char *s)
   unsigned int olduv, oldun;
   unsigned int litlen;
   short new = 0;
-  short new_msg_count = 0;
 
   char *mailbox = imap_next_word(s);
 
@@ -851,10 +850,7 @@ static void cmd_parse_status(struct ImapAccountData *adata, char *s)
     const unsigned int count = (unsigned int) ulcount;
 
     if (mutt_str_startswith(s, "MESSAGES", CASE_MATCH))
-    {
       mdata->messages = count;
-      new_msg_count = 1;
-    }
     else if (mutt_str_startswith(s, "RECENT", CASE_MATCH))
       mdata->recent = count;
     else if (mutt_str_startswith(s, "UIDNEXT", CASE_MATCH))
@@ -898,22 +894,16 @@ static void cmd_parse_status(struct ImapAccountData *adata, char *s)
 #ifdef USE_SIDEBAR
   if ((m->has_new != new) || (m->msg_count != mdata->messages) ||
       (m->msg_unread != mdata->unseen))
-  {
     mutt_menu_set_current_redraw(REDRAW_SIDEBAR);
-  }
 #endif
+
   m->has_new = new;
-  if (new_msg_count)
-    m->msg_count = mdata->messages;
+  m->msg_count = mdata->messages;
   m->msg_unread = mdata->unseen;
 
+  // force back to keep detecting new mail until the mailbox is opened
   if (m->has_new)
-  {
-    /* force back to keep detecting new mail until the mailbox is
-       opened */
     mdata->uid_next = oldun;
-  }
-  return;
 }
 
 /**
index 12d2b4acf2d5734e62f4f5201f47e29f40527035..4a7272a130489e1efad99b7cbab0b4392098b622 100644 (file)
@@ -1345,14 +1345,13 @@ int imap_check(struct ImapAccountData *adata, struct ImapMboxData *mdata, bool f
 /**
  * imap_mailbox_check - Check for new mail in subscribed folders
  * @param m           Mailbox
- * @param check_stats Check for message stats too
  * @retval num Number of mailboxes with new mail
  * @retval 0   Failure
  *
  * Given a list of mailboxes rather than called once for each so that it can
  * batch the commands and save on round trips.
  */
-int imap_mailbox_check(struct Mailbox *m, bool check_stats)
+int imap_mailbox_check(struct Mailbox *m)
 {
   struct ImapAccountData *adata = NULL;
   struct ImapMboxData *mdata = NULL;
@@ -1384,16 +1383,8 @@ int imap_mailbox_check(struct Mailbox *m, bool check_stats)
     return -1;
   }
 
-  if (check_stats)
-  {
-    snprintf(command, sizeof(command),
-             "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT MESSAGES)", mdata->munge_name);
-  }
-  else
-  {
-    snprintf(command, sizeof(command),
-             "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT)", mdata->munge_name);
-  }
+  snprintf(command, sizeof(command),
+           "STATUS %s (UIDNEXT UIDVALIDITY UNSEEN RECENT MESSAGES)", mdata->munge_name);
 
   if (imap_exec(adata, command, IMAP_CMD_QUEUE | IMAP_CMD_POLL) != IMAP_EXEC_SUCCESS)
   {
@@ -1450,7 +1441,7 @@ int imap_status(const char *path, bool queue)
   }
 
   imap_exec(adata, buf, queue ? IMAP_CMD_QUEUE : 0);
-  return mdata->messages;
+  return m->msg_count;
 }
 
 /**
index 6a90ca5774203433a2b9d1fc24d1a1f4484ee775..6fc86bd391b8aa7d44a42c7a2d7316729b63746d 100644 (file)
@@ -80,7 +80,7 @@ int imap_access(const char *path);
 int imap_check_mailbox(struct Mailbox *m, bool force);
 int imap_delete_mailbox(struct Mailbox *m, char *path);
 int imap_sync_mailbox(struct Context *ctx, bool expunge, bool close);
-int imap_mailbox_check(struct Mailbox *m, bool check_stats);
+int imap_mailbox_check(struct Mailbox *m);
 int imap_status(const char *path, bool queue);
 int imap_search(struct Mailbox *m, const struct Pattern *pat);
 int imap_subscribe(char *path, bool subscribe);
index 82e56c2a2f945fc82c83d8d8fb40f073f20c1e73..e0cecb90ffe7d5439c83514932fc56af8608b399 100644 (file)
--- a/mailbox.c
+++ b/mailbox.c
@@ -372,7 +372,7 @@ static void mailbox_check(struct Mailbox *m, struct stat *ctx_sb, bool check_sta
         break;
 #ifdef USE_IMAP
       case MUTT_IMAP:
-        if (imap_mailbox_check(m, check_stats) == 0 && m->has_new)
+        if (imap_mailbox_check(m) == 0 && m->has_new)
           MailboxCount++;
         break;
 #endif