CtdlDeleteMessages() now has a bulk API. Updated all of the
[citadel.git] / citadel / serv_imap.c
index cc442ca8d3f198dad1f87e3b1ad0cf48503e6fec..fd64162af26a53ea7370303c1ae1f09a8ca79263 100644 (file)
@@ -434,7 +434,7 @@ void imap_cleanup_function(void)
  * output this stuff in other places as well)
  */
 void imap_output_capability_string(void) {
-       cprintf("CAPABILITY IMAP4REV1 NAMESPACE AUTH=LOGIN");
+       cprintf("CAPABILITY IMAP4REV1 NAMESPACE ID AUTH=LOGIN");
 #ifdef HAVE_OPENSSL
        if (!CC->redirect_ssl) cprintf(" STARTTLS");
 #endif
@@ -453,6 +453,23 @@ void imap_capability(int num_parms, char *parms[])
 
 
 
+/*
+ * Implements the ID command (specified by RFC2971)
+ *
+ * We ignore the client-supplied information, and output a NIL response.
+ * Although this is technically a valid implementation of the extension, it
+ * is quite useless.  It exists only so that we may see which clients are
+ * making use of this extension.
+ * 
+ */
+void imap_id(int num_parms, char *parms[])
+{
+       cprintf("* ID NIL\r\n");
+       cprintf("%s OK ID completed\r\n", parms[0]);
+}
+
+
+
 /*
  * Here's where our IMAP session begins its happy day.
  */
@@ -688,26 +705,31 @@ void imap_select(int num_parms, char *parms[])
 
 
 /*
- * does the real work for expunge
+ * Does the real work for expunge.
  */
 int imap_do_expunge(void)
 {
        int i;
        int num_expunged = 0;
+       long *delmsgs = NULL;
+       int num_delmsgs = 0;
 
        lprintf(CTDL_DEBUG, "imap_do_expunge() called\n");
        if (IMAP->selected == 0) {
                return (0);
        }
 
-       if (IMAP->num_msgs > 0)
+       if (IMAP->num_msgs > 0) {
+               delmsgs = malloc(IMAP->num_msgs * sizeof(long));
                for (i = 0; i < IMAP->num_msgs; ++i) {
                        if (IMAP->flags[i] & IMAP_DELETED) {
-                               CtdlDeleteMessages(CC->room.QRname,
-                                                  IMAP->msgids[i], "");
-                               ++num_expunged;
+                               delmsgs[num_delmsgs++] = IMAP->msgids[i];
                        }
                }
+               CtdlDeleteMessages(CC->room.QRname, delmsgs, num_delmsgs, "", 1);
+               num_expunged += num_delmsgs;
+               free(delmsgs);
+       }
 
        if (num_expunged > 0) {
                imap_rescan_msgids();
@@ -1378,7 +1400,7 @@ void imap_command_loop(void)
        memset(cmdbuf, 0, sizeof cmdbuf);       /* Clear it, just in case */
        flush_output();
        if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
-               lprintf(CTDL_ERR, "IMAP socket is broken.  Ending session.\r\n");
+               lprintf(CTDL_ERR, "Client disconnected: ending session.\r\n");
                CC->kill_me = 1;
                return;
        }
@@ -1386,7 +1408,7 @@ void imap_command_loop(void)
        if (IMAP->authstate == imap_as_expecting_password) {
                lprintf(CTDL_INFO, "IMAP: <password>\n");
        }
-       else if (bmstrstr(cmdbuf, " LOGIN ", strncasecmp)) {
+       else if (bmstrcasestr(cmdbuf, " LOGIN ")) {
                lprintf(CTDL_INFO, "IMAP: LOGIN...\n");
        }
        else {
@@ -1444,6 +1466,11 @@ void imap_command_loop(void)
                        parms[0]);
        }
 
+       else if (!strcasecmp(parms[1], "ID")) {
+               imap_id(num_parms, parms);
+       }
+
+
        else if (!strcasecmp(parms[1], "LOGOUT")) {
                if (IMAP->selected) {
                        imap_do_expunge();      /* yes, we auto-expunge */