]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_imap.c
* added a comment infront of the svn modifieable returns. Now it will be me listed...
[citadel.git] / citadel / serv_imap.c
index bb28d45eb4cfb7daa29cd545a5abcab86a91bd46..9599d19ed16b450cc1f5d100bebaa2fb055a0147 100644 (file)
@@ -56,6 +56,7 @@
 #include "imap_search.h"
 #include "imap_store.h"
 #include "imap_acl.h"
+#include "imap_metadata.h"
 #include "imap_misc.h"
 
 #ifdef HAVE_OPENSSL
@@ -436,10 +437,19 @@ void imap_cleanup_function(void)
  * output this stuff in other places as well)
  */
 void imap_output_capability_string(void) {
-       cprintf("CAPABILITY IMAP4REV1 NAMESPACE ID ACL AUTH=LOGIN");
+       cprintf("CAPABILITY IMAP4REV1 NAMESPACE ID ACL AUTH=PLAIN AUTH=LOGIN");
+
 #ifdef HAVE_OPENSSL
        if (!CC->redirect_ssl) cprintf(" STARTTLS");
 #endif
+
+       /* We are building a partial implementation of METADATA for the sole purpose
+        * of interoperating with the ical/vcard version of the Bynari Insight Connector.
+        * If you were expecting something else, comment out one or both of these
+        * extension advertisements.
+        */
+       cprintf(" METADATA");
+       /* cprintf(" LIST-EXTENDED"); */
 }
 
 /*
@@ -512,7 +522,7 @@ void imap_login(int num_parms, char *parms[])
                return;
        }
 
-       if (CtdlLoginExistingUser(parms[2]) == login_ok) {
+       if (CtdlLoginExistingUser(NULL, parms[2]) == login_ok) {
                if (CtdlTryPassword(parms[3]) == pass_ok) {
                        cprintf("%s OK [", parms[0]);
                        imap_output_capability_string();
@@ -551,18 +561,58 @@ void imap_authenticate(int num_parms, char *parms[])
                return;
        }
 
+       if (!strcasecmp(parms[2], "PLAIN")) {
+               // CtdlEncodeBase64(buf, "Username:", 9);
+               // cprintf("+ %s\r\n", buf);
+               cprintf("+ \r\n");
+               IMAP->authstate = imap_as_expecting_plainauth;
+               strcpy(IMAP->authseq, parms[0]);
+               return;
+       }
+
        else {
                cprintf("%s NO AUTHENTICATE %s failed\r\n",
                        parms[0], parms[1]);
        }
 }
 
+void imap_auth_plain(char *cmd)
+{
+       char decoded_authstring[1024];
+       char ident[256];
+       char user[256];
+       char pass[256];
+       int result;
+
+       CtdlDecodeBase64(decoded_authstring, cmd, strlen(cmd));
+       safestrncpy(ident, decoded_authstring, sizeof ident);
+       safestrncpy(user, &decoded_authstring[strlen(ident) + 1], sizeof user);
+       safestrncpy(pass, &decoded_authstring[strlen(ident) + strlen(user) + 2], sizeof pass);
+
+       IMAP->authstate = imap_as_normal;
+
+       if (strlen(ident) > 0) {
+               result = CtdlLoginExistingUser(user, ident);
+       }
+       else {
+               result = CtdlLoginExistingUser(NULL, user);
+       }
+
+       if (result == login_ok) {
+               if (CtdlTryPassword(pass) == pass_ok) {
+                       cprintf("%s OK authentication succeeded\r\n", IMAP->authseq);
+                       return;
+               }
+       }
+       cprintf("%s NO authentication failed\r\n", IMAP->authseq);
+}
+
 void imap_auth_login_user(char *cmd)
 {
        char buf[SIZ];
 
        CtdlDecodeBase64(buf, cmd, SIZ);
-       CtdlLoginExistingUser(buf);
+       CtdlLoginExistingUser(NULL, buf);
        CtdlEncodeBase64(buf, "Password:", 9);
        cprintf("+ %s\r\n", buf);
        IMAP->authstate = imap_as_expecting_password;
@@ -575,8 +625,7 @@ void imap_auth_login_pass(char *cmd)
 
        CtdlDecodeBase64(buf, cmd, SIZ);
        if (CtdlTryPassword(buf) == pass_ok) {
-               cprintf("%s OK authentication succeeded\r\n",
-                       IMAP->authseq);
+               cprintf("%s OK authentication succeeded\r\n", IMAP->authseq);
        } else {
                cprintf("%s NO authentication failed\r\n", IMAP->authseq);
        }
@@ -1286,6 +1335,9 @@ void imap_command_loop(void)
        if (IMAP->authstate == imap_as_expecting_password) {
                lprintf(CTDL_INFO, "IMAP: <password>\n");
        }
+       else if (IMAP->authstate == imap_as_expecting_plainauth) {
+               lprintf(CTDL_INFO, "IMAP: <plain_auth>\n");
+       }
        else if (bmstrcasestr(cmdbuf, " LOGIN ")) {
                lprintf(CTDL_INFO, "IMAP: LOGIN...\n");
        }
@@ -1308,6 +1360,10 @@ void imap_command_loop(void)
                imap_auth_login_user(cmdbuf);
                return;
        }
+       if (IMAP->authstate == imap_as_expecting_plainauth) {
+               imap_auth_plain(cmdbuf);
+               return;
+       }
        if (IMAP->authstate == imap_as_expecting_password) {
                imap_auth_login_pass(cmdbuf);
                return;
@@ -1450,6 +1506,14 @@ void imap_command_loop(void)
                imap_myrights(num_parms, parms);
        }
 
+       else if (!strcasecmp(parms[1], "GETMETADATA")) {
+               imap_getmetadata(num_parms, parms);
+       }
+
+       else if (!strcasecmp(parms[1], "SETMETADATA")) {
+               imap_setmetadata(num_parms, parms);
+       }
+
        else if (IMAP->selected == 0) {
                cprintf("%s BAD no folder selected\r\n", parms[0]);
        }
@@ -1532,5 +1596,7 @@ char *serv_imap_init(void)
                                NULL, imaps_greeting, imap_command_loop, NULL);
 #endif
        CtdlRegisterSessionHook(imap_cleanup_function, EVT_STOP);
+
+       /* return our Subversion id for the Log */
        return "$Id$";
 }