3 * IMAP server for the Citadel/UX system
4 * Copyright (C) 2000 by Art Cancro and others.
5 * This code is released under the terms of the GNU General Public License.
7 * Current status of standards conformance:
9 * *** ABSOLUTELY NOTHING WORKS ***
21 #include <sys/types.h>
29 #include "sysdep_decls.h"
30 #include "citserver.h"
33 #include "dynloader.h"
40 #include "internet_addressing.h"
41 #include "serv_imap.h"
48 * This cleanup function blows away the temporary memory and files used by
51 void imap_cleanup_function(void) {
53 /* Don't do this stuff if this is not a IMAP session! */
54 if (CC->h_command_function != imap_command_loop) return;
56 lprintf(9, "Performing IMAP cleanup hook\n");
59 lprintf(9, "Finished IMAP cleanup hook\n");
65 * Here's where our IMAP session begins its happy day.
67 void imap_greeting(void) {
69 strcpy(CC->cs_clientname, "IMAP session");
71 CtdlAllocUserData(SYM_IMAP, sizeof(struct citimap));
73 cprintf("* OK %s Citadel/UX IMAP4rev1 server ready\r\n",
79 * implements the LOGIN command (ordinary username/password login)
81 void imap_login(char *tag, char *cmd, char *parms) {
85 extract_token(username, parms, 0, ' ');
86 extract_token(password, parms, 1, ' ');
88 cprintf("%s BAD hi <%s> <%s>\r\n", username, password);
94 * Main command loop for IMAP sessions.
96 void imap_command_loop(void) {
102 memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
103 if (client_gets(cmdbuf) < 1) {
104 lprintf(3, "IMAP socket is broken. Ending session.\r\n");
109 lprintf(5, "citserver[%3d]: %s\r\n", CC->cs_pid, cmdbuf);
110 while (strlen(cmdbuf) < 5) strcat(cmdbuf, " ");
113 /* strip off l/t whitespace and CRLF */
114 if (cmdbuf[strlen(cmdbuf)-1]=='\n') cmdbuf[strlen(cmdbuf)-1]=0;
115 if (cmdbuf[strlen(cmdbuf)-1]=='\r') cmdbuf[strlen(cmdbuf)-1]=0;
119 extract_token(tag, cmdbuf, 0, ' ');
120 extract_token(cmd, cmdbuf, 1, ' ');
121 remove_token(cmdbuf, 0, ' ');
122 remove_token(cmdbuf, 0, ' ');
123 lprintf(9, "tag=<%s> cmd=<%s> parms=<%s>\n", tag, cmd, cmdbuf);
125 if (!strcasecmp(cmd, "NOOP")) {
126 cprintf("%s OK This command successfully did nothing.\r\n",
130 else if (!strcasecmp(cmd, "LOGOUT")) {
131 cprintf("%s OK thank you for using Citadel IMAP\r\n", tag);
136 else if (!strcasecmp(cmd, "LOGIN")) {
137 imap_login(tag, cmd, cmdbuf);
140 else if (!CC->logged_in) {
141 cprintf("%s BAD Not logged in.\r\n", tag);
144 /* FIXME ... implement commands requiring login here */
147 cprintf("%s BAD command unrecognized\r\n", tag);
154 char *Dynamic_Module_Init(void)
156 SYM_IMAP = CtdlGetDynamicSymbol();
157 CtdlRegisterServiceHook(143, /* FIXME put in config setup */
161 CtdlRegisterSessionHook(imap_cleanup_function, EVT_STOP);