From: Mehdi Abaakouk Date: Mon, 19 Nov 2018 12:38:32 +0000 (+0100) Subject: imap: remove MESSAGES count optimization X-Git-Tag: 2019-10-25~505^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4ab1120006779fd29e58a0221aa3c862735665fa;p=neomutt imap: remove MESSAGES count optimization 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. --- diff --git a/imap/command.c b/imap/command.c index ae88d4227..fb4a812fd 100644 --- a/imap/command.c +++ b/imap/command.c @@ -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; } /** diff --git a/imap/imap.c b/imap/imap.c index 12d2b4acf..4a7272a13 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -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; } /** diff --git a/imap/imap.h b/imap/imap.h index 6a90ca577..6fc86bd39 100644 --- a/imap/imap.h +++ b/imap/imap.h @@ -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); diff --git a/mailbox.c b/mailbox.c index 82e56c2a2..e0cecb90f 100644 --- 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