Moved IMAP LIST/LSUB to a separate source file
authorArt Cancro <ajc@citadel.org>
Thu, 26 Apr 2007 21:26:48 +0000 (21:26 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 26 Apr 2007 21:26:48 +0000 (21:26 +0000)
citadel/Makefile.in
citadel/imap_list.c [new file with mode: 0644]
citadel/imap_list.h [new file with mode: 0644]
citadel/serv_imap.c

index 213cb4594be037fefe4794d35a32c2a1ec5038dd..9d8e19cea995ca748f1a6d7cb2fc71d0ba35da35 100644 (file)
@@ -35,7 +35,7 @@ SERV_MODULES=serv_chat.o \
        serv_vcard.o vcard.o \
        serv_mrtg.o \
        serv_imap.o imap_fetch.o imap_misc.o imap_search.o \
-               imap_store.o imap_acl.o imap_tools.o \
+               imap_store.o imap_acl.o imap_tools.o imap_list.o \
        serv_fulltext.o ft_wordbreaker.o crc16.o \
        serv_network.o \
        serv_listsub.o \
@@ -106,7 +106,7 @@ SOURCES=aidepost.c auth.c base64.c chkpwd.c citadel.c citadel_ipc.c \
        serv_sieve.c serv_funambol.c setup.c snprintf.c imap_acl.c \
        stress.c support.c sysdep.c tools.c user_ops.c userlist.c \
        whobbs.c vcard.c serv_notes.c serv_fulltext.c ft_wordbreaker.c \
-       crc16.c journaling.c citadel_dirs.c
+       crc16.c journaling.c citadel_dirs.c imap_list.c
 
 DEP_FILES=$(SOURCES:.c=.d)
 
diff --git a/citadel/imap_list.c b/citadel/imap_list.c
new file mode 100644 (file)
index 0000000..aca8a65
--- /dev/null
@@ -0,0 +1,183 @@
+/*
+ * $Id$ 
+ *
+ * Implements the LIST and LSUB commands.
+ *
+ * Copyright (C) 2000-2007 by Art Cancro and others.
+ * This code is released under the terms of the GNU General Public License.
+ *
+ */
+
+#include "sysdep.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <pwd.h>
+#include <errno.h>
+#include <sys/types.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+#include <sys/wait.h>
+#include <ctype.h>
+#include <string.h>
+#include <limits.h>
+#include "citadel.h"
+#include "server.h"
+#include "sysdep_decls.h"
+#include "citserver.h"
+#include "support.h"
+#include "config.h"
+#include "serv_extensions.h"
+#include "room_ops.h"
+#include "user_ops.h"
+#include "policy.h"
+#include "database.h"
+#include "msgbase.h"
+#include "tools.h"
+#include "internet_addressing.h"
+#include "serv_imap.h"
+#include "imap_tools.h"
+#include "imap_fetch.h"
+#include "imap_search.h"
+#include "imap_store.h"
+#include "imap_acl.h"
+#include "imap_misc.h"
+
+#ifdef HAVE_OPENSSL
+#include "serv_crypto.h"
+#endif
+
+/*
+ * Used by LIST and LSUB to show the floors in the listing
+ */
+void imap_list_floors(char *verb, char *pattern)
+{
+       int i;
+       struct floor *fl;
+
+       for (i = 0; i < MAXFLOORS; ++i) {
+               fl = cgetfloor(i);
+               if (fl->f_flags & F_INUSE) {
+                       if (imap_mailbox_matches_pattern
+                           (pattern, fl->f_name)) {
+                               cprintf("* %s (\\NoSelect) \"/\" ", verb);
+                               imap_strout(fl->f_name);
+                               cprintf("\r\n");
+                       }
+               }
+       }
+}
+
+
+/*
+ * Back end for imap_list()
+ *
+ * Implementation note: IMAP "subscribed folder" is equivalent to Citadel "known room"
+ *
+ * The "user data" field is actually an array of pointers; see below for the breakdown
+ *
+ */
+void imap_list_listroom(struct ctdlroom *qrbuf, void *data)
+{
+       char buf[SIZ];
+       int ra;
+       int yes_output_this_room;
+
+       char **data_for_callback;
+       char *pattern;
+       char *verb;
+       int subscribed_rooms_only;
+
+       /* Here's how we break down the array of pointers passed to us */
+       data_for_callback = data;
+       pattern = data_for_callback[0];
+       verb = data_for_callback[1];
+       subscribed_rooms_only = (int) data_for_callback[2];
+
+       /* Only list rooms to which the user has access!! */
+       yes_output_this_room = 0;
+       CtdlRoomAccess(qrbuf, &CC->user, &ra, NULL);
+
+       if (subscribed_rooms_only) {
+               if (ra & UA_KNOWN) {
+                       yes_output_this_room = 1;
+               }
+       }
+       else {
+               if ((ra & UA_KNOWN) || ((ra & UA_GOTOALLOWED) && (ra & UA_ZAPPED))) {
+                       yes_output_this_room = 1;
+               }
+       }
+
+       if (yes_output_this_room) {
+               imap_mailboxname(buf, sizeof buf, qrbuf);
+               if (imap_mailbox_matches_pattern(pattern, buf)) {
+                       cprintf("* %s () \"/\" ", verb);
+                       imap_strout(buf);
+                       cprintf("\r\n");
+               }
+       }
+}
+
+
+/*
+ * 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;
+
+       char *data_for_callback[3];
+
+       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]);
+
+       data_for_callback[0] = pattern;
+       data_for_callback[1] = verb;
+       data_for_callback[2] = (char *) subscribed_rooms_only;
+
+       if (strlen(parms[3]) == 0) {
+               cprintf("* %s (\\Noselect) \"/\" \"\"\r\n", verb);
+       }
+
+       else {
+               imap_list_floors(verb, pattern);
+               ForEachRoom(imap_list_listroom, data_for_callback);
+       }
+
+       cprintf("%s OK %s completed\r\n", parms[0], verb);
+}
+
+
diff --git a/citadel/imap_list.h b/citadel/imap_list.h
new file mode 100644 (file)
index 0000000..01a790f
--- /dev/null
@@ -0,0 +1,6 @@
+/*
+ * $Id$
+ */
+
+
+void imap_list(int num_parms, char *parms[]);
index 128ac1e4e0720d1790920243972f0c7530913a9f..bb28d45eb4cfb7daa29cd545a5abcab86a91bd46 100644 (file)
@@ -51,6 +51,7 @@
 #include "internet_addressing.h"
 #include "serv_imap.h"
 #include "imap_tools.h"
+#include "imap_list.h"
 #include "imap_fetch.h"
 #include "imap_search.h"
 #include "imap_store.h"
@@ -814,129 +815,6 @@ void imap_namespace(int num_parms, char *parms[])
 
 
 
-/*
- * Used by LIST and LSUB to show the floors in the listing
- */
-void imap_list_floors(char *verb, char *pattern)
-{
-       int i;
-       struct floor *fl;
-
-       for (i = 0; i < MAXFLOORS; ++i) {
-               fl = cgetfloor(i);
-               if (fl->f_flags & F_INUSE) {
-                       if (imap_mailbox_matches_pattern
-                           (pattern, fl->f_name)) {
-                               cprintf("* %s (\\NoSelect) \"/\" ", verb);
-                               imap_strout(fl->f_name);
-                               cprintf("\r\n");
-                       }
-               }
-       }
-}
-
-
-/*
- * Back end for imap_list()
- *
- * Implementation note: IMAP "subscribed folder" is equivalent to Citadel "known room"
- *
- * The "user data" field is actually an array of pointers; see below for the breakdown
- *
- */
-void imap_list_listroom(struct ctdlroom *qrbuf, void *data)
-{
-       char buf[SIZ];
-       int ra;
-       int yes_output_this_room;
-
-       char **data_for_callback;
-       char *pattern;
-       char *verb;
-       int subscribed_rooms_only;
-
-       /* Here's how we break down the array of pointers passed to us */
-       data_for_callback = data;
-       pattern = data_for_callback[0];
-       verb = data_for_callback[1];
-       subscribed_rooms_only = (int) data_for_callback[2];
-
-       /* Only list rooms to which the user has access!! */
-       yes_output_this_room = 0;
-       CtdlRoomAccess(qrbuf, &CC->user, &ra, NULL);
-
-       if (subscribed_rooms_only) {
-               if (ra & UA_KNOWN) {
-                       yes_output_this_room = 1;
-               }
-       }
-       else {
-               if ((ra & UA_KNOWN) || ((ra & UA_GOTOALLOWED) && (ra & UA_ZAPPED))) {
-                       yes_output_this_room = 1;
-               }
-       }
-
-       if (yes_output_this_room) {
-               imap_mailboxname(buf, sizeof buf, qrbuf);
-               if (imap_mailbox_matches_pattern(pattern, buf)) {
-                       cprintf("* %s () \"/\" ", verb);
-                       imap_strout(buf);
-                       cprintf("\r\n");
-               }
-       }
-}
-
-
-/*
- * 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;
-
-       char *data_for_callback[3];
-
-       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]);
-
-       data_for_callback[0] = pattern;
-       data_for_callback[1] = verb;
-       data_for_callback[2] = (char *) subscribed_rooms_only;
-
-       if (strlen(parms[3]) == 0) {
-               cprintf("* %s (\\Noselect) \"/\" \"\"\r\n", verb);
-       }
-
-       else {
-               imap_list_floors(verb, pattern);
-               ForEachRoom(imap_list_listroom, data_for_callback);
-       }
-
-       cprintf("%s OK %s completed\r\n", parms[0], verb);
-}
-
-
-
 /*
  * Implements the CREATE command
  *