4 * IMAP server for the Citadel/UX system
5 * Copyright (C) 2000-2001 by Art Cancro and others.
6 * This code is released under the terms of the GNU General Public License.
8 * WARNING: this is an incomplete implementation. It is now good enough to
9 * be usable with much of the popular IMAP client software available, but it
10 * is by no means perfect. Some commands (particularly SEARCH and RENAME)
11 * are implemented either incompletely or not at all.
13 * WARNING: Mark Crispin is an idiot. IMAP is the most brain-damaged protocol
14 * you will ever have the profound lack of pleasure to encounter.
26 #include <sys/types.h>
28 #if TIME_WITH_SYS_TIME
29 # include <sys/time.h>
33 # include <sys/time.h>
45 #include "sysdep_decls.h"
46 #include "citserver.h"
49 #include "dynloader.h"
56 #include "internet_addressing.h"
57 #include "serv_imap.h"
58 #include "imap_tools.h"
59 #include "imap_fetch.h"
60 #include "imap_search.h"
61 #include "imap_store.h"
62 #include "imap_misc.h"
69 * If there is a message ID map in memory, free it
71 void imap_free_msgids(void) {
72 if (IMAP->msgids != NULL) {
77 if (IMAP->flags != NULL) {
85 * If there is a transmitted message in memory, free it
87 void imap_free_transmitted_message(void) {
88 if (IMAP->transmitted_message != NULL) {
89 phree(IMAP->transmitted_message);
90 IMAP->transmitted_message = NULL;
91 IMAP->transmitted_length = 0;
97 * Set the \\Seen flag for messages which aren't new
99 void imap_set_seen_flags(void) {
103 CtdlGetRelationship(&vbuf, &CC->usersupp, &CC->quickroom);
104 if (IMAP->num_msgs > 0) {
105 for (i=0; i<IMAP->num_msgs; ++i) {
106 if (is_msg_in_mset(vbuf.v_seen, IMAP->msgids[i])) {
107 IMAP->flags[i] |= IMAP_SEEN;
117 * Back end for imap_load_msgids()
119 * Optimization: instead of calling realloc() to add each message, we
120 * allocate space in the list for REALLOC_INCREMENT messages at a time. This
121 * allows the mapping to proceed much faster.
123 void imap_add_single_msgid(long msgnum, void *userdata) {
125 IMAP->num_msgs = IMAP->num_msgs + 1;
126 if (IMAP->msgids == NULL) {
127 IMAP->msgids = mallok(IMAP->num_msgs * sizeof(long)
128 * REALLOC_INCREMENT);
130 else if (IMAP->num_msgs % REALLOC_INCREMENT == 0) {
131 IMAP->msgids = reallok(IMAP->msgids,
132 (IMAP->num_msgs + REALLOC_INCREMENT) * sizeof(long));
134 if (IMAP->flags == NULL) {
135 IMAP->flags = mallok(IMAP->num_msgs * sizeof(long)
136 * REALLOC_INCREMENT);
138 else if (IMAP->num_msgs % REALLOC_INCREMENT == 0) {
139 IMAP->flags = reallok(IMAP->flags,
140 (IMAP->num_msgs + REALLOC_INCREMENT) * sizeof(long));
142 IMAP->msgids[IMAP->num_msgs - 1] = msgnum;
143 IMAP->flags[IMAP->num_msgs - 1] = 0;
149 * Set up a message ID map for the current room (folder)
151 void imap_load_msgids(void) {
153 if (IMAP->selected == 0) {
154 lprintf(5, "imap_load_msgids() can't run; no room selected\n");
158 imap_free_msgids(); /* If there was already a map, free it */
160 CtdlForEachMessage(MSGS_ALL, 0L, (-63), NULL, NULL,
161 imap_add_single_msgid, NULL);
163 imap_set_seen_flags();
164 lprintf(9, "imap_load_msgids() mapped %d messages\n", IMAP->num_msgs);
169 * Re-scan the selected room (folder) and see if it's been changed at all
171 void imap_rescan_msgids(void) {
173 int original_num_msgs = 0;
174 long original_highest = 0L;
178 if (IMAP->selected == 0) {
179 lprintf(5, "imap_load_msgids() can't run; no room selected\n");
185 * Check to see if any of the messages we know about have been expunged
187 if (IMAP->num_msgs > 0)
188 for (i=0; i<IMAP->num_msgs; ++i) {
190 count = CtdlForEachMessage(MSGS_EQ, IMAP->msgids[i],
191 (-63), NULL, NULL, NULL, NULL);
194 cprintf("* %d EXPUNGE\r\n", i+1);
196 /* Here's some nice stupid nonsense. When a message
197 * is expunged, we have to slide all the existing
198 * messages up in the message array.
201 memcpy(&IMAP->msgids[i], &IMAP->msgids[i+1],
202 (sizeof(long)*(IMAP->num_msgs-i)) );
203 memcpy(&IMAP->flags[i], &IMAP->flags[i+1],
204 (sizeof(long)*(IMAP->num_msgs-i)) );
212 * Remember how many messages were here before we re-scanned.
214 original_num_msgs = IMAP->num_msgs;
215 if (IMAP->num_msgs > 0) {
216 original_highest = IMAP->msgids[IMAP->num_msgs - 1];
219 original_highest = 0L;
223 * Now peruse the room for *new* messages only.
225 CtdlForEachMessage(MSGS_GT, original_highest, (-63), NULL, NULL,
226 imap_add_single_msgid, NULL);
228 imap_set_seen_flags();
231 * If new messages have arrived, tell the client about them.
233 if (IMAP->num_msgs > original_num_msgs) {
234 cprintf("* %d EXISTS\r\n", IMAP->num_msgs);
246 * This cleanup function blows away the temporary memory and files used by
249 void imap_cleanup_function(void) {
251 /* Don't do this stuff if this is not a IMAP session! */
252 if (CC->h_command_function != imap_command_loop) return;
254 lprintf(9, "Performing IMAP cleanup hook\n");
256 imap_free_transmitted_message();
257 lprintf(9, "Finished IMAP cleanup hook\n");
263 * Here's where our IMAP session begins its happy day.
265 void imap_greeting(void) {
267 strcpy(CC->cs_clientname, "IMAP session");
268 CtdlAllocUserData(SYM_IMAP, sizeof(struct citimap));
269 IMAP->authstate = imap_as_normal;
271 cprintf("* OK %s Citadel/UX IMAP4rev1 server ready\r\n",
277 * implements the LOGIN command (ordinary username/password login)
279 void imap_login(int num_parms, char *parms[]) {
280 if (CtdlLoginExistingUser(parms[2]) == login_ok) {
281 if (CtdlTryPassword(parms[3]) == pass_ok) {
282 cprintf("%s OK login successful\r\n", parms[0]);
287 cprintf("%s BAD Login incorrect\r\n", parms[0]);
292 * Implements the AUTHENTICATE command
294 void imap_authenticate(int num_parms, char *parms[]) {
297 if (num_parms != 3) {
298 cprintf("%s BAD incorrect number of parameters\r\n", parms[0]);
302 if (!strcasecmp(parms[2], "LOGIN")) {
303 encode_base64(buf, "Username:");
304 cprintf("+ %s\r\n", buf);
305 IMAP->authstate = imap_as_expecting_username;
306 strcpy(IMAP->authseq, parms[0]);
311 cprintf("%s NO AUTHENTICATE %s failed\r\n",
316 void imap_auth_login_user(char *cmd) {
319 decode_base64(buf, cmd);
320 CtdlLoginExistingUser(buf);
321 encode_base64(buf, "Password:");
322 cprintf("+ %s\r\n", buf);
323 IMAP->authstate = imap_as_expecting_password;
327 void imap_auth_login_pass(char *cmd) {
330 decode_base64(buf, cmd);
331 if (CtdlTryPassword(buf) == pass_ok) {
332 cprintf("%s OK authentication succeeded\r\n", IMAP->authseq);
335 cprintf("%s NO authentication failed\r\n", IMAP->authseq);
337 IMAP->authstate = imap_as_normal;
344 * implements the CAPABILITY command
346 void imap_capability(int num_parms, char *parms[]) {
347 cprintf("* CAPABILITY IMAP4 IMAP4REV1 AUTH=LOGIN\r\n");
348 cprintf("%s OK CAPABILITY completed\r\n", parms[0]);
356 * implements the SELECT command
358 void imap_select(int num_parms, char *parms[]) {
360 char augmented_roomname[ROOMNAMELEN];
364 struct quickroom QRscratch;
370 /* Convert the supplied folder name to a roomname */
371 i = imap_roomname(towhere, sizeof towhere, parms[2]);
373 cprintf("%s NO Invalid mailbox name.\r\n", parms[0]);
377 floornum = (i & 0x00ff);
378 roomflags = (i & 0xff00);
380 /* First try a regular match */
381 c = getroom(&QRscratch, towhere);
383 /* Then try a mailbox name match */
385 MailboxName(augmented_roomname, &CC->usersupp, towhere);
386 c = getroom(&QRscratch, augmented_roomname);
388 strcpy(towhere, augmented_roomname);
391 /* If the room exists, check security/access */
393 /* See if there is an existing user/room relationship */
394 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
396 /* normal clients have to pass through security */
402 /* Fail here if no such room */
404 cprintf("%s NO ... no such room, or access denied\r\n",
411 * usergoto() formally takes us to the desired room, happily returning
412 * the number of messages and number of new messages.
414 usergoto(QRscratch.QRname, 0, &msgs, &new);
417 if (!strcasecmp(parms[1], "EXAMINE")) {
426 /* FIXME ... much more info needs to be supplied here */
427 cprintf("* %d EXISTS\r\n", msgs);
428 cprintf("* %d RECENT\r\n", new);
429 cprintf("* FLAGS (\\Deleted \\Seen)\r\n");
430 cprintf("* OK [PERMANENTFLAGS (\\Deleted \\Seen)] permanent flags\r\n");
431 cprintf("* OK [UIDVALIDITY 0] UIDs valid\r\n");
432 cprintf("%s OK [%s] %s completed\r\n",
434 (IMAP->readonly ? "READ-ONLY" : "READ-WRITE"),
441 * does the real work for expunge
443 int imap_do_expunge(void) {
445 int num_expunged = 0;
447 if (IMAP->num_msgs > 0) for (i=0; i<IMAP->num_msgs; ++i) {
448 if (IMAP->flags[i] & IMAP_DELETED) {
449 CtdlDeleteMessages(CC->quickroom.QRname,
450 IMAP->msgids[i], "");
455 if (num_expunged > 0) {
456 imap_rescan_msgids();
459 return(num_expunged);
464 * implements the EXPUNGE command syntax
466 void imap_expunge(int num_parms, char *parms[]) {
467 int num_expunged = 0;
469 cprintf("%s OK expunged %d messages.\r\n", parms[0], num_expunged);
474 * implements the CLOSE command
476 void imap_close(int num_parms, char *parms[]) {
478 /* Yes, we always expunge on close. */
484 cprintf("%s OK CLOSE completed\r\n", parms[0]);
491 * Used by LIST and LSUB to show the floors in the listing
493 void imap_list_floors(char *cmd, char *pattern) {
497 for (i=0; i<MAXFLOORS; ++i) {
499 if (fl->f_flags & F_INUSE) {
500 if (imap_mailbox_matches_pattern(pattern, fl->f_name)) {
501 cprintf("* %s (\\NoSelect) \"|\" ", cmd);
502 imap_strout(fl->f_name);
512 * Back end for imap_lsub()
514 * IMAP "subscribed folder" is equivocated to Citadel "known rooms." This
515 * may or may not be the desired behavior in the future.
517 void imap_lsub_listroom(struct quickroom *qrbuf, void *data) {
522 pattern = (char *)data;
524 /* Only list rooms to which the user has access!! */
525 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
527 imap_mailboxname(buf, sizeof buf, qrbuf);
528 if (imap_mailbox_matches_pattern(pattern, buf)) {
529 cprintf("* LSUB (\\NoInferiors) \"|\" ");
538 * Implements the LSUB command
540 void imap_lsub(int num_parms, char *parms[]) {
543 cprintf("%s BAD arguments invalid\r\n", parms[0]);
546 sprintf(pattern, "%s%s", parms[2], parms[3]);
548 if (strlen(parms[3])==0) {
549 cprintf("* LIST (\\Noselect) \"|\" \"\"\r\n");
553 imap_list_floors("LSUB", pattern);
554 ForEachRoom(imap_lsub_listroom, pattern);
557 cprintf("%s OK LSUB completed\r\n", parms[0]);
563 * Back end for imap_list()
565 void imap_list_listroom(struct quickroom *qrbuf, void *data) {
570 pattern = (char *)data;
572 /* Only list rooms to which the user has access!! */
573 ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
575 || ((ra & UA_GOTOALLOWED) && (ra & UA_ZAPPED))) {
576 imap_mailboxname(buf, sizeof buf, qrbuf);
577 if (imap_mailbox_matches_pattern(pattern, buf)) {
578 cprintf("* LIST (\\NoInferiors) \"|\" ");
587 * Implements the LIST command
589 void imap_list(int num_parms, char *parms[]) {
592 cprintf("%s BAD arguments invalid\r\n", parms[0]);
595 sprintf(pattern, "%s%s", parms[2], parms[3]);
597 if (strlen(parms[3])==0) {
598 cprintf("* LIST (\\Noselect) \"|\" \"\"\r\n");
602 imap_list_floors("LIST", pattern);
603 ForEachRoom(imap_list_listroom, pattern);
606 cprintf("%s OK LIST completed\r\n", parms[0]);
612 * Implements the CREATE command
615 void imap_create(int num_parms, char *parms[]) {
617 char roomname[ROOMNAMELEN];
622 ret = imap_roomname(roomname, sizeof roomname, parms[2]);
624 cprintf("%s NO Invalid mailbox name or location\r\n",
628 floornum = ( ret & 0x00ff ); /* lower 8 bits = floor number */
629 flags = ( ret & 0xff00 ); /* upper 8 bits = flags */
631 if (flags & IR_MAILBOX) {
632 newroomtype = 4; /* private mailbox */
635 newroomtype = 0; /* public folder */
638 lprintf(7, "Create new room <%s> on floor <%d> with type <%d>\n",
639 roomname, floornum, newroomtype);
641 ret = create_room(roomname, newroomtype, "", floornum, 1);
643 cprintf("%s NO Mailbox already exists, or create failed\r\n",
647 cprintf("%s OK CREATE completed\r\n", parms[0]);
653 * Locate a room by its IMAP folder name, and check access to it
655 int imap_grabroom(char *returned_roomname, char *foldername) {
657 char augmented_roomname[ROOMNAMELEN];
658 char roomname[ROOMNAMELEN];
660 struct quickroom QRscratch;
664 ret = imap_roomname(roomname, sizeof roomname, foldername);
669 /* First try a regular match */
670 c = getroom(&QRscratch, roomname);
672 /* Then try a mailbox name match */
674 MailboxName(augmented_roomname, &CC->usersupp, roomname);
675 c = getroom(&QRscratch, augmented_roomname);
677 strcpy(roomname, augmented_roomname);
680 /* If the room exists, check security/access */
682 /* See if there is an existing user/room relationship */
683 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
685 /* normal clients have to pass through security */
691 /* Fail here if no such room */
693 strcpy(returned_roomname, "");
697 strcpy(returned_roomname, QRscratch.QRname);
704 * Implements the STATUS command (sort of)
707 void imap_status(int num_parms, char *parms[]) {
709 char roomname[ROOMNAMELEN];
711 char savedroom[ROOMNAMELEN];
714 ret = imap_grabroom(roomname, parms[2]);
716 cprintf("%s NO Invalid mailbox name or location, or access denied\r\n",
722 * usergoto() formally takes us to the desired room, happily returning
723 * the number of messages and number of new messages. (If another
724 * folder is selected, save its name so we can return there!!!!!)
726 if (IMAP->selected) {
727 strcpy(savedroom, CC->quickroom.QRname);
729 usergoto(roomname, 0, &msgs, &new);
732 * Tell the client what it wants to know. In fact, tell it *more* than
733 * it wants to know. We happily IGnore the supplied status data item
734 * names and simply spew all possible data items. It's far easier to
735 * code and probably saves us some processing time too.
737 imap_mailboxname(buf, sizeof buf, &CC->quickroom);
738 cprintf("* STATUS ");
740 cprintf(" (MESSAGES %d ", msgs);
741 cprintf("RECENT 0 "); /* FIXME we need to implement this */
742 cprintf("UIDNEXT %ld ", CitControl.MMhighest + 1);
743 cprintf("UNSEEN %d)\r\n", new);
746 * If another folder is selected, go back to that room so we can resume
747 * our happy day without violent explosions.
749 if (IMAP->selected) {
750 usergoto(savedroom, 0, &msgs, &new);
754 * Oooh, look, we're done!
756 cprintf("%s OK STATUS completed\r\n", parms[0]);
762 * Implements the SUBSCRIBE command
765 void imap_subscribe(int num_parms, char *parms[]) {
767 char roomname[ROOMNAMELEN];
768 char savedroom[ROOMNAMELEN];
771 ret = imap_grabroom(roomname, parms[2]);
773 cprintf("%s NO Invalid mailbox name or location, or access denied\r\n",
779 * usergoto() formally takes us to the desired room, which has the side
780 * effect of marking the room as not-zapped ... exactly the effect
783 if (IMAP->selected) {
784 strcpy(savedroom, CC->quickroom.QRname);
786 usergoto(roomname, 0, &msgs, &new);
789 * If another folder is selected, go back to that room so we can resume
790 * our happy day without violent explosions.
792 if (IMAP->selected) {
793 usergoto(savedroom, 0, &msgs, &new);
796 cprintf("%s OK SUBSCRIBE completed\r\n", parms[0]);
801 * Implements the UNSUBSCRIBE command
804 void imap_unsubscribe(int num_parms, char *parms[]) {
806 char roomname[ROOMNAMELEN];
807 char savedroom[ROOMNAMELEN];
810 ret = imap_grabroom(roomname, parms[2]);
812 cprintf("%s NO Invalid mailbox name or location, or access denied\r\n",
818 * usergoto() formally takes us to the desired room.
820 if (IMAP->selected) {
821 strcpy(savedroom, CC->quickroom.QRname);
823 usergoto(roomname, 0, &msgs, &new);
826 * Now make the API call to zap the room
828 if (CtdlForgetThisRoom() == 0) {
829 cprintf("%s OK UNSUBSCRIBE completed\r\n", parms[0]);
832 cprintf("%s NO You may not unsubscribe from this folder.\r\n",
837 * If another folder is selected, go back to that room so we can resume
838 * our happy day without violent explosions.
840 if (IMAP->selected) {
841 usergoto(savedroom, 0, &msgs, &new);
848 * Implements the DELETE command
851 void imap_delete(int num_parms, char *parms[]) {
853 char roomname[ROOMNAMELEN];
854 char savedroom[ROOMNAMELEN];
857 ret = imap_grabroom(roomname, parms[2]);
859 cprintf("%s NO Invalid mailbox name, or access denied\r\n",
865 * usergoto() formally takes us to the desired room, happily returning
866 * the number of messages and number of new messages. (If another
867 * folder is selected, save its name so we can return there!!!!!)
869 if (IMAP->selected) {
870 strcpy(savedroom, CC->quickroom.QRname);
872 usergoto(roomname, 0, &msgs, &new);
875 * Now delete the room.
877 if (CtdlDoIHavePermissionToDeleteThisRoom(&CC->quickroom)) {
878 cprintf("%s OK DELETE completed\r\n", parms[0]);
879 delete_room(&CC->quickroom);
882 cprintf("%s NO Can't delete this folder.\r\n", parms[0]);
886 * If another folder is selected, go back to that room so we can resume
887 * our happy day without violent explosions.
889 if (IMAP->selected) {
890 usergoto(savedroom, 0, &msgs, &new);
897 * Implements the RENAME command
900 void imap_rename(int num_parms, char *parms[]) {
901 cprintf("%s NO The RENAME command is not yet implemented (FIXME)\r\n",
908 * Main command loop for IMAP sessions.
910 void imap_command_loop(void) {
916 memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
917 if (client_gets(cmdbuf) < 1) {
918 lprintf(3, "IMAP socket is broken. Ending session.\r\n");
923 lprintf(5, "citserver[%3d]: %s\r\n", CC->cs_pid, cmdbuf);
924 while (strlen(cmdbuf) < 5) strcat(cmdbuf, " ");
927 /* strip off l/t whitespace and CRLF */
928 if (cmdbuf[strlen(cmdbuf)-1]=='\n') cmdbuf[strlen(cmdbuf)-1]=0;
929 if (cmdbuf[strlen(cmdbuf)-1]=='\r') cmdbuf[strlen(cmdbuf)-1]=0;
932 /* If we're in the middle of a multi-line command, handle that */
933 if (IMAP->authstate == imap_as_expecting_username) {
934 imap_auth_login_user(cmdbuf);
937 if (IMAP->authstate == imap_as_expecting_password) {
938 imap_auth_login_pass(cmdbuf);
943 /* Ok, at this point we're in normal command mode. The first thing
944 * we do is print any incoming pages (yeah! we really do!)
946 imap_print_express_messages();
949 * Before processing the command that was just entered... if we happen
950 * to have a folder selected, we'd like to rescan that folder for new
951 * messages, and for deletions/changes of existing messages. This
952 * could probably be optimized somehow, but IMAP sucks...
954 if (IMAP->selected) {
955 imap_rescan_msgids();
958 /* Now for the command set. */
960 /* Grab the tag, command, and parameters. Check syntax. */
961 num_parms = imap_parameterize(parms, cmdbuf);
963 cprintf("BAD syntax error\r\n");
966 /* The commands below may be executed in any state */
968 else if ( (!strcasecmp(parms[1], "NOOP"))
969 || (!strcasecmp(parms[1], "CHECK")) ) {
970 cprintf("%s OK This command successfully did nothing.\r\n",
974 else if (!strcasecmp(parms[1], "LOGOUT")) {
975 cprintf("* BYE %s logging out\r\n", config.c_fqdn);
976 cprintf("%s OK thank you for using Citadel IMAP\r\n", parms[0]);
981 else if (!strcasecmp(parms[1], "LOGIN")) {
982 imap_login(num_parms, parms);
985 else if (!strcasecmp(parms[1], "AUTHENTICATE")) {
986 imap_authenticate(num_parms, parms);
989 else if (!strcasecmp(parms[1], "CAPABILITY")) {
990 imap_capability(num_parms, parms);
993 else if (!CC->logged_in) {
994 cprintf("%s BAD Not logged in.\r\n", parms[0]);
997 /* The commans below require a logged-in state */
999 else if (!strcasecmp(parms[1], "SELECT")) {
1000 imap_select(num_parms, parms);
1003 else if (!strcasecmp(parms[1], "EXAMINE")) {
1004 imap_select(num_parms, parms);
1007 else if (!strcasecmp(parms[1], "LSUB")) {
1008 imap_lsub(num_parms, parms);
1011 else if (!strcasecmp(parms[1], "LIST")) {
1012 imap_list(num_parms, parms);
1015 else if (!strcasecmp(parms[1], "CREATE")) {
1016 imap_create(num_parms, parms);
1019 else if (!strcasecmp(parms[1], "DELETE")) {
1020 imap_delete(num_parms, parms);
1023 else if (!strcasecmp(parms[1], "RENAME")) {
1024 imap_rename(num_parms, parms);
1027 else if (!strcasecmp(parms[1], "STATUS")) {
1028 imap_status(num_parms, parms);
1031 else if (!strcasecmp(parms[1], "SUBSCRIBE")) {
1032 imap_subscribe(num_parms, parms);
1035 else if (!strcasecmp(parms[1], "UNSUBSCRIBE")) {
1036 imap_unsubscribe(num_parms, parms);
1039 else if (!strcasecmp(parms[1], "APPEND")) {
1040 imap_append(num_parms, parms);
1043 else if (IMAP->selected == 0) {
1044 cprintf("%s BAD no folder selected\r\n", parms[0]);
1047 /* The commands below require the SELECT state on a mailbox */
1049 else if (!strcasecmp(parms[1], "FETCH")) {
1050 imap_fetch(num_parms, parms);
1053 else if ( (!strcasecmp(parms[1], "UID"))
1054 && (!strcasecmp(parms[2], "FETCH")) ) {
1055 imap_uidfetch(num_parms, parms);
1058 else if (!strcasecmp(parms[1], "SEARCH")) {
1059 imap_search(num_parms, parms);
1062 else if ( (!strcasecmp(parms[1], "UID"))
1063 && (!strcasecmp(parms[2], "SEARCH")) ) {
1064 imap_uidsearch(num_parms, parms);
1067 else if (!strcasecmp(parms[1], "STORE")) {
1068 imap_store(num_parms, parms);
1071 else if ( (!strcasecmp(parms[1], "UID"))
1072 && (!strcasecmp(parms[2], "STORE")) ) {
1073 imap_uidstore(num_parms, parms);
1076 else if (!strcasecmp(parms[1], "COPY")) {
1077 imap_copy(num_parms, parms);
1080 else if ( (!strcasecmp(parms[1], "UID"))
1081 && (!strcasecmp(parms[2], "COPY")) ) {
1082 imap_uidcopy(num_parms, parms);
1085 else if (!strcasecmp(parms[1], "EXPUNGE")) {
1086 imap_expunge(num_parms, parms);
1089 else if (!strcasecmp(parms[1], "CLOSE")) {
1090 imap_close(num_parms, parms);
1093 /* End of commands. If we get here, the command is either invalid
1098 cprintf("%s BAD command unrecognized\r\n", parms[0]);
1101 /* If the client transmitted a message we can free it now */
1102 imap_free_transmitted_message();
1108 * This function is called by dynloader.c to register the IMAP module
1109 * with the Citadel server.
1111 char *Dynamic_Module_Init(void)
1113 SYM_IMAP = CtdlGetDynamicSymbol();
1114 CtdlRegisterServiceHook(config.c_imap_port,
1118 CtdlRegisterSessionHook(imap_cleanup_function, EVT_STOP);