From: Austin Ray Date: Fri, 7 Dec 2018 00:41:07 +0000 (+0000) Subject: maildir: use mbox_check_stats() X-Git-Tag: 2019-10-25~460^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cf7ed5ac249fe64a814a14b49f7c371abc16ba27;p=neomutt maildir: use mbox_check_stats() --- diff --git a/mailbox.c b/mailbox.c index 64668861b..6343f12b5 100644 --- a/mailbox.c +++ b/mailbox.c @@ -171,21 +171,14 @@ static void mailbox_check(struct Mailbox *m, struct stat *ctx_sb, bool check_sta { switch (m->magic) { - case MUTT_MAILDIR: - if (maildir_check(m, check_stats) > 0) - MailboxCount++; - break; - - case MUTT_MH: - if (mh_mailbox(m, check_stats)) - MailboxCount++; - break; case MUTT_IMAP: if (!m->has_new) break; /* fallthrough */ case MUTT_MBOX: case MUTT_MMDF: + case MUTT_MAILDIR: + case MUTT_MH: case MUTT_NOTMUCH: if (mx_mbox_check_stats(m, 0)) MailboxCount++; diff --git a/maildir/lib.h b/maildir/lib.h index 17ada5e7e..cb180a2db 100644 --- a/maildir/lib.h +++ b/maildir/lib.h @@ -58,7 +58,6 @@ extern struct MxOps mx_maildir_ops; extern struct MxOps mx_mh_ops; int maildir_check_empty (const char *path); -int maildir_check (struct Mailbox *m, bool check_stats); void maildir_gen_flags (char *dest, size_t destlen, struct Email *e); FILE * maildir_open_find_message(const char *folder, const char *msg, char **newname); void maildir_parse_flags (struct Email *e, const char *path); @@ -66,7 +65,6 @@ struct Email *maildir_parse_message (enum MailboxType magic, const char *fnam struct Email *maildir_parse_stream (enum MailboxType magic, FILE *f, const char *fname, bool is_old, struct Email *e); bool maildir_update_flags (struct Mailbox *m, struct Email *o, struct Email *n); int mh_check_empty (const char *path); -bool mh_mailbox (struct Mailbox *m, bool check_stats); #ifdef USE_HCACHE int mh_sync_mailbox_message (struct Mailbox *m, int msgno, header_cache_t *hc); #else diff --git a/maildir/maildir.c b/maildir/maildir.c index 53cdba349..204b16da2 100644 --- a/maildir/maildir.c +++ b/maildir/maildir.c @@ -543,6 +543,31 @@ int maildir_mbox_check(struct Context *ctx, int *index_hint) return 0; } +/** + * maildir_mbox_check_stats - Implements MxOps::mbox_check_stats + */ +static int maildir_mbox_check_stats(struct Mailbox *m, int flags) +{ + if (!m) + return -1; + + bool check_stats = true; + bool check_new = true; + + m->msg_count = 0; + m->msg_unread = 0; + m->msg_flagged = 0; + m->msg_new = 0; + + maildir_check_dir(m, "new", check_new, check_stats); + + check_new = !m->has_new && MaildirCheckCur; + if (check_new || check_stats) + maildir_check_dir(m, "cur", check_new, check_stats); + + return 0; +} + /** * maildir_msg_open - Implements MxOps::msg_open() */ @@ -671,6 +696,7 @@ struct MxOps mx_maildir_ops = { .mbox_open = maildir_mbox_open, .mbox_open_append = maildir_mbox_open_append, .mbox_check = maildir_mbox_check, + .mbox_check_stats = maildir_mbox_check_stats, .mbox_sync = mh_mbox_sync, .mbox_close = mh_mbox_close, .msg_open = maildir_msg_open, diff --git a/maildir/mh.c b/maildir/mh.c index 4fa77503d..2974f5863 100644 --- a/maildir/mh.c +++ b/maildir/mh.c @@ -416,12 +416,9 @@ bool mh_valid_message(const char *s) } /** - * mh_mailbox - Check for new mail for a mh mailbox - * @param m Mailbox to check - * @param check_stats Also count total, new, and flagged messages - * @retval true if the mailbox has new mail + * mh_mbox_check_stats - Implements MxOps::check_stats */ -bool mh_mailbox(struct Mailbox *m, bool check_stats) +static int mh_mbox_check_stats(struct Mailbox *m, int flags) { struct MhSequences mhs = { 0 }; bool check_new = true; @@ -437,27 +434,23 @@ bool mh_mailbox(struct Mailbox *m, bool check_stats) check_new = false; } - if (!(check_new || check_stats)) - return rc; + if (!check_new) + return 0; if (mh_read_sequences(&mhs, m->path) < 0) return false; - if (check_stats) - { - m->msg_count = 0; - m->msg_unread = 0; - m->msg_flagged = 0; - } + m->msg_count = 0; + m->msg_unread = 0; + m->msg_flagged = 0; for (int i = mhs.max; i > 0; i--) { - if (check_stats && (mhs_check(&mhs, i) & MH_SEQ_FLAGGED)) + if ((mhs_check(&mhs, i) & MH_SEQ_FLAGGED)) m->msg_flagged++; if (mhs_check(&mhs, i) & MH_SEQ_UNSEEN) { - if (check_stats) - m->msg_unread++; + m->msg_unread++; if (check_new) { /* if the first unseen message we encounter was in the m during the @@ -471,27 +464,23 @@ bool mh_mailbox(struct Mailbox *m, bool check_stats) * checking for new mail after the first unseen message. * Whether it resulted in "new mail" or not. */ check_new = false; - if (!check_stats) - break; } } } + mhs_free_sequences(&mhs); - if (check_stats) + dirp = opendir(m->path); + if (dirp) { - dirp = opendir(m->path); - if (dirp) + while ((de = readdir(dirp))) { - while ((de = readdir(dirp))) - { - if (*de->d_name == '.') - continue; - if (mh_valid_message(de->d_name)) - m->msg_count++; - } - closedir(dirp); + if (*de->d_name == '.') + continue; + if (mh_valid_message(de->d_name)) + m->msg_count++; } + closedir(dirp); } return rc; @@ -819,6 +808,7 @@ struct MxOps mx_mh_ops = { .mbox_open = mh_mbox_open, .mbox_open_append = mh_mbox_open_append, .mbox_check = mh_mbox_check, + .mbox_check_stats = mh_mbox_check_stats, .mbox_sync = mh_mbox_sync, .mbox_close = mh_mbox_close, .msg_open = mh_msg_open, diff --git a/maildir/shared.c b/maildir/shared.c index 9b59960e8..de7e7e1fe 100644 --- a/maildir/shared.c +++ b/maildir/shared.c @@ -1864,32 +1864,3 @@ int mh_msg_close(struct Mailbox *m, struct Message *msg) { return mutt_file_fclose(&msg->fp); } - -/** - * maildir_check - Check for new mail in a maildir mailbox - * @param m Mailbox to check - * @param check_stats if true, also count total, new, and flagged messages - * @retval 1 if the mailbox has new mail - */ -int maildir_check(struct Mailbox *m, bool check_stats) -{ - int rc = 1; - bool check_new = true; - - if (check_stats) - { - m->msg_count = 0; - m->msg_unread = 0; - m->msg_flagged = 0; - m->msg_new = 0; - } - - rc = maildir_check_dir(m, "new", check_new, check_stats); - - check_new = !rc && MaildirCheckCur; - if (check_new || check_stats) - if (maildir_check_dir(m, "cur", check_new, check_stats)) - rc = 1; - - return rc; -}