#include "imap_search.h"
#include "imap_store.h"
#include "imap_acl.h"
+#include "imap_metadata.h"
#include "imap_misc.h"
#ifdef HAVE_OPENSSL
* 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"); */
}
/*
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();
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;
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);
}
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");
}
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;
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]);
}
NULL, imaps_greeting, imap_command_loop, NULL);
#endif
CtdlRegisterSessionHook(imap_cleanup_function, EVT_STOP);
+
+ /* return our Subversion id for the Log */
return "$Id$";
}