]> granicus.if.org Git - mutt/commitdiff
Add hook for proper IMAP unseen count in mailbox browser
authorBrendan Cully <brendan@kublai.com>
Tue, 3 Apr 2007 02:19:55 +0000 (19:19 -0700)
committerBrendan Cully <brendan@kublai.com>
Tue, 3 Apr 2007 02:19:55 +0000 (19:19 -0700)
browser.c
browser.h
imap/browse.c
imap/imap.h

index c200b9423cb3ab0e7da6f904d252451823fa51af..9a377bd3a9d4e7f5f4f8815eada61fc329abe398 100644 (file)
--- 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
index 52ede51eb2d7d79544c6370ec90ee14c24815b86..5d3f977e667f56c10e241e1e50d24f55fc101a80 100644 (file)
--- 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 */
index a41e98c0156899d697781bfdc74bf218291598b2..3ca444582aa2252f273d25c33eabd455f5079c4f 100644 (file)
@@ -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)
 {
index 9bfea6fc50ed4b890d785a7fd3ed1c02ab0c4cf2..ed59566bc60c4c45337cdf8d092a000f72b90879 100644 (file)
@@ -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);