4 * IMAP server for the Citadel system
5 * Copyright (C) 2000-2009 by Art Cancro and others.
6 * This code is released under the terms of the GNU General Public License.
8 * WARNING: the IMAP protocol is badly designed. No implementation of it
9 * is perfect. Indeed, with so much gratuitous complexity, *all* IMAP
10 * implementations have bugs.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #include <sys/types.h>
37 #if TIME_WITH_SYS_TIME
38 # include <sys/time.h>
42 # include <sys/time.h>
52 #include <libcitadel.h>
55 #include "citserver.h"
62 #include "internet_addressing.h"
63 #include "imap_tools.h"
64 #include "serv_imap.h"
65 #include "imap_list.h"
66 #include "imap_fetch.h"
67 #include "imap_search.h"
68 #include "imap_store.h"
70 #include "imap_metadata.h"
71 #include "imap_misc.h"
73 #include "ctdl_module.h"
76 /* imap_rename() uses this struct containing list of rooms to rename */
79 char irl_oldroom[ROOMNAMELEN];
80 char irl_newroom[ROOMNAMELEN];
84 /* Data which is passed between imap_rename() and imap_rename_backend() */
93 * If there is a message ID map in memory, free it
95 void imap_free_msgids(void)
97 if (IMAP->msgids != NULL) {
103 if (IMAP->flags != NULL) {
107 IMAP->last_mtime = (-1);
112 * If there is a transmitted message in memory, free it
114 void imap_free_transmitted_message(void)
116 FreeStrBuf(&IMAP->TransmittedMessage);
121 * Set the \Seen, \Recent. and \Answered flags, based on the sequence
122 * sets stored in the visit record for this user/room. Note that we have
123 * to parse each sequence set manually here, because calling the utility
124 * function is_msg_in_sequence_set() over and over again is too expensive.
126 * first_msg should be set to 0 to rescan the flags for every message in the
127 * room, or some other value if we're only interested in an incremental
130 void imap_set_seen_flags(int first_msg)
136 char setstr[64], lostr[64], histr[64];
139 if (IMAP->num_msgs < 1) return;
140 CtdlGetRelationship(&vbuf, &CC->user, &CC->room);
142 for (i = first_msg; i < IMAP->num_msgs; ++i) {
143 IMAP->flags[i] = IMAP->flags[i] & ~IMAP_SEEN;
144 IMAP->flags[i] |= IMAP_RECENT;
145 IMAP->flags[i] = IMAP->flags[i] & ~IMAP_ANSWERED;
149 * Do the "\Seen" flag.
150 * (Any message not "\Seen" is considered "\Recent".)
152 num_sets = num_tokens(vbuf.v_seen, ',');
153 for (s=0; s<num_sets; ++s) {
154 extract_token(setstr, vbuf.v_seen, s, ',', sizeof setstr);
156 extract_token(lostr, setstr, 0, ':', sizeof lostr);
157 if (num_tokens(setstr, ':') >= 2) {
158 extract_token(histr, setstr, 1, ':', sizeof histr);
159 if (!strcmp(histr, "*")) {
160 snprintf(histr, sizeof histr, "%ld", LONG_MAX);
164 strcpy(histr, lostr);
169 for (i = first_msg; i < IMAP->num_msgs; ++i) {
170 if ((IMAP->msgids[i] >= lo) && (IMAP->msgids[i] <= hi)){
171 IMAP->flags[i] |= IMAP_SEEN;
172 IMAP->flags[i] = IMAP->flags[i] & ~IMAP_RECENT;
177 /* Do the ANSWERED flag */
178 num_sets = num_tokens(vbuf.v_answered, ',');
179 for (s=0; s<num_sets; ++s) {
180 extract_token(setstr, vbuf.v_answered, s, ',', sizeof setstr);
182 extract_token(lostr, setstr, 0, ':', sizeof lostr);
183 if (num_tokens(setstr, ':') >= 2) {
184 extract_token(histr, setstr, 1, ':', sizeof histr);
185 if (!strcmp(histr, "*")) {
186 snprintf(histr, sizeof histr, "%ld", LONG_MAX);
190 strcpy(histr, lostr);
195 for (i = first_msg; i < IMAP->num_msgs; ++i) {
196 if ((IMAP->msgids[i] >= lo) && (IMAP->msgids[i] <= hi)){
197 IMAP->flags[i] |= IMAP_ANSWERED;
207 * Back end for imap_load_msgids()
209 * Optimization: instead of calling realloc() to add each message, we
210 * allocate space in the list for REALLOC_INCREMENT messages at a time. This
211 * allows the mapping to proceed much faster.
213 void imap_add_single_msgid(long msgnum, void *userdata)
217 if (IMAP->num_msgs > IMAP->num_alloc) {
218 IMAP->num_alloc += REALLOC_INCREMENT;
219 IMAP->msgids = realloc(IMAP->msgids, (IMAP->num_alloc * sizeof(long)) );
220 IMAP->flags = realloc(IMAP->flags, (IMAP->num_alloc * sizeof(long)) );
222 IMAP->msgids[IMAP->num_msgs - 1] = msgnum;
223 IMAP->flags[IMAP->num_msgs - 1] = 0;
229 * Set up a message ID map for the current room (folder)
231 void imap_load_msgids(void)
233 struct cdbdata *cdbfr;
235 if (IMAP->selected == 0) {
236 CtdlLogPrintf(CTDL_ERR,
237 "imap_load_msgids() can't run; no room selected\n");
241 imap_free_msgids(); /* If there was already a map, free it */
243 /* Load the message list */
244 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
246 IMAP->msgids = malloc(cdbfr->len);
247 memcpy(IMAP->msgids, cdbfr->ptr, cdbfr->len);
248 IMAP->num_msgs = cdbfr->len / sizeof(long);
249 IMAP->num_alloc = cdbfr->len / sizeof(long);
253 if (IMAP->num_msgs) {
254 IMAP->flags = malloc(IMAP->num_alloc * sizeof(long));
255 memset(IMAP->flags, 0, (IMAP->num_alloc * sizeof(long)) );
258 imap_set_seen_flags(0);
263 * Re-scan the selected room (folder) and see if it's been changed at all
265 void imap_rescan_msgids(void)
268 int original_num_msgs = 0;
269 long original_highest = 0L;
271 int message_still_exists;
272 struct cdbdata *cdbfr;
273 long *msglist = NULL;
277 if (IMAP->selected == 0) {
278 CtdlLogPrintf(CTDL_ERR, "imap_load_msgids() can't run; no room selected\n");
283 * Check to see if the room's contents have changed.
284 * If not, we can avoid this rescan.
286 CtdlGetRoom(&CC->room, CC->room.QRname);
287 if (IMAP->last_mtime == CC->room.QRmtime) { /* No changes! */
291 /* Load the *current* message list from disk, so we can compare it
292 * to what we have in memory.
294 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
296 msglist = malloc(cdbfr->len);
297 if (msglist == NULL) {
298 CtdlLogPrintf(CTDL_CRIT, "malloc() failed\n");
301 memcpy(msglist, cdbfr->ptr, (size_t)cdbfr->len);
302 num_msgs = cdbfr->len / sizeof(long);
309 * Check to see if any of the messages we know about have been expunged
311 if (IMAP->num_msgs > 0) {
313 for (i = 0; i < IMAP->num_msgs; ++i) {
315 message_still_exists = 0;
317 for (j = jstart; j < num_msgs; ++j) {
318 if (msglist[j] == IMAP->msgids[i]) {
319 message_still_exists = 1;
326 if (message_still_exists == 0) {
327 cprintf("* %d EXPUNGE\r\n", i + 1);
329 /* Here's some nice stupid nonsense. When a
330 * message is expunged, we have to slide all
331 * the existing messages up in the message
335 memcpy(&IMAP->msgids[i],
336 &IMAP->msgids[i + 1],
338 (IMAP->num_msgs - i)));
339 memcpy(&IMAP->flags[i],
342 (IMAP->num_msgs - i)));
351 * Remember how many messages were here before we re-scanned.
353 original_num_msgs = IMAP->num_msgs;
354 if (IMAP->num_msgs > 0) {
355 original_highest = IMAP->msgids[IMAP->num_msgs - 1];
357 original_highest = 0L;
361 * Now peruse the room for *new* messages only.
362 * This logic is probably the cause of Bug # 368
363 * [ http://bugzilla.citadel.org/show_bug.cgi?id=368 ]
366 for (j = 0; j < num_msgs; ++j) {
367 if (msglist[j] > original_highest) {
368 imap_add_single_msgid(msglist[j], NULL);
372 imap_set_seen_flags(original_num_msgs);
375 * If new messages have arrived, tell the client about them.
377 if (IMAP->num_msgs > original_num_msgs) {
379 for (j = 0; j < num_msgs; ++j) {
380 if (IMAP->flags[j] & IMAP_RECENT) {
385 cprintf("* %d EXISTS\r\n", IMAP->num_msgs);
386 cprintf("* %d RECENT\r\n", num_recent);
392 IMAP->last_mtime = CC->room.QRmtime;
397 * This cleanup function blows away the temporary memory and files used by
400 void imap_cleanup_function(void)
403 /* Don't do this stuff if this is not a IMAP session! */
404 if (CC->h_command_function != imap_command_loop)
407 /* If there is a mailbox selected, auto-expunge it. */
408 if (IMAP->selected) {
412 CtdlLogPrintf(CTDL_DEBUG, "Performing IMAP cleanup hook\n");
414 imap_free_transmitted_message();
416 if (IMAP->cached_rfc822_data != NULL) {
417 free(IMAP->cached_rfc822_data);
418 IMAP->cached_rfc822_data = NULL;
419 IMAP->cached_rfc822_msgnum = (-1);
420 IMAP->cached_rfc822_withbody = 0;
423 if (IMAP->cached_body != NULL) {
424 free(IMAP->cached_body);
425 IMAP->cached_body = NULL;
426 IMAP->cached_body_len = 0;
427 IMAP->cached_bodymsgnum = (-1);
429 FreeStrBuf(&IMAP->Cmd.CmdBuf);
430 if (IMAP->Cmd.Params != NULL) free(IMAP->Cmd.Params);
432 CtdlLogPrintf(CTDL_DEBUG, "Finished IMAP cleanup hook\n");
437 * Does the actual work of the CAPABILITY command (because we need to
438 * output this stuff in other places as well)
440 void imap_output_capability_string(void) {
441 cprintf("CAPABILITY IMAP4REV1 NAMESPACE ID AUTH=PLAIN AUTH=LOGIN UIDPLUS");
444 if (!CC->redirect_ssl) cprintf(" STARTTLS");
447 #ifndef DISABLE_IMAP_ACL
451 /* We are building a partial implementation of METADATA for the sole purpose
452 * of interoperating with the ical/vcard version of the Bynari Insight Connector.
453 * It is not a full RFC5464 implementation, but it should refuse non-Bynari
454 * metadata in a compatible and graceful way.
456 cprintf(" METADATA");
459 * LIST-EXTENDED was originally going to be required by the METADATA extension.
460 * It was mercifully removed prior to the finalization of RFC5464. We started
461 * implementing this but stopped when we learned that it would not be needed.
462 * If you uncomment this declaration you are responsible for writing a lot of new
465 * cprintf(" LIST-EXTENDED")
471 * implements the CAPABILITY command
473 void imap_capability(int num_parms, ConstStr *Params)
476 imap_output_capability_string();
478 cprintf("%s OK CAPABILITY completed\r\n", Params[0].Key);
483 * Implements the ID command (specified by RFC2971)
485 * We ignore the client-supplied information, and output a NIL response.
486 * Although this is technically a valid implementation of the extension, it
487 * is quite useless. It exists only so that we may see which clients are
488 * making use of this extension.
491 void imap_id(int num_parms, ConstStr *Params)
493 cprintf("* ID NIL\r\n");
494 cprintf("%s OK ID completed\r\n", Params[0].Key);
499 * Here's where our IMAP session begins its happy day.
501 void imap_greeting(void)
504 strcpy(CC->cs_clientname, "IMAP session");
505 CC->session_specific_data = malloc(sizeof(citimap));
506 memset(IMAP, 0, sizeof(citimap));
507 IMAP->authstate = imap_as_normal;
508 IMAP->cached_rfc822_data = NULL;
509 IMAP->cached_rfc822_msgnum = (-1);
510 IMAP->cached_rfc822_withbody = 0;
514 cprintf("* BYE; Server busy, try later\r\n");
519 imap_output_capability_string();
520 cprintf("] %s IMAP4rev1 %s ready\r\n", config.c_fqdn, CITADEL);
525 * IMAPS is just like IMAP, except it goes crypto right away.
527 void imaps_greeting(void) {
528 CtdlModuleStartCryptoMsgs(NULL, NULL, NULL);
530 if (!CC->redirect_ssl) CC->kill_me = 1; /* kill session if no crypto */
537 * implements the LOGIN command (ordinary username/password login)
539 void imap_login(int num_parms, ConstStr *Params)
544 if (Params[2].Key[0] == '{') {
545 cprintf("+ go ahead\r\n");
546 IMAP->authstate = imap_as_expecting_multilineusername;
547 strcpy(IMAP->authseq, Params[0].Key);
551 cprintf("%s BAD incorrect number of parameters\r\n", Params[0].Key);
555 if (CtdlLoginExistingUser(NULL, Params[2].Key) == login_ok) {
556 if (CtdlTryPassword(Params[3].Key) == pass_ok) {
557 cprintf("%s OK [", Params[0].Key);
558 imap_output_capability_string();
559 cprintf("] Hello, %s\r\n", CC->user.fullname);
564 cprintf("%s BAD Login incorrect\r\n", Params[0].Key);
566 cprintf("%s BAD incorrect number of parameters\r\n", Params[0].Key);
574 * Implements the AUTHENTICATE command
576 void imap_authenticate(int num_parms, ConstStr *Params)
580 if (num_parms != 3) {
581 cprintf("%s BAD incorrect number of parameters\r\n",
587 cprintf("%s BAD Already logged in.\r\n", Params[0].Key);
591 if (!strcasecmp(Params[2].Key, "LOGIN")) {
592 CtdlEncodeBase64(buf, "Username:", 9, 0);
593 cprintf("+ %s\r\n", buf);
594 IMAP->authstate = imap_as_expecting_username;
595 strcpy(IMAP->authseq, Params[0].Key);
599 if (!strcasecmp(Params[2].Key, "PLAIN")) {
600 // CtdlEncodeBase64(buf, "Username:", 9, 0);
601 // cprintf("+ %s\r\n", buf);
603 IMAP->authstate = imap_as_expecting_plainauth;
604 strcpy(IMAP->authseq, Params[0].Key);
609 cprintf("%s NO AUTHENTICATE %s failed\r\n",
610 Params[0].Key, Params[1].Key);
615 void imap_auth_plain(void)
617 const char *decoded_authstring;
623 memset(pass, 0, sizeof(pass));
624 StrBufDecodeBase64(IMAP->Cmd.CmdBuf);
626 decoded_authstring = ChrPtr(IMAP->Cmd.CmdBuf);
627 safestrncpy(ident, decoded_authstring, sizeof ident);
628 safestrncpy(user, &decoded_authstring[strlen(ident) + 1], sizeof user);
629 safestrncpy(pass, &decoded_authstring[strlen(ident) + strlen(user) + 2], sizeof pass);
631 IMAP->authstate = imap_as_normal;
633 if (!IsEmptyStr(ident)) {
634 result = CtdlLoginExistingUser(user, ident);
637 result = CtdlLoginExistingUser(NULL, user);
640 if (result == login_ok) {
641 if (CtdlTryPassword(pass) == pass_ok) {
642 cprintf("%s OK authentication succeeded\r\n", IMAP->authseq);
646 cprintf("%s NO authentication failed\r\n", IMAP->authseq);
650 void imap_auth_login_user(long state)
653 citimap *Imap = IMAP;
656 case imap_as_expecting_username:
657 StrBufDecodeBase64(Imap->Cmd.CmdBuf);
658 CtdlLoginExistingUser(NULL, ChrPtr(Imap->Cmd.CmdBuf));
659 CtdlEncodeBase64(buf, "Password:", 9, 0);
660 cprintf("+ %s\r\n", buf);
662 Imap->authstate = imap_as_expecting_password;
664 case imap_as_expecting_multilineusername:
665 extract_token(buf, ChrPtr(Imap->Cmd.CmdBuf), 1, ' ', sizeof(buf));
666 CtdlLoginExistingUser(NULL, ChrPtr(Imap->Cmd.CmdBuf));
667 cprintf("+ go ahead\r\n");
668 IMAP->authstate = imap_as_expecting_multilinepassword;
674 void imap_auth_login_pass(long state)
676 citimap *Imap = IMAP;
677 const char *pass = NULL;
682 case imap_as_expecting_password:
683 StrBufDecodeBase64(Imap->Cmd.CmdBuf);
686 case imap_as_expecting_multilinepassword:
687 pass = ChrPtr(Imap->Cmd.CmdBuf);
690 if (CtdlTryPassword(pass) == pass_ok) {
691 cprintf("%s OK authentication succeeded\r\n", IMAP->authseq);
693 cprintf("%s NO authentication failed\r\n", IMAP->authseq);
695 IMAP->authstate = imap_as_normal;
701 * implements the STARTTLS command (Citadel API version)
703 void imap_starttls(int num_parms, ConstStr *Params)
705 char ok_response[SIZ];
706 char nosup_response[SIZ];
707 char error_response[SIZ];
709 sprintf(ok_response, "%s OK begin TLS negotiation now\r\n", Params[0].Key);
710 sprintf(nosup_response, "%s NO TLS not supported here\r\n", Params[0].Key);
711 sprintf(error_response, "%s BAD Internal error\r\n", Params[0].Key);
712 CtdlModuleStartCryptoMsgs(ok_response, nosup_response, error_response);
717 * implements the SELECT command
719 void imap_select(int num_parms, ConstStr *Params)
722 char augmented_roomname[ROOMNAMELEN];
726 struct ctdlroom QRscratch;
732 /* Convert the supplied folder name to a roomname */
733 i = imap_roomname(towhere, sizeof towhere, Params[2].Key);
735 cprintf("%s NO Invalid mailbox name.\r\n", Params[0].Key);
739 floornum = (i & 0x00ff);
740 roomflags = (i & 0xff00);
742 /* First try a regular match */
743 c = CtdlGetRoom(&QRscratch, towhere);
745 /* Then try a mailbox name match */
747 CtdlMailboxName(augmented_roomname, sizeof augmented_roomname, &CC->user, towhere);
748 c = CtdlGetRoom(&QRscratch, augmented_roomname);
750 strcpy(towhere, augmented_roomname);
754 /* If the room exists, check security/access */
756 /* See if there is an existing user/room relationship */
757 CtdlRoomAccess(&QRscratch, &CC->user, &ra, NULL);
759 /* normal clients have to pass through security */
765 /* Fail here if no such room */
767 cprintf("%s NO ... no such room, or access denied\r\n", Params[0].Key);
771 /* If we already had some other folder selected, auto-expunge it */
775 * CtdlUserGoto() formally takes us to the desired room, happily returning
776 * the number of messages and number of new messages.
778 memcpy(&CC->room, &QRscratch, sizeof(struct ctdlroom));
779 CtdlUserGoto(NULL, 0, 0, &msgs, &new);
782 if (!strcasecmp(Params[1].Key, "EXAMINE")) {
789 IMAP->last_mtime = CC->room.QRmtime;
791 cprintf("* %d EXISTS\r\n", msgs);
792 cprintf("* %d RECENT\r\n", new);
794 cprintf("* OK [UIDVALIDITY %ld] UID validity status\r\n", GLOBAL_UIDVALIDITY_VALUE);
795 cprintf("* OK [UIDNEXT %ld] Predicted next UID\r\n", CitControl.MMhighest + 1);
797 /* Technically, \Deleted is a valid flag, but not a permanent flag,
798 * because we don't maintain its state across sessions. Citadel
799 * automatically expunges mailboxes when they are de-selected.
801 * Unfortunately, omitting \Deleted as a PERMANENTFLAGS flag causes
802 * some clients (particularly Thunderbird) to misbehave -- they simply
803 * elect not to transmit the flag at all. So we have to advertise
804 * \Deleted as a PERMANENTFLAGS flag, even though it technically isn't.
806 cprintf("* FLAGS (\\Deleted \\Seen \\Answered)\r\n");
807 cprintf("* OK [PERMANENTFLAGS (\\Deleted \\Seen \\Answered)] permanent flags\r\n");
809 cprintf("%s OK [%s] %s completed\r\n",
811 (IMAP->readonly ? "READ-ONLY" : "READ-WRITE"), Params[1].Key
817 * Does the real work for expunge.
819 int imap_do_expunge(void)
822 int num_expunged = 0;
823 long *delmsgs = NULL;
826 CtdlLogPrintf(CTDL_DEBUG, "imap_do_expunge() called\n");
827 if (IMAP->selected == 0) {
831 if (IMAP->num_msgs > 0) {
832 delmsgs = malloc(IMAP->num_msgs * sizeof(long));
833 for (i = 0; i < IMAP->num_msgs; ++i) {
834 if (IMAP->flags[i] & IMAP_DELETED) {
835 delmsgs[num_delmsgs++] = IMAP->msgids[i];
838 if (num_delmsgs > 0) {
839 CtdlDeleteMessages(CC->room.QRname, delmsgs, num_delmsgs, "");
841 num_expunged += num_delmsgs;
845 if (num_expunged > 0) {
846 imap_rescan_msgids();
849 CtdlLogPrintf(CTDL_DEBUG, "Expunged %d messages from <%s>\n", num_expunged, CC->room.QRname);
850 return (num_expunged);
855 * implements the EXPUNGE command syntax
857 void imap_expunge(int num_parms, ConstStr *Params)
859 int num_expunged = 0;
861 num_expunged = imap_do_expunge();
862 cprintf("%s OK expunged %d messages.\r\n", Params[0].Key, num_expunged);
867 * implements the CLOSE command
869 void imap_close(int num_parms, ConstStr *Params)
872 /* Yes, we always expunge on close. */
873 if (IMAP->selected) {
880 cprintf("%s OK CLOSE completed\r\n", Params[0].Key);
885 * Implements the NAMESPACE command.
887 void imap_namespace(int num_parms, ConstStr *Params)
894 cprintf("* NAMESPACE ");
896 /* All personal folders are subordinate to INBOX. */
897 cprintf("((\"INBOX/\" \"/\")) ");
899 /* Other users' folders ... coming soon! FIXME */
902 /* Show all floors as shared namespaces. Neato! */
904 for (i = 0; i < MAXFLOORS; ++i) {
905 fl = CtdlGetCachedFloor(i);
906 if (fl->f_flags & F_INUSE) {
907 if (floors > 0) cprintf(" ");
909 sprintf(buf, "%s/", fl->f_name);
910 plain_imap_strout(buf);
917 /* Wind it up with a newline and a completion message. */
919 cprintf("%s OK NAMESPACE completed\r\n", Params[0].Key);
924 * Implements the CREATE command
927 void imap_create(int num_parms, ConstStr *Params)
930 char roomname[ROOMNAMELEN];
935 char *notification_message = NULL;
938 cprintf("%s NO A foder name must be specified\r\n", Params[0].Key);
942 if (strchr(Params[2].Key, '\\') != NULL) {
943 cprintf("%s NO Invalid character in folder name\r\n", Params[0].Key);
944 CtdlLogPrintf(CTDL_DEBUG, "invalid character in folder name\n");
948 ret = imap_roomname(roomname, sizeof roomname, Params[2].Key);
950 cprintf("%s NO Invalid mailbox name or location\r\n",
952 CtdlLogPrintf(CTDL_DEBUG, "invalid mailbox name or location\n");
955 floornum = (ret & 0x00ff); /* lower 8 bits = floor number */
956 flags = (ret & 0xff00); /* upper 8 bits = flags */
958 if (flags & IR_MAILBOX) {
959 if (strncasecmp(Params[2].Key, "INBOX/", 6)) {
960 cprintf("%s NO Personal folders must be created under INBOX\r\n", Params[0].Key);
961 CtdlLogPrintf(CTDL_DEBUG, "not subordinate to inbox\n");
966 if (flags & IR_MAILBOX) {
967 newroomtype = 4; /* private mailbox */
968 newroomview = VIEW_MAILBOX;
970 newroomtype = 0; /* public folder */
971 newroomview = VIEW_BBS;
974 CtdlLogPrintf(CTDL_INFO, "Create new room <%s> on floor <%d> with type <%d>\n",
975 roomname, floornum, newroomtype);
977 ret = CtdlCreateRoom(roomname, newroomtype, "", floornum, 1, 0, newroomview);
979 /*** DO NOT CHANGE THIS ERROR MESSAGE IN ANY WAY! BYNARI CONNECTOR DEPENDS ON IT! ***/
980 cprintf("%s NO Mailbox already exists, or create failed\r\n", Params[0].Key);
982 cprintf("%s OK CREATE completed\r\n", Params[0].Key);
983 /* post a message in Aide> describing the new room */
984 notification_message = malloc(1024);
985 snprintf(notification_message, 1024,
986 "A new room called \"%s\" has been created by %s%s%s%s\n",
989 ((ret & QR_MAILBOX) ? " [personal]" : ""),
990 ((ret & QR_PRIVATE) ? " [private]" : ""),
991 ((ret & QR_GUESSNAME) ? " [hidden]" : "")
993 CtdlAideMessage(notification_message, "Room Creation Message");
994 free(notification_message);
996 CtdlLogPrintf(CTDL_DEBUG, "imap_create() completed\n");
1001 * Locate a room by its IMAP folder name, and check access to it.
1002 * If zapped_ok is nonzero, we can also look for the room in the zapped list.
1004 int imap_grabroom(char *returned_roomname, const char *foldername, int zapped_ok)
1007 char augmented_roomname[ROOMNAMELEN];
1008 char roomname[ROOMNAMELEN];
1010 struct ctdlroom QRscratch;
1014 ret = imap_roomname(roomname, sizeof roomname, foldername);
1019 /* First try a regular match */
1020 c = CtdlGetRoom(&QRscratch, roomname);
1022 /* Then try a mailbox name match */
1024 CtdlMailboxName(augmented_roomname, sizeof augmented_roomname,
1025 &CC->user, roomname);
1026 c = CtdlGetRoom(&QRscratch, augmented_roomname);
1028 strcpy(roomname, augmented_roomname);
1031 /* If the room exists, check security/access */
1033 /* See if there is an existing user/room relationship */
1034 CtdlRoomAccess(&QRscratch, &CC->user, &ra, NULL);
1036 /* normal clients have to pass through security */
1037 if (ra & UA_KNOWN) {
1040 if ((zapped_ok) && (ra & UA_ZAPPED)) {
1045 /* Fail here if no such room */
1047 strcpy(returned_roomname, "");
1050 strcpy(returned_roomname, QRscratch.QRname);
1057 * Implements the STATUS command (sort of)
1060 void imap_status(int num_parms, ConstStr *Params)
1063 char roomname[ROOMNAMELEN];
1065 char savedroom[ROOMNAMELEN];
1068 ret = imap_grabroom(roomname, Params[2].Key, 1);
1071 ("%s NO Invalid mailbox name or location, or access denied\r\n",
1077 * CtdlUserGoto() formally takes us to the desired room, happily returning
1078 * the number of messages and number of new messages. (If another
1079 * folder is selected, save its name so we can return there!!!!!)
1081 if (IMAP->selected) {
1082 strcpy(savedroom, CC->room.QRname);
1084 CtdlUserGoto(roomname, 0, 0, &msgs, &new);
1087 * Tell the client what it wants to know. In fact, tell it *more* than
1088 * it wants to know. We happily IGnore the supplied status data item
1089 * names and simply spew all possible data items. It's far easier to
1090 * code and probably saves us some processing time too.
1092 imap_mailboxname(buf, sizeof buf, &CC->room);
1093 cprintf("* STATUS ");
1094 plain_imap_strout(buf);
1095 cprintf(" (MESSAGES %d ", msgs);
1096 cprintf("RECENT %d ", new); /* Initially, new==recent */
1097 cprintf("UIDNEXT %ld ", CitControl.MMhighest + 1);
1098 cprintf("UNSEEN %d)\r\n", new);
1101 * If another folder is selected, go back to that room so we can resume
1102 * our happy day without violent explosions.
1104 if (IMAP->selected) {
1105 CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
1109 * Oooh, look, we're done!
1111 cprintf("%s OK STATUS completed\r\n", Params[0].Key);
1116 * Implements the SUBSCRIBE command
1119 void imap_subscribe(int num_parms, ConstStr *Params)
1122 char roomname[ROOMNAMELEN];
1123 char savedroom[ROOMNAMELEN];
1126 ret = imap_grabroom(roomname, Params[2].Key, 1);
1129 "%s NO Error %d: invalid mailbox name or location, or access denied\r\n",
1137 * CtdlUserGoto() formally takes us to the desired room, which has the side
1138 * effect of marking the room as not-zapped ... exactly the effect
1139 * we're looking for.
1141 if (IMAP->selected) {
1142 strcpy(savedroom, CC->room.QRname);
1144 CtdlUserGoto(roomname, 0, 0, &msgs, &new);
1147 * If another folder is selected, go back to that room so we can resume
1148 * our happy day without violent explosions.
1150 if (IMAP->selected) {
1151 CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
1154 cprintf("%s OK SUBSCRIBE completed\r\n", Params[0].Key);
1159 * Implements the UNSUBSCRIBE command
1162 void imap_unsubscribe(int num_parms, ConstStr *Params)
1165 char roomname[ROOMNAMELEN];
1166 char savedroom[ROOMNAMELEN];
1169 ret = imap_grabroom(roomname, Params[2].Key, 1);
1172 ("%s NO Invalid mailbox name or location, or access denied\r\n",
1178 * CtdlUserGoto() formally takes us to the desired room.
1180 if (IMAP->selected) {
1181 strcpy(savedroom, CC->room.QRname);
1183 CtdlUserGoto(roomname, 0, 0, &msgs, &new);
1186 * Now make the API call to zap the room
1188 if (CtdlForgetThisRoom() == 0) {
1189 cprintf("%s OK UNSUBSCRIBE completed\r\n", Params[0].Key);
1192 ("%s NO You may not unsubscribe from this folder.\r\n",
1197 * If another folder is selected, go back to that room so we can resume
1198 * our happy day without violent explosions.
1200 if (IMAP->selected) {
1201 CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
1207 * Implements the DELETE command
1210 void imap_delete(int num_parms, ConstStr *Params)
1213 char roomname[ROOMNAMELEN];
1214 char savedroom[ROOMNAMELEN];
1217 ret = imap_grabroom(roomname, Params[2].Key, 1);
1219 cprintf("%s NO Invalid mailbox name, or access denied\r\n",
1225 * CtdlUserGoto() formally takes us to the desired room, happily returning
1226 * the number of messages and number of new messages. (If another
1227 * folder is selected, save its name so we can return there!!!!!)
1229 if (IMAP->selected) {
1230 strcpy(savedroom, CC->room.QRname);
1232 CtdlUserGoto(roomname, 0, 0, &msgs, &new);
1235 * Now delete the room.
1237 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->room)) {
1238 CtdlScheduleRoomForDeletion(&CC->room);
1239 cprintf("%s OK DELETE completed\r\n", Params[0].Key);
1241 cprintf("%s NO Can't delete this folder.\r\n", Params[0].Key);
1245 * If another folder is selected, go back to that room so we can resume
1246 * our happy day without violent explosions.
1248 if (IMAP->selected) {
1249 CtdlUserGoto(savedroom, 0, 0, &msgs, &new);
1255 * Back end function for imap_rename()
1257 void imap_rename_backend(struct ctdlroom *qrbuf, void *data)
1259 char foldername[SIZ];
1260 char newfoldername[SIZ];
1261 char newroomname[ROOMNAMELEN];
1263 struct irl *irlp = NULL; /* scratch pointer */
1264 struct irlparms *irlparms;
1266 irlparms = (struct irlparms *) data;
1267 imap_mailboxname(foldername, sizeof foldername, qrbuf);
1269 /* Rename subfolders */
1270 if ((!strncasecmp(foldername, irlparms->oldname,
1271 strlen(irlparms->oldname))
1272 && (foldername[strlen(irlparms->oldname)] == '/'))) {
1274 sprintf(newfoldername, "%s/%s",
1276 &foldername[strlen(irlparms->oldname) + 1]
1279 newfloor = imap_roomname(newroomname,
1281 newfoldername) & 0xFF;
1283 irlp = (struct irl *) malloc(sizeof(struct irl));
1284 strcpy(irlp->irl_newroom, newroomname);
1285 strcpy(irlp->irl_oldroom, qrbuf->QRname);
1286 irlp->irl_newfloor = newfloor;
1287 irlp->next = *(irlparms->irl);
1288 *(irlparms->irl) = irlp;
1294 * Implements the RENAME command
1297 void imap_rename(int num_parms, ConstStr *Params)
1299 char old_room[ROOMNAMELEN];
1300 char new_room[ROOMNAMELEN];
1304 struct irl *irl = NULL; /* the list */
1305 struct irl *irlp = NULL; /* scratch pointer */
1306 struct irlparms irlparms;
1309 if (strchr(Params[3].Key, '\\') != NULL) {
1310 cprintf("%s NO Invalid character in folder name\r\n",
1315 oldr = imap_roomname(old_room, sizeof old_room, Params[2].Key);
1316 newr = imap_roomname(new_room, sizeof new_room, Params[3].Key);
1317 new_floor = (newr & 0xFF);
1319 r = CtdlRenameRoom(old_room, new_room, new_floor);
1321 if (r == crr_room_not_found) {
1322 cprintf("%s NO Could not locate this folder\r\n",
1326 if (r == crr_already_exists) {
1327 cprintf("%s NO '%s' already exists.\r\n", Params[0].Key, Params[2].Key);
1330 if (r == crr_noneditable) {
1331 cprintf("%s NO This folder is not editable.\r\n", Params[0].Key);
1334 if (r == crr_invalid_floor) {
1335 cprintf("%s NO Folder root does not exist.\r\n", Params[0].Key);
1338 if (r == crr_access_denied) {
1339 cprintf("%s NO You do not have permission to edit this folder.\r\n",
1344 cprintf("%s NO Rename failed - undefined error %d\r\n",
1349 /* If this is the INBOX, then RFC2060 says we have to just move the
1350 * contents. In a Citadel environment it's easier to rename the room
1351 * (already did that) and create a new inbox.
1353 if (!strcasecmp(Params[2].Key, "INBOX")) {
1354 CtdlCreateRoom(MAILROOM, 4, "", 0, 1, 0, VIEW_MAILBOX);
1357 /* Otherwise, do the subfolders. Build a list of rooms to rename... */
1359 irlparms.oldname = Params[2].Key;
1360 irlparms.newname = Params[3].Key;
1361 irlparms.irl = &irl;
1362 CtdlForEachRoom(imap_rename_backend, (void *) &irlparms);
1364 /* ... and now rename them. */
1365 while (irl != NULL) {
1366 r = CtdlRenameRoom(irl->irl_oldroom,
1370 /* FIXME handle error returns better */
1371 CtdlLogPrintf(CTDL_ERR, "CtdlRenameRoom() error %d\n", r);
1379 snprintf(buf, sizeof buf, "IMAP folder \"%s\" renamed to \"%s\" by %s\n",
1384 CtdlAideMessage(buf, "IMAP folder rename");
1386 cprintf("%s OK RENAME completed\r\n", Params[0].Key);
1391 * Main command loop for IMAP sessions.
1393 void imap_command_loop(void)
1395 struct timeval tv1, tv2;
1396 suseconds_t total_time = 0;
1397 int untagged_ok = 1;
1399 const char *pchs, *pche;
1401 gettimeofday(&tv1, NULL);
1402 CC->lastcmd = time(NULL);
1406 if (Imap->Cmd.CmdBuf == NULL)
1407 Imap->Cmd.CmdBuf = NewStrBufPlain(NULL, SIZ);
1409 FlushStrBuf(Imap->Cmd.CmdBuf);
1411 if (CtdlClientGetLine(Imap->Cmd.CmdBuf) < 1) {
1412 CtdlLogPrintf(CTDL_ERR, "Client disconnected: ending session.\r\n");
1417 if (Imap->authstate == imap_as_expecting_password) {
1418 CtdlLogPrintf(CTDL_INFO, "IMAP: <password>\n");
1420 else if (Imap->authstate == imap_as_expecting_plainauth) {
1421 CtdlLogPrintf(CTDL_INFO, "IMAP: <plain_auth>\n");
1423 else if ((Imap->authstate == imap_as_expecting_multilineusername) ||
1424 bmstrcasestr(ChrPtr(Imap->Cmd.CmdBuf), " LOGIN ")) {
1425 CtdlLogPrintf(CTDL_INFO, "IMAP: LOGIN...\n");
1428 CtdlLogPrintf(CTDL_INFO, "IMAP: %s\n", ChrPtr(Imap->Cmd.CmdBuf));
1431 pchs = ChrPtr(Imap->Cmd.CmdBuf);
1432 pche = pchs + StrLength(Imap->Cmd.CmdBuf);
1434 while ((pche > pchs) &&
1439 StrBufCutRight(Imap->Cmd.CmdBuf, 1);
1441 StrBufTrim(Imap->Cmd.CmdBuf);
1443 /* If we're in the middle of a multi-line command, handle that */
1444 switch (Imap->authstate){
1445 case imap_as_expecting_username:
1446 imap_auth_login_user(imap_as_expecting_username);
1448 case imap_as_expecting_multilineusername:
1449 imap_auth_login_user(imap_as_expecting_multilineusername);
1451 case imap_as_expecting_plainauth:
1454 case imap_as_expecting_password:
1455 imap_auth_login_pass(imap_as_expecting_password);
1457 case imap_as_expecting_multilinepassword:
1458 imap_auth_login_pass(imap_as_expecting_multilinepassword);
1465 /* Ok, at this point we're in normal command mode.
1466 * If the command just submitted does not contain a literal, we
1467 * might think about delivering some untagged stuff...
1469 if (*(ChrPtr(Imap->Cmd.CmdBuf) + StrLength(Imap->Cmd.CmdBuf) - 1)
1474 /* Grab the tag, command, and parameters. */
1475 imap_parameterize(&Imap->Cmd);
1477 /* debug output the parsed vector */
1480 CtdlLogPrintf(CTDL_DEBUG, "----- %ld params \n",
1481 Imap->Cmd.num_parms);
1483 for (i=0; i < Imap->Cmd.num_parms; i++) {
1484 if (Imap->Cmd.Params[i].len != strlen(Imap->Cmd.Params[i].Key))
1485 CtdlLogPrintf(CTDL_DEBUG, "*********** %ld != %ld : %s\n",
1486 Imap->Cmd.Params[i].len,
1487 strlen(Imap->Cmd.Params[i].Key),
1488 Imap->Cmd.Params[i].Key);
1490 CtdlLogPrintf(CTDL_DEBUG, "%ld : %s\n",
1491 Imap->Cmd.Params[i].len,
1492 Imap->Cmd.Params[i].Key);
1496 /* RFC3501 says that we cannot output untagged data during these commands */
1497 if (Imap->Cmd.num_parms >= 2) {
1498 if ( (!strcasecmp(Imap->Cmd.Params[1].Key, "FETCH"))
1499 || (!strcasecmp(Imap->Cmd.Params[1].Key, "STORE"))
1500 || (!strcasecmp(Imap->Cmd.Params[1].Key, "SEARCH"))
1508 /* we can put any additional untagged stuff right here in the future */
1511 * Before processing the command that was just entered... if we happen
1512 * to have a folder selected, we'd like to rescan that folder for new
1513 * messages, and for deletions/changes of existing messages. This
1514 * could probably be optimized better with some deep thought...
1516 if (Imap->selected) {
1517 imap_rescan_msgids();
1521 /* Now for the command set. */
1523 if (Imap->Cmd.num_parms < 2) {
1524 cprintf("BAD syntax error\r\n");
1527 /* The commands below may be executed in any state */
1529 else if ((!strcasecmp(Imap->Cmd.Params[1].Key, "NOOP"))
1530 || (!strcasecmp(Imap->Cmd.Params[1].Key, "CHECK"))) {
1531 cprintf("%s OK No operation\r\n",
1532 Imap->Cmd.Params[0].Key);
1535 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "ID")) {
1536 imap_id(Imap->Cmd.num_parms, Imap->Cmd.Params);
1540 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "LOGOUT")) {
1541 if (Imap->selected) {
1542 imap_do_expunge(); /* yes, we auto-expunge at logout */
1544 cprintf("* BYE %s logging out\r\n", config.c_fqdn);
1545 cprintf("%s OK Citadel IMAP session ended.\r\n",
1546 Imap->Cmd.Params[0].Key);
1551 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "LOGIN")) {
1552 imap_login(Imap->Cmd.num_parms, Imap->Cmd.Params);
1555 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "AUTHENTICATE")) {
1556 imap_authenticate(Imap->Cmd.num_parms, Imap->Cmd.Params);
1559 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "CAPABILITY")) {
1560 imap_capability(Imap->Cmd.num_parms, Imap->Cmd.Params);
1563 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "STARTTLS")) {
1564 imap_starttls(Imap->Cmd.num_parms, Imap->Cmd.Params);
1567 else if (!CC->logged_in) {
1568 cprintf("%s BAD Not logged in.\r\n", Imap->Cmd.Params[0].Key);
1571 /* The commans below require a logged-in state */
1573 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "SELECT")) {
1574 imap_select(Imap->Cmd.num_parms, Imap->Cmd.Params);
1577 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "EXAMINE")) {
1578 imap_select(Imap->Cmd.num_parms, Imap->Cmd.Params);
1581 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "LSUB")) {
1582 imap_list(Imap->Cmd.num_parms, Imap->Cmd.Params);
1585 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "LIST")) {
1586 imap_list(Imap->Cmd.num_parms, Imap->Cmd.Params);
1589 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "CREATE")) {
1590 imap_create(Imap->Cmd.num_parms, Imap->Cmd.Params);
1593 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "DELETE")) {
1594 imap_delete(Imap->Cmd.num_parms, Imap->Cmd.Params);
1597 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "RENAME")) {
1598 imap_rename(Imap->Cmd.num_parms, Imap->Cmd.Params);
1601 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "STATUS")) {
1602 imap_status(Imap->Cmd.num_parms, Imap->Cmd.Params);
1605 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "SUBSCRIBE")) {
1606 imap_subscribe(Imap->Cmd.num_parms, Imap->Cmd.Params);
1609 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "UNSUBSCRIBE")) {
1610 imap_unsubscribe(Imap->Cmd.num_parms, Imap->Cmd.Params);
1613 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "APPEND")) {
1614 imap_append(Imap->Cmd.num_parms, Imap->Cmd.Params);
1617 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "NAMESPACE")) {
1618 imap_namespace(Imap->Cmd.num_parms, Imap->Cmd.Params);
1621 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "SETACL")) {
1622 imap_setacl(Imap->Cmd.num_parms, Imap->Cmd.Params);
1625 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "DELETEACL")) {
1626 imap_deleteacl(Imap->Cmd.num_parms, Imap->Cmd.Params);
1629 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "GETACL")) {
1630 imap_getacl(Imap->Cmd.num_parms, Imap->Cmd.Params);
1633 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "LISTRIGHTS")) {
1634 imap_listrights(Imap->Cmd.num_parms, Imap->Cmd.Params);
1637 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "MYRIGHTS")) {
1638 imap_myrights(Imap->Cmd.num_parms, Imap->Cmd.Params);
1641 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "GETMETADATA")) {
1642 imap_getmetadata(Imap->Cmd.num_parms, Imap->Cmd.Params);
1645 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "SETMETADATA")) {
1646 imap_setmetadata(Imap->Cmd.num_parms, Imap->Cmd.Params);
1649 else if (Imap->selected == 0) {
1650 cprintf("%s BAD no folder selected\r\n", Imap->Cmd.Params[0].Key);
1653 /* The commands below require the SELECT state on a mailbox */
1655 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "FETCH")) {
1656 imap_fetch(Imap->Cmd.num_parms, Imap->Cmd.Params);
1659 else if ((!strcasecmp(Imap->Cmd.Params[1].Key, "UID"))
1660 && (!strcasecmp(Imap->Cmd.Params[2].Key, "FETCH"))) {
1661 imap_uidfetch(Imap->Cmd.num_parms, Imap->Cmd.Params);
1664 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "SEARCH")) {
1665 imap_search(Imap->Cmd.num_parms, Imap->Cmd.Params);
1668 else if ((!strcasecmp(Imap->Cmd.Params[1].Key, "UID"))
1669 && (!strcasecmp(Imap->Cmd.Params[2].Key, "SEARCH"))) {
1670 imap_uidsearch(Imap->Cmd.num_parms, Imap->Cmd.Params);
1673 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "STORE")) {
1674 imap_store(Imap->Cmd.num_parms, Imap->Cmd.Params);
1677 else if ((!strcasecmp(Imap->Cmd.Params[1].Key, "UID"))
1678 && (!strcasecmp(Imap->Cmd.Params[2].Key, "STORE"))) {
1679 imap_uidstore(Imap->Cmd.num_parms, Imap->Cmd.Params);
1682 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "COPY")) {
1683 imap_copy(Imap->Cmd.num_parms, Imap->Cmd.Params);
1686 else if ((!strcasecmp(Imap->Cmd.Params[1].Key, "UID")) && (!strcasecmp(Imap->Cmd.Params[2].Key, "COPY"))) {
1687 imap_uidcopy(Imap->Cmd.num_parms, Imap->Cmd.Params);
1690 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "EXPUNGE")) {
1691 imap_expunge(Imap->Cmd.num_parms, Imap->Cmd.Params);
1694 else if ((!strcasecmp(Imap->Cmd.Params[1].Key, "UID")) && (!strcasecmp(Imap->Cmd.Params[2].Key, "EXPUNGE"))) {
1695 imap_expunge(Imap->Cmd.num_parms, Imap->Cmd.Params);
1698 else if (!strcasecmp(Imap->Cmd.Params[1].Key, "CLOSE")) {
1699 imap_close(Imap->Cmd.num_parms, Imap->Cmd.Params);
1702 /* End of commands. If we get here, the command is either invalid
1707 cprintf("%s BAD command unrecognized\r\n", Imap->Cmd.Params[0].Key);
1710 /* If the client transmitted a message we can free it now */
1711 imap_free_transmitted_message();
1713 gettimeofday(&tv2, NULL);
1714 total_time = (tv2.tv_usec + (tv2.tv_sec * 1000000)) - (tv1.tv_usec + (tv1.tv_sec * 1000000));
1715 CtdlLogPrintf(CTDL_DEBUG, "IMAP command completed in %ld.%ld seconds\n",
1716 (total_time / 1000000),
1717 (total_time % 1000000)
1722 const char *CitadelServiceIMAP="IMAP";
1723 const char *CitadelServiceIMAPS="IMAPS";
1726 * This function is called to register the IMAP extension with Citadel.
1728 CTDL_MODULE_INIT(imap)
1732 CtdlRegisterServiceHook(config.c_imap_port,
1733 NULL, imap_greeting, imap_command_loop, NULL, CitadelServiceIMAP);
1735 CtdlRegisterServiceHook(config.c_imaps_port,
1736 NULL, imaps_greeting, imap_command_loop, NULL, CitadelServiceIMAPS);
1738 CtdlRegisterSessionHook(imap_cleanup_function, EVT_STOP);
1741 /* return our Subversion id for the Log */