]> code.citadel.org Git - citadel.git/commitdiff
* Slowly and painfully writing IMAP support
authorArt Cancro <ajc@citadel.org>
Thu, 5 Oct 2000 22:23:17 +0000 (22:23 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 5 Oct 2000 22:23:17 +0000 (22:23 +0000)
citadel/ChangeLog
citadel/imap_tools.c
citadel/imap_tools.h
citadel/serv_imap.c
citadel/serv_imap.h

index dced25ec17c9c5a82d325cd81f6427c2f8478e33..0701c444f7e6642e7b6b9825539a254da9e36c04 100644 (file)
@@ -1,4 +1,7 @@
  $Log$
+ Revision 573.8  2000/10/05 22:23:16  ajc
+ * Slowly and painfully writing IMAP support
+
  Revision 573.7  2000/10/04 22:39:06  ajc
  * Added skeleton versions of the LIST and LSUB commands to the imap server
 
@@ -2077,4 +2080,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
-
index 05bfe3230021973e1ce9a81bf32c681c2cb00605..1f381526ed912a34ab2d5cfd50636d112407eabe 100644 (file)
@@ -9,6 +9,8 @@
 #include <unistd.h>
 #include <ctype.h>
 #include <string.h>
+#include "citadel.h"
+#include "tools.h"
 #include "imap_tools.h"
 
 /*
@@ -52,5 +54,14 @@ int imap_parameterize(char **args, char *buf) {
        return(num);
 }
                        
+/*
+ * Convert a struct quickroom to an IMAP-compatible mailbox name.
+ */
+void imap_mailboxname(char *buf, int bufsize, struct quickroom *qrbuf) {
 
-
+       safestrncpy(buf, qrbuf->QRname, bufsize);
+       if (qrbuf->QRflags & QR_MAILBOX) {
+               strcpy(buf, &buf[11]);
+               if (!strcasecmp(buf, MAILROOM)) strcpy(buf, "INBOX");
+       }
+}
index 0f53a09348ce42a48cc522cff0cf1482b2b7f41a..d363cd8c2ea2523e3a796c4e4dc7b0399b835ba3 100644 (file)
@@ -4,3 +4,4 @@
  */
 
 int imap_parameterize(char **args, char *buf);
+void imap_mailboxname(char *buf, int bufsize, struct quickroom *qrbuf);
index 89e41bd207526618caab4d412e24376ed79587ba..05ccac112cec38651acaa099cc3f97db84d76c05 100644 (file)
 long SYM_IMAP;
 
 
+/*
+ * If there is a message ID map in memory, free it
+ */
+void imap_free_msgids(void) {
+       if (IMAP->msgids != NULL) {
+               phree(IMAP->msgids);
+               IMAP->msgids = NULL;
+               IMAP->num_msgs = 0;
+       }
+}
+
+
+/*
+ * Back end for imap_load_msgids()
+ *
+ * FIXME: this should be optimized by figuring out a way to allocate memory
+ * once rather than doing a reallok() for each message.
+ */
+void imap_add_single_msgid(long msgnum, void *userdata) {
+       
+       IMAP->num_msgs = IMAP->num_msgs + 1;
+       if (IMAP->msgids == NULL) {
+               IMAP->msgids = mallok(IMAP->num_msgs * sizeof(long));
+       }
+       else {
+               IMAP->msgids = reallok(IMAP->msgids,
+                       IMAP->num_msgs * sizeof(long));
+       }
+       IMAP->msgids[IMAP->num_msgs - 1] = msgnum;
+}
+
+
+
+/*
+ * Set up a message ID map for the current room (folder)
+ */
+void imap_load_msgids(void) {
+        
+       if (IMAP->selected == 0) {
+               lprintf(5, "imap_load_msgids() can't run; no room selected\n");
+               return;
+       }
+
+       imap_free_msgids();     /* If there was already a map, free it */
+
+       CtdlForEachMessage(MSGS_ALL, 0L, (-63), NULL, NULL,
+               imap_add_single_msgid, NULL);
+
+       lprintf(9, "imap_load_msgids() mapped %d messages\n", IMAP->num_msgs);
+}
+
+
+
+
 /*
  * This cleanup function blows away the temporary memory and files used by
  * the IMAP server.
@@ -56,8 +110,7 @@ void imap_cleanup_function(void) {
        if (CC->h_command_function != imap_command_loop) return;
 
        lprintf(9, "Performing IMAP cleanup hook\n");
-
-
+       imap_free_msgids();
        lprintf(9, "Finished IMAP cleanup hook\n");
 }
 
@@ -167,6 +220,8 @@ void imap_select(int num_parms, char *parms[]) {
                IMAP->readonly = 0;
        }
 
+       imap_load_msgids();
+
        /* FIXME ... much more info needs to be supplied here */
        cprintf("* %d EXISTS\r\n", msgs);
        cprintf("* %d RECENT\r\n", new);
@@ -185,6 +240,7 @@ void imap_select(int num_parms, char *parms[]) {
 void imap_close(int num_parms, char *parms[]) {
        IMAP->selected = 0;
        IMAP->readonly = 0;
+       imap_free_msgids();
        cprintf("%s OK CLOSE completed\r\n", parms[0]);
 }
 
@@ -196,14 +252,19 @@ void imap_close(int num_parms, char *parms[]) {
  * Back end for imap_lsub()
  */
 void imap_lsub_listroom(struct quickroom *qrbuf, void *data) {
-       cprintf("* LSUB () \"|\" %s\r\n", qrbuf->QRname);
+       char buf[256];
+       
+       imap_mailboxname(buf, sizeof buf, qrbuf);
+       cprintf("* LSUB () \"|\" \"%s\"\r\n", buf);
 }
 
 
 /*
  * Implements the LSUB command
  *
- * FIXME: Handle wildcards, please.  Handle subscriptions, for that matter.
+ * FIXME: Handle wildcards, please.
+ * FIXME: Currently we show all rooms as subscribed folders.  Need to handle
+ *        subscriptions properly.
  */
 void imap_lsub(int num_parms, char *parms[]) {
        ForEachRoom(imap_lsub_listroom, NULL);
@@ -216,7 +277,10 @@ void imap_lsub(int num_parms, char *parms[]) {
  * Back end for imap_list()
  */
 void imap_list_listroom(struct quickroom *qrbuf, void *data) {
-       cprintf("* LIST () \"|\" %s\r\n", qrbuf->QRname);
+       char buf[256];
+       
+       imap_mailboxname(buf, sizeof buf, qrbuf);
+       cprintf("* LIST () \"|\" \"%s\"\r\n", buf);
 }
 
 
@@ -227,7 +291,6 @@ void imap_list_listroom(struct quickroom *qrbuf, void *data) {
  */
 void imap_list(int num_parms, char *parms[]) {
        ForEachRoom(imap_list_listroom, NULL);
-       cprintf("* LIST () \"|\" INBOX\r\n");
        cprintf("%s OK LIST completed\r\n", parms[0]);
 }
 
index 3a3b57e88d1352ca0923ec383d9cf4f98bad8816..b332ee326f0dd5a905edb8c3f1c3f269cc75bf1f 100644 (file)
@@ -12,6 +12,8 @@ void imap_command_loop(void);
 struct citimap {
        int selected;           /* set to 1 if in the SELECTED state */
        int readonly;           /* mailbox is open read only */
+       int num_msgs;           /* Number of messages being mapped */
+       long *msgids;
 };
 
 #define IMAP ((struct citimap *)CtdlGetUserData(SYM_IMAP))