Began merging the code for IMAP LIST and LSUB
authorArt Cancro <ajc@citadel.org>
Thu, 26 Apr 2007 15:33:40 +0000 (15:33 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 26 Apr 2007 15:33:40 +0000 (15:33 +0000)
commands into a single code path, in anticipation of implementing
the LIST-EXTENDED extension.

citadel/serv_imap.c

index 5b95ae63ee707124f97118ffde0d34f58becff30..616538ddcb4e630e7462013878ac34c329a8cdc1 100644 (file)
@@ -864,32 +864,6 @@ void imap_lsub_listroom(struct ctdlroom *qrbuf, void *data)
 }
 
 
-/*
- * Implements the LSUB command
- */
-void imap_lsub(int num_parms, char *parms[])
-{
-       char pattern[SIZ];
-       if (num_parms < 4) {
-               cprintf("%s BAD arguments invalid\r\n", parms[0]);
-               return;
-       }
-       snprintf(pattern, sizeof pattern, "%s%s", parms[2], parms[3]);
-
-       if (strlen(parms[3]) == 0) {
-               cprintf("* LIST (\\Noselect) \"/\" \"\"\r\n");
-       }
-
-       else {
-               imap_list_floors("LSUB", pattern);
-               ForEachRoom(imap_lsub_listroom, pattern);
-       }
-
-       cprintf("%s OK LSUB completed\r\n", parms[0]);
-}
-
-
-
 /*
  * Back end for imap_list()
  */
@@ -916,27 +890,48 @@ void imap_list_listroom(struct ctdlroom *qrbuf, void *data)
 
 
 /*
- * Implements the LIST command
+ * Implements the LIST and LSUB commands
  */
 void imap_list(int num_parms, char *parms[])
 {
        char pattern[SIZ];
+       int subscribed_rooms_only = 0;
+       char verb[16];
+       int i, j;
+
        if (num_parms < 4) {
                cprintf("%s BAD arguments invalid\r\n", parms[0]);
                return;
        }
+
+       /* parms[1] is the IMAP verb being used (e.g. LIST or LSUB)
+        * This tells us how to behave, and what verb to return back to the caller
+        */
+       safestrncpy(verb, parms[1], sizeof verb);
+       j = strlen(verb);
+       for (i=0; i<j; ++i) {
+               verb[i] = toupper(verb[i]);
+       }
+
+       if (!strcasecmp(verb, "LSUB")) {
+               subscribed_rooms_only = 1;
+       }
+
        snprintf(pattern, sizeof pattern, "%s%s", parms[2], parms[3]);
 
        if (strlen(parms[3]) == 0) {
-               cprintf("* LIST (\\Noselect) \"/\" \"\"\r\n");
+               cprintf("* %s (\\Noselect) \"/\" \"\"\r\n", verb);
        }
 
        else {
-               imap_list_floors("LIST", pattern);
-               ForEachRoom(imap_list_listroom, pattern);
+               imap_list_floors(verb, pattern);
+               ForEachRoom(
+                       (subscribed_rooms_only ? imap_lsub_listroom : imap_list_listroom),
+                       pattern
+               );
        }
 
-       cprintf("%s OK LIST completed\r\n", parms[0]);
+       cprintf("%s OK %s completed\r\n", parms[0], verb);
 }
 
 
@@ -1517,7 +1512,7 @@ void imap_command_loop(void)
        }
 
        else if (!strcasecmp(parms[1], "LSUB")) {
-               imap_lsub(num_parms, parms);
+               imap_list(num_parms, parms);
        }
 
        else if (!strcasecmp(parms[1], "LIST")) {