From c11dbf982443513f1bc52e781532f88a7c4ca368 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Wed, 11 Sep 2019 14:31:08 +0100 Subject: [PATCH] fix: mbox_check_stats() retvals Change mbox_check_stats() to clearly show when a Mailbox has new mail. Return: * -1 Error * 0 Success, no new mail * 1 Success, some new mail A bug was introduced when mbox_check_stats() was created that caused 'mbox' Mailboxes to always appear as if they had new mail. --- imap/imap.c | 2 +- maildir/maildir.c | 2 +- maildir/mh.c | 8 ++++---- mbox/mbox.c | 2 +- mutt_mailbox.c | 6 +++--- mx.h | 3 ++- notmuch/mutt_notmuch.c | 2 +- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/imap/imap.c b/imap/imap.c index 19c414f76..3ec35140d 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -1295,7 +1295,7 @@ int imap_mbox_check_stats(struct Mailbox *m, int flags) { int rc = imap_mailbox_status(m, true); if (rc > 0) - rc = 0; + rc = 1; return rc; } diff --git a/maildir/maildir.c b/maildir/maildir.c index ad6b731ad..3db24cabb 100644 --- a/maildir/maildir.c +++ b/maildir/maildir.c @@ -549,7 +549,7 @@ static int maildir_mbox_check_stats(struct Mailbox *m, int flags) if (check_new || check_stats) maildir_check_dir(m, "cur", check_new, check_stats); - return 0; + return (m->msg_new > 0); } /** diff --git a/maildir/mh.c b/maildir/mh.c index a5bb65d0d..759524af0 100644 --- a/maildir/mh.c +++ b/maildir/mh.c @@ -419,7 +419,7 @@ static int mh_mbox_check_stats(struct Mailbox *m, int flags) { struct MhSequences mhs = { 0 }; bool check_new = true; - bool rc = false; + int rc = -1; DIR *dirp = NULL; struct dirent *de = NULL; @@ -427,7 +427,7 @@ static int mh_mbox_check_stats(struct Mailbox *m, int flags) * since the last m visit, there is no "new mail" */ if (C_MailCheckRecent && (mh_sequences_changed(m) <= 0)) { - rc = false; + rc = 0; check_new = false; } @@ -435,7 +435,7 @@ static int mh_mbox_check_stats(struct Mailbox *m, int flags) return 0; if (mh_read_sequences(&mhs, mailbox_path(m)) < 0) - return false; + return -1; m->msg_count = 0; m->msg_unread = 0; @@ -455,7 +455,7 @@ static int mh_mbox_check_stats(struct Mailbox *m, int flags) if (!C_MailCheckRecent || (mh_already_notified(m, i) == 0)) { m->has_new = true; - rc = true; + rc = 1; } /* Because we are traversing from high to low, we can stop * checking for new mail after the first unseen message. diff --git a/mbox/mbox.c b/mbox/mbox.c index f2246803c..49a90017e 100644 --- a/mbox/mbox.c +++ b/mbox/mbox.c @@ -1781,7 +1781,7 @@ static int mbox_mbox_check_stats(struct Mailbox *m, int flags) } } - return 0; + return (m->msg_new > 0); } // clang-format off diff --git a/mutt_mailbox.c b/mutt_mailbox.c index 3925d6ba6..6cb89b79b 100644 --- a/mutt_mailbox.c +++ b/mutt_mailbox.c @@ -88,7 +88,7 @@ static void mailbox_check(struct Mailbox *m_cur, struct Mailbox *m_check, case MUTT_MAILDIR: case MUTT_MH: case MUTT_NOTMUCH: - if (mx_mbox_check_stats(m_check, 0) == 0) + if ((mx_mbox_check_stats(m_check, check_stats) == 1) && m_check->has_new) MailboxCount++; break; default:; /* do nothing */ @@ -187,7 +187,7 @@ int mutt_mailbox_check(struct Mailbox *m_cur, int force) */ bool mutt_mailbox_notify(struct Mailbox *m_cur) { - if (mutt_mailbox_check(m_cur, 0) && MailboxNotify) + if ((mutt_mailbox_check(m_cur, 0) > 0) && MailboxNotify) { return mutt_mailbox_list(); } @@ -292,7 +292,7 @@ void mutt_mailbox_next_buffer(struct Mailbox *m_cur, struct Buffer *s) { mutt_buffer_expand_path(s); - if (mutt_mailbox_check(m_cur, 0)) + if (mutt_mailbox_check(m_cur, 0) > 0) { bool found = false; for (int pass = 0; pass < 2; pass++) diff --git a/mx.h b/mx.h index 28957bc60..2e53e53eb 100644 --- a/mx.h +++ b/mx.h @@ -149,7 +149,8 @@ struct MxOps * mbox_check_stats - Check the Mailbox statistics * @param m Mailbox to check * @param flags Function flags - * @retval 0 Success + * @retval 0 Success, no new mail + * @retval 1 Success, some new mail * @retval -1 Failure */ int (*mbox_check_stats)(struct Mailbox *m, int flags); diff --git a/notmuch/mutt_notmuch.c b/notmuch/mutt_notmuch.c index 7bcfd8623..3e55dac12 100644 --- a/notmuch/mutt_notmuch.c +++ b/notmuch/mutt_notmuch.c @@ -1996,7 +1996,7 @@ static int nm_mbox_check_stats(struct Mailbox *m, int flags) m->msg_flagged = count_query(db, qstr, limit); FREE(&qstr); - rc = 0; + rc = (m->msg_new > 0); done: if (db) { -- 2.40.0