From: Brendan Cully Date: Tue, 3 Apr 2007 02:19:55 +0000 (-0700) Subject: Add hook for proper IMAP unseen count in mailbox browser X-Git-Tag: mutt-1-5-15-rel~31 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=92ff5e5b541eb0bdf6b2f5c79d9892b97c0efd2a;p=mutt Add hook for proper IMAP unseen count in mailbox browser --- diff --git a/browser.c b/browser.c index c200b942..9a377bd3 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 52ede51e..5d3f977e 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 a41e98c0..3ca44458 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 9bfea6fc..ed59566b 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);