#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.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 "imap_tools.h"
+#include "imap_tools.h" /* Needed for imap_parameterize */
#include "genstamp.h"
#include "domain.h"
#include "clientsocket.h"
#include "locate_host.h"
#include "citadel_dirs.h"
-#ifdef HAVE_OPENSSL
-#include "serv_crypto.h"
-#endif
-
#ifndef HAVE_SNPRINTF
#include "snprintf.h"
#endif
mgsve_plain
};
-#define MGSVE CC->MGSVE
+#define MGSVE ((struct citmgsve *)CC->session_specific_data)
/*****************************************************************************/
/* MANAGESIEVE Server */
/*****************************************************************************/
+
void sieve_outbuf_append(char *str)
{
size_t newlen = strlen(str)+1;
CC->internal_pgm = 1;
CC->cs_flags |= CS_STEALTH;
- MGSVE = malloc(sizeof(struct citmgsve));
+ CC->session_specific_data = malloc(sizeof(struct citmgsve));
memset(MGSVE, 0, sizeof(struct citmgsve));
cmd_mgsve_caps();
}
char *cursor = token;
char *number;
- while ((*cursor != '\0') &&
+ while (!IsEmptyStr(cursor) &&
(*cursor != '{'))
{
cursor++;
}
- if (*cursor == '\0')
+ if (IsEmptyStr(cursor))
return -1;
number = cursor + 1;
while ((*cursor != '\0') &&
if (cursor[-1] == '+')
cursor--;
- if (*cursor == '\0')
+ if (IsEmptyStr(cursor))
return -1;
return atol(number);
}
-#ifdef HAVE_OPENSSL
/**
* STARTTLS command chapter 2.2
*/
void cmd_mgsve_starttls(void)
{ /** answer with OK, and fire off tls session. */
cprintf("OK\r\n");
- CtdlStartTLS(NULL, NULL, NULL);
+ CtdlModuleStartCryptoMsgs(NULL, NULL, NULL);
cmd_mgsve_caps();
}
-#endif
if (strlen(argbuf) >= 7) {
}
else {
- CtdlEncodeBase64(username_prompt, "Username:", 9);
+ CtdlEncodeBase64(username_prompt, "Username:", 9, 0);
cprintf("334 %s\r\n", username_prompt);
}
return;
/*
* implements the STARTTLS command (Citadel API version)
*/
-#ifdef HAVE_OPENSSL
void _mgsve_starttls(void)
{
char ok_response[SIZ];
"554 5.7.3 TLS not supported here\r\n");
sprintf(error_response,
"554 5.7.3 Internal error\r\n");
- CtdlStartTLS(ok_response, nosup_response, error_response);
+ CtdlModuleStartCryptoMsgs(ok_response, nosup_response, error_response);
}
-#endif
/*
}
+/*
+ * This cleanup function blows away the temporary memory and files used by
+ * the server.
+ */
+void managesieve_cleanup_function(void) {
-#endif /* HAVE_LIBSIEVE */
+ /* Don't do this stuff if this is not a managesieve session! */
+ if (CC->h_command_function != managesieve_command_loop) return;
+ lprintf(CTDL_DEBUG, "Performing managesieve cleanup hook\n");
+ free(MGSVE);
+}
+
+
+
+#endif /* HAVE_LIBSIEVE */
+const char* CitadelServiceManageSieve = "ManageSieve";
CTDL_MODULE_INIT(managesieve)
{
-
+ if (!threading)
+ {
#ifdef HAVE_LIBSIEVE
-
- CtdlRegisterServiceHook(config.c_managesieve_port, /* MGSVE */
- NULL,
- managesieve_greeting,
- managesieve_command_loop,
- NULL);
+ CtdlRegisterServiceHook(config.c_managesieve_port,
+ NULL,
+ managesieve_greeting,
+ managesieve_command_loop,
+ NULL,
+ CitadelServiceManageSieve);
+ CtdlRegisterSessionHook(managesieve_cleanup_function, EVT_STOP);
#else /* HAVE_LIBSIEVE */
- lprintf(CTDL_INFO, "This server is missing libsieve. Managesieve protocol is disabled..\n");
+ lprintf(CTDL_INFO, "This server is missing libsieve. Managesieve protocol is disabled..\n");
#endif /* HAVE_LIBSIEVE */
-
+ }
+
/* return our Subversion id for the Log */
return "$Id$";
}