<<< Date Index >>>     <<< Thread Index >>>

[PATCH] N flag for IMAP (cvs head)



I've seen some other patches for this, and looking at the code in cvs it
seems someone started on this but never finished.  This patch adds the
ability to see whether there are new messages when browsing imap
folders.  It uses the imap \Marked flag to do this.  Mutt currently has
code to use the flag in browser.c, but the flag never gets set by the
imap library.

It should be possible to find out the number of messages in each imap
folder by using the STATUS command, but that's a task I'll tackle
another day.  Someone else out there has a patch do do this, but it
didn't work for me on the 1.5.x series (it was designed for 1.3.x).

Paul

? stamp-h1
Index: imap/browse.c
===================================================================
RCS file: /home/roessler/cvs/mutt/imap/browse.c,v
retrieving revision 3.3
diff -u -r3.3 browse.c
--- imap/browse.c       19 Sep 2003 13:03:26 -0000      3.3
+++ imap/browse.c       18 Oct 2004 20:51:06 -0000
@@ -29,7 +29,7 @@
 static int browse_add_list_result (IMAP_DATA* idata, const char* cmd,
   struct browser_state* state, short isparent);
 static void imap_add_folder (char delim, char *folder, int noselect,
-  int noinferiors, struct browser_state *state, short isparent);
+  int noinferiors, int marked, struct browser_state *state, short isparent);
 static int compare_names(struct folder_file *a, struct folder_file *b);
 static int browse_get_namespace (IMAP_DATA *idata, char *nsbuf, int nsblen, 
   IMAP_NAMESPACE_INFO *nsi, int nsilen, int *nns);
@@ -57,6 +57,7 @@
   short showparents = 0;
   int noselect;
   int noinferiors;
+  int marked;
   IMAP_MBOX mx;
 
   if (imap_parse_path (path, &mx))
@@ -110,7 +111,7 @@
       do 
       {
         if (imap_parse_list_response (idata, &cur_folder, &noselect,
-            &noinferiors, &idata->delim) != 0)
+            &noinferiors, &marked, &idata->delim) != 0)
          goto fail;
 
         if (cur_folder)
@@ -156,7 +157,7 @@
       if (showparents)
       {
        dprint (3, (debugfile, "imap_init_browse: adding parent %s\n", mbox));
-       imap_add_folder (idata->delim, mbox, 1, 0, state, 1);
+       imap_add_folder (idata->delim, mbox, 1, 0, 0, state, 1);
       }
 
       /* if our target isn't a folder, we are in our superior */
@@ -178,7 +179,7 @@
       /* folder may be "/" */
       snprintf (relpath, sizeof (relpath), "%c" , n < 0 ? '\0' : idata->delim);
       if (showparents)
-        imap_add_folder (idata->delim, relpath, 1, 0, state, 1); 
+        imap_add_folder (idata->delim, relpath, 1, 0, 0, state, 1); 
       if (!state->folder)
       {
         imap_qualify_path (buf, sizeof (buf), &mx, relpath);
@@ -229,7 +230,7 @@
     for (i = 0; i < nns; i++)
       if (nsi[i].listable && !nsi[i].home_namespace) {
        imap_add_folder(nsi[i].delim, nsi[i].prefix, nsi[i].noselect,
-                       nsi[i].noinferiors, state, 0);
+                       nsi[i].noinferiors, nsi[i].marked, state, 0);
        dprint (3, (debugfile, "imap_browse: adding namespace: %s\n",
                    nsi[i].prefix));
       }
@@ -304,6 +305,7 @@
   char *name;
   int noselect;
   int noinferiors;
+  int marked;
   IMAP_MBOX mx;
 
   if (imap_parse_path (state->folder, &mx))
@@ -318,7 +320,7 @@
   do 
   {
     if (imap_parse_list_response(idata, &name, &noselect, &noinferiors,
-        &idata->delim) != 0)
+        &marked, &idata->delim) != 0)
     {
       FREE (&mx.mbox);
       return -1;
@@ -331,8 +333,8 @@
         noselect = 1;
       /* prune current folder from output */
       if (isparent || mutt_strncmp (name, mx.mbox, strlen (name)))
-        imap_add_folder (idata->delim, name, noselect, noinferiors, state,
-          isparent);
+        imap_add_folder (idata->delim, name, noselect, noinferiors, marked,
+          state, isparent);
     }
   }
   while ((ascii_strncmp (idata->cmd.buf, idata->cmd.seq, SEQLEN) != 0));
@@ -344,7 +346,7 @@
 /* imap_add_folder: add a folder name to the browser list, formatting it as
  *   necessary. */
 static void imap_add_folder (char delim, char *folder, int noselect,
-  int noinferiors, struct browser_state *state, short isparent)
+  int noinferiors, int marked, struct browser_state *state, short isparent)
 {
   char tmp[LONG_STRING];
   char relpath[LONG_STRING];
@@ -400,6 +402,7 @@
   (state->entry)[state->entrylen].delim = delim;
   (state->entry)[state->entrylen].selectable = !noselect;
   (state->entry)[state->entrylen].inferiors = !noinferiors;
+  (state->entry)[state->entrylen].new = marked;
   (state->entrylen)++;
 
   FREE (&mx.mbox);
@@ -543,7 +546,7 @@
     do 
     {
       if (imap_parse_list_response(idata, &name, &nsi->noselect,
-          &nsi->noinferiors, &delim) != 0)
+          &nsi->noinferiors, &nsi->marked, &delim) != 0)
        return -1;
       nsi->listable |= (name != NULL);
     }
Index: imap/imap.c
===================================================================
RCS file: /home/roessler/cvs/mutt/imap/imap.c,v
retrieving revision 3.15
diff -u -r3.15 imap.c
--- imap/imap.c 16 Aug 2004 21:36:38 -0000      3.15
+++ imap/imap.c 18 Oct 2004 20:51:06 -0000
@@ -1247,7 +1247,7 @@
  *   code can't possibly handle non-LIST untagged responses properly.
  *   FIXME. ?! */
 int imap_parse_list_response(IMAP_DATA* idata, char **name, int *noselect,
-  int *noinferiors, char *delim)
+  int *noinferiors, int *marked, char *delim)
 {
   char *s;
   long bytes;
@@ -1267,6 +1267,7 @@
   {
     *noselect = 0;
     *noinferiors = 0;
+    *marked = 0;
       
     s = imap_next_word (s); /* flags */
     if (*s == '(')
@@ -1282,6 +1283,8 @@
          *noselect = 1;
        if (!ascii_strncasecmp (s, "\\NoInferiors", 12))
          *noinferiors = 1;
+       if (!ascii_strncasecmp (s, "\\Marked", 7))
+         *marked = 1;
        /* See draft-gahrns-imap-child-mailbox-?? */
        if (!ascii_strncasecmp (s, "\\HasNoChildren", 14))
          *noinferiors = 1;
@@ -1366,7 +1369,7 @@
   char list[LONG_STRING];
   char buf[LONG_STRING];
   char* list_word = NULL;
-  int noselect, noinferiors;
+  int noselect, noinferiors, marked;
   char delim;
   char completion[LONG_STRING];
   int clen, matchlen = 0;
@@ -1404,7 +1407,7 @@
   do
   {
     if (imap_parse_list_response(idata, &list_word, &noselect, &noinferiors,
-        &delim))
+        &marked, &delim))
       break;
 
     if (list_word)
Index: imap/imap_private.h
===================================================================
RCS file: /home/roessler/cvs/mutt/imap/imap_private.h,v
retrieving revision 3.1
diff -u -r3.1 imap_private.h
--- imap/imap_private.h 15 Jul 2003 11:41:32 -0000      3.1
+++ imap/imap_private.h 18 Oct 2004 20:51:06 -0000
@@ -137,6 +137,7 @@
   /* We get these when we check if namespace exists - cache them */
   int noselect;                        
   int noinferiors;
+  int marked;
 } IMAP_NAMESPACE_INFO;
 
 /* IMAP command structure */
@@ -195,7 +196,7 @@
 int imap_open_connection (IMAP_DATA* idata);
 IMAP_DATA* imap_conn_find (const ACCOUNT* account, int flags);
 int imap_parse_list_response(IMAP_DATA* idata, char** name, int* noselect,
-  int* noinferiors, char* delim);
+  int* noinferiors, int* marked, char* delim);
 int imap_read_literal (FILE* fp, IMAP_DATA* idata, long bytes);
 void imap_expunge_mailbox (IMAP_DATA* idata);
 void imap_logout (IMAP_DATA* idata);