From 47cf165600e2f6d2bd3ffc0519e0ddf0dd7e49e8 Mon Sep 17 00:00:00 2001 From: Brendan Cully Date: Mon, 2 Apr 2007 19:19:55 -0700 Subject: [PATCH] Add hook for proper IMAP unseen count in mailbox browser --- browser.c | 6 +++++- browser.h | 6 ++++++ imap/browse.c | 29 +++++++++++++++++++++++++++++ imap/imap.h | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/browser.c b/browser.c index c200b9423..9a377bd3a 100644 --- a/browser.c +++ b/browser.c @@ -426,6 +426,9 @@ static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state) struct stat s; char buffer[LONG_STRING]; BUFFY *tmp = Incoming; +#ifdef USE_IMAP + struct mailbox_state mbox; +#endif if (!Incoming) return (-1); @@ -438,7 +441,8 @@ static int examine_mailboxes (MUTTMENU *menu, struct browser_state *state) #ifdef USE_IMAP if (mx_is_imap (tmp->path)) { - add_folder (menu, state, tmp->path, NULL, tmp->new); + imap_mailbox_state (tmp->path, &mbox); + add_folder (menu, state, tmp->path, NULL, mbox.new); continue; } #endif diff --git a/browser.h b/browser.h index 52ede51eb..5d3f977e6 100644 --- a/browser.h +++ b/browser.h @@ -55,4 +55,10 @@ struct browser_state #endif }; +struct mailbox_state +{ + unsigned int new; + unsigned int old; + unsigned int messages; +}; #endif /* _BROWSER_H */ diff --git a/imap/browse.c b/imap/browse.c index a41e98c01..3ca444582 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -253,6 +253,35 @@ int imap_browse (char* path, struct browser_state* state) return -1; } +int imap_mailbox_state (const char* path, struct mailbox_state* state) +{ + IMAP_DATA* idata; + IMAP_MBOX mx; + IMAP_STATUS* status; + + memset (state, 0, sizeof (*state)); + if (imap_parse_path (path, &mx) < 0) + { + dprint (1, (debugfile, "imap_mailbox_state: bad path %s\n", path)); + return -1; + } + if (!(idata = imap_conn_find (&mx.account, M_IMAP_CONN_NONEW))) + { + dprint (2, (debugfile, "imap_mailbox_state: no open connection for %s\n", + path)); + FREE (&mx.mbox); + return -1; + } + + if ((status = imap_mboxcache_get (idata, mx.mbox, 0))) + { + state->new = status->unseen; + state->messages = status->messages; + } + + return 0; +} + /* imap_mailbox_create: Prompt for a new mailbox name, and try to create it */ int imap_mailbox_create (const char* folder) { diff --git a/imap/imap.h b/imap/imap.h index 9bfea6fc5..ed59566bc 100644 --- a/imap/imap.h +++ b/imap/imap.h @@ -50,6 +50,7 @@ void imap_disallow_reopen (CONTEXT *ctx); /* browse.c */ int imap_browse (char* path, struct browser_state* state); +int imap_mailbox_state (const char* path, struct mailbox_state* state); int imap_mailbox_create (const char* folder); int imap_mailbox_rename (const char* mailbox); -- 2.50.1