#include <ctype.h>
#include <string.h>
#include <limits.h>
+#include <libcitadel.h>
#include "citadel.h"
#include "server.h"
#include "citserver.h"
#include "policy.h"
#include "database.h"
#include "msgbase.h"
-#include "tools.h"
#include "internet_addressing.h"
#include "serv_imap.h"
#include "imap_tools.h"
* output this stuff in other places as well)
*/
void imap_output_capability_string(void) {
- cprintf("CAPABILITY IMAP4REV1 NAMESPACE ID ACL AUTH=PLAIN AUTH=LOGIN");
+ cprintf("CAPABILITY IMAP4REV1 NAMESPACE ID AUTH=PLAIN AUTH=LOGIN UIDPLUS");
#ifdef HAVE_OPENSSL
if (!CC->redirect_ssl) cprintf(" STARTTLS");
#endif
+#ifndef DISABLE_IMAP_ACL
+ cprintf(" ACL");
+#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
{
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;
*/
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();
}
}
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]);
}
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;
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;
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,
struct irl *irl = NULL; /* the list */
struct irl *irlp = NULL; /* scratch pointer */
struct irlparms irlparms;
+ char buf[1024];
if (strchr(parms[3], '\\') != NULL) {
cprintf("%s NO Invalid character in folder name\r\n",
return;
}
if (r == crr_already_exists) {
- cprintf("%s '%s' already exists.\r\n", parms[0], parms[2]);
+ cprintf("%s NO '%s' already exists.\r\n", parms[0], parms[2]);
return;
}
if (r == crr_noneditable) {
- cprintf("%s This folder is not editable.\r\n", parms[0]);
+ cprintf("%s NO This folder is not editable.\r\n", parms[0]);
return;
}
if (r == crr_invalid_floor) {
- cprintf("%s Folder root does not exist.\r\n", parms[0]);
+ cprintf("%s NO Folder root does not exist.\r\n", parms[0]);
return;
}
if (r == crr_access_denied) {
- cprintf("%s You do not have permission to edit "
- "this folder.\r\n", parms[0]);
+ cprintf("%s NO You do not have permission to edit this folder.\r\n",
+ parms[0]);
return;
}
if (r != crr_ok) {
return;
}
-
/* If this is the INBOX, then RFC2060 says we have to just move the
* contents. In a Citadel environment it's easier to rename the room
* (already did that) and create a new inbox.
}
}
+ snprintf(buf, sizeof buf, "IMAP folder \"%s\" renamed to \"%s\" by %s\n",
+ parms[2],
+ parms[3],
+ CC->curr_user
+ );
+ aide_message(buf, "IMAP folder rename");
+
cprintf("%s OK RENAME completed\r\n", parms[0]);
}
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. */
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);
}
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);
}
}
+const char *CitadelServiceIMAP="IMAP";
+const char *CitadelServiceIMAPS="IMAPS";
+
/*
* This function is called to register the IMAP extension with Citadel.
*/
CTDL_MODULE_INIT(imap)
{
- CtdlRegisterServiceHook(config.c_imap_port,
- NULL, imap_greeting, imap_command_loop, NULL);
+ 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);
+ 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$";
}