]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/imap/serv_imap.c
IMAP server: suppress untagged 'EXISTS' and 'EXPUNGE' responses
[citadel.git] / citadel / modules / imap / serv_imap.c
index ca4acfb6c38dca00a0ad52381d67f5dd244d11e7..b6ec6e5c5b4b051d312c233294cc03affc59ea26 100644 (file)
@@ -35,6 +35,7 @@
 #include <ctype.h>
 #include <string.h>
 #include <limits.h>
+#include <libcitadel.h>
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
@@ -45,7 +46,6 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
-#include "tools.h"
 #include "internet_addressing.h"
 #include "serv_imap.h"
 #include "imap_tools.h"
@@ -435,7 +435,7 @@ void imap_cleanup_function(void)
  * output this stuff in other places as well)
  */
 void imap_output_capability_string(void) {
-       cprintf("CAPABILITY IMAP4REV1 NAMESPACE ID AUTH=PLAIN AUTH=LOGIN");
+       cprintf("CAPABILITY IMAP4REV1 NAMESPACE ID AUTH=PLAIN AUTH=LOGIN UIDPLUS");
 
 #ifdef HAVE_OPENSSL
        if (!CC->redirect_ssl) cprintf(" STARTTLS");
@@ -491,7 +491,7 @@ void imap_greeting(void)
 {
 
        strcpy(CC->cs_clientname, "IMAP session");
-       IMAP = malloc(sizeof (struct citimap));
+       CC->session_specific_data = malloc(sizeof(struct citimap));
        memset(IMAP, 0, sizeof(struct citimap));
        IMAP->authstate = imap_as_normal;
        IMAP->cached_rfc822_data = NULL;
@@ -508,6 +508,9 @@ void imap_greeting(void)
  */
 void imaps_greeting(void) {
        CtdlModuleStartCryptoMsgs(NULL, NULL, NULL);
+#ifdef HAVE_OPENSSL
+       if (!CC->redirect_ssl) CC->kill_me = 1;         /* kill session if no crypto */
+#endif
        imap_greeting();
 }
 
@@ -554,7 +557,7 @@ void imap_authenticate(int num_parms, char *parms[])
        }
 
        if (!strcasecmp(parms[2], "LOGIN")) {
-               CtdlEncodeBase64(buf, "Username:", 9);
+               CtdlEncodeBase64(buf, "Username:", 9, 0);
                cprintf("+ %s\r\n", buf);
                IMAP->authstate = imap_as_expecting_username;
                strcpy(IMAP->authseq, parms[0]);
@@ -562,7 +565,7 @@ void imap_authenticate(int num_parms, char *parms[])
        }
 
        if (!strcasecmp(parms[2], "PLAIN")) {
-               // CtdlEncodeBase64(buf, "Username:", 9);
+               // CtdlEncodeBase64(buf, "Username:", 9, 0);
                // cprintf("+ %s\r\n", buf);
                cprintf("+ \r\n");
                IMAP->authstate = imap_as_expecting_plainauth;
@@ -613,7 +616,7 @@ void imap_auth_login_user(char *cmd)
 
        CtdlDecodeBase64(buf, cmd, SIZ);
        CtdlLoginExistingUser(NULL, buf);
-       CtdlEncodeBase64(buf, "Password:", 9);
+       CtdlEncodeBase64(buf, "Password:", 9, 0);
        cprintf("+ %s\r\n", buf);
        IMAP->authstate = imap_as_expecting_password;
        return;
@@ -735,7 +738,7 @@ void imap_select(int num_parms, char *parms[])
        cprintf("* %d EXISTS\r\n", msgs);
        cprintf("* %d RECENT\r\n", new);
 
-       cprintf("* OK [UIDVALIDITY 1] UID validity status\r\n");
+       cprintf("* OK [UIDVALIDITY %ld] UID validity status\r\n", GLOBAL_UIDVALIDITY_VALUE);
        cprintf("* OK [UIDNEXT %ld] Predicted next UID\r\n", CitControl.MMhighest + 1);
 
        /* Note that \Deleted is a valid flag, but not a permanent flag,
@@ -1367,19 +1370,24 @@ void imap_command_loop(void)
                return;
        }
 
-       /* Ok, at this point we're in normal command mode.  The first thing
-        * we do is print any incoming pages (yeah! we really do!)
-        */
-       imap_print_instant_messages();
 
-       /*
-        * Before processing the command that was just entered... if we happen
-        * to have a folder selected, we'd like to rescan that folder for new
-        * messages, and for deletions/changes of existing messages.  This
-        * could probably be optimized somehow, but IMAP sucks...
+       /* Ok, at this point we're in normal command mode.
+        * If the command just submitted does not contain a literal, we
+        * might think about delivering some untagged stuff...
         */
-       if (IMAP->selected) {
-               imap_rescan_msgids();
+       if (cmdbuf[strlen(cmdbuf)-1] != '}') {
+
+               imap_print_instant_messages();
+       
+               /*
+                * Before processing the command that was just entered... if we happen
+                * to have a folder selected, we'd like to rescan that folder for new
+                * messages, and for deletions/changes of existing messages.  This
+                * could probably be optimized somehow, but IMAP sucks...
+                */
+               if (IMAP->selected) {
+                       imap_rescan_msgids();
+               }
        }
 
        /* Now for the command set. */
@@ -1549,8 +1557,7 @@ void imap_command_loop(void)
                imap_copy(num_parms, parms);
        }
 
-       else if ((!strcasecmp(parms[1], "UID"))
-                && (!strcasecmp(parms[2], "COPY"))) {
+       else if ((!strcasecmp(parms[1], "UID")) && (!strcasecmp(parms[2], "COPY"))) {
                imap_uidcopy(num_parms, parms);
        }
 
@@ -1558,6 +1565,10 @@ void imap_command_loop(void)
                imap_expunge(num_parms, parms);
        }
 
+       else if ((!strcasecmp(parms[1], "UID")) && (!strcasecmp(parms[2], "EXPUNGE"))) {
+               imap_expunge(num_parms, parms);
+       }
+
        else if (!strcasecmp(parms[1], "CLOSE")) {
                imap_close(num_parms, parms);
        }
@@ -1590,14 +1601,17 @@ const char *CitadelServiceIMAPS="IMAPS";
  */
 CTDL_MODULE_INIT(imap)
 {
-       CtdlRegisterServiceHook(config.c_imap_port,
-                               NULL, imap_greeting, imap_command_loop, NULL, CitadelServiceIMAP);
+       if (!threading)
+       {
+               CtdlRegisterServiceHook(config.c_imap_port,
+                                       NULL, imap_greeting, imap_command_loop, NULL, CitadelServiceIMAP);
 #ifdef HAVE_OPENSSL
-       CtdlRegisterServiceHook(config.c_imaps_port,
-                               NULL, imaps_greeting, imap_command_loop, NULL, CitadelServiceIMAPS);
+               CtdlRegisterServiceHook(config.c_imaps_port,
+                                       NULL, imaps_greeting, imap_command_loop, NULL, CitadelServiceIMAPS);
 #endif
-       CtdlRegisterSessionHook(imap_cleanup_function, EVT_STOP);
-
+               CtdlRegisterSessionHook(imap_cleanup_function, EVT_STOP);
+       }
+       
        /* return our Subversion id for the Log */
        return "$Id$";
 }