* 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
+/*
+ * 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.
*/
/*
- * 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();
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;
}
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 {
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 */