]> code.citadel.org Git - citadel.git/blob - citadel/serv_imap.c
* Wrote a bit of the IMAP STORE command
[citadel.git] / citadel / serv_imap.c
1 /*
2  * $Id$ 
3  *
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.
7  *
8  * WARNING: this is an incomplete implementation, still in progress.  Parts of
9  * it work, but it's not really usable yet from a user perspective.
10  *
11  * WARNING: Mark Crispin is an idiot.  IMAP is the most brain-damaged protocol
12  * you will ever have the profound lack of pleasure to encounter.
13  * 
14  */
15
16 #include "sysdep.h"
17 #include <stdlib.h>
18 #include <unistd.h>
19 #include <stdio.h>
20 #include <fcntl.h>
21 #include <signal.h>
22 #include <pwd.h>
23 #include <errno.h>
24 #include <sys/types.h>
25 #include <sys/time.h>
26 #include <sys/wait.h>
27 #include <ctype.h>
28 #include <string.h>
29 #include <limits.h>
30 #include "citadel.h"
31 #include "server.h"
32 #include <time.h>
33 #include "sysdep_decls.h"
34 #include "citserver.h"
35 #include "support.h"
36 #include "config.h"
37 #include "dynloader.h"
38 #include "room_ops.h"
39 #include "user_ops.h"
40 #include "policy.h"
41 #include "database.h"
42 #include "msgbase.h"
43 #include "tools.h"
44 #include "internet_addressing.h"
45 #include "serv_imap.h"
46 #include "imap_tools.h"
47 #include "imap_fetch.h"
48 #include "imap_search.h"
49 #include "imap_store.h"
50
51
52 long SYM_IMAP;
53
54
55 /*
56  * If there is a message ID map in memory, free it
57  */
58 void imap_free_msgids(void) {
59         if (IMAP->msgids != NULL) {
60                 phree(IMAP->msgids);
61                 IMAP->msgids = NULL;
62                 IMAP->num_msgs = 0;
63         }
64         if (IMAP->flags != NULL) {
65                 phree(IMAP->flags);
66                 IMAP->flags = NULL;
67         }
68 }
69
70
71 /*
72  * Back end for imap_load_msgids()
73  *
74  * FIXME: this should be optimized by figuring out a way to allocate memory
75  * once rather than doing a reallok() for each message.
76  */
77 void imap_add_single_msgid(long msgnum, void *userdata) {
78         
79         IMAP->num_msgs = IMAP->num_msgs + 1;
80         if (IMAP->msgids == NULL) {
81                 IMAP->msgids = mallok(IMAP->num_msgs * sizeof(long));
82         }
83         else {
84                 IMAP->msgids = reallok(IMAP->msgids,
85                         IMAP->num_msgs * sizeof(long));
86         }
87         if (IMAP->flags == NULL) {
88                 IMAP->flags = mallok(IMAP->num_msgs * sizeof(long));
89         }
90         else {
91                 IMAP->flags = reallok(IMAP->flags,
92                         IMAP->num_msgs * sizeof(long));
93         }
94         IMAP->msgids[IMAP->num_msgs - 1] = msgnum;
95         IMAP->flags[IMAP->num_msgs - 1] = 0;
96 }
97
98
99
100 /*
101  * Set up a message ID map for the current room (folder)
102  */
103 void imap_load_msgids(void) {
104          
105         if (IMAP->selected == 0) {
106                 lprintf(5, "imap_load_msgids() can't run; no room selected\n");
107                 return;
108         }
109
110         imap_free_msgids();     /* If there was already a map, free it */
111
112         CtdlForEachMessage(MSGS_ALL, 0L, (-63), NULL, NULL,
113                 imap_add_single_msgid, NULL);
114
115         lprintf(9, "imap_load_msgids() mapped %d messages\n", IMAP->num_msgs);
116 }
117
118
119 /*
120  * Re-scan the selected room (folder) and see if it's been changed at all
121  */
122 void imap_rescan_msgids(void) {
123
124         int original_num_msgs = 0;
125         long original_highest = 0L;
126         int i;
127         int count;
128
129         if (IMAP->selected == 0) {
130                 lprintf(5, "imap_load_msgids() can't run; no room selected\n");
131                 return;
132         }
133
134
135         /*
136          * Check to see if any of the messages we know about have been expunged
137          */
138         if (IMAP->num_msgs > 0)
139          for (i=0; i<IMAP->num_msgs; ++i)
140           if ((IMAP->flags[i] & IMAP_EXPUNGED) == 0) {
141
142                 count = CtdlForEachMessage(MSGS_EQ, IMAP->msgids[i],
143                         (-63), NULL, NULL, NULL, NULL);
144
145                 if (count == 0) {
146                         IMAP->flags[i] = IMAP->flags[i] | IMAP_EXPUNGED;
147                         cprintf("* %d EXPUNGE\r\n", i+1);
148                 }
149
150         }
151
152         /*
153          * Remember how many messages were here before we re-scanned.
154          */
155         original_num_msgs = IMAP->num_msgs;
156         if (IMAP->num_msgs > 0) {
157                 original_highest = IMAP->msgids[IMAP->num_msgs - 1];
158         }
159         else {
160                 original_highest = 0L;
161         }
162
163         /*
164          * Now peruse the room for *new* messages only.
165          */
166         CtdlForEachMessage(MSGS_GT, original_highest, (-63), NULL, NULL,
167                 imap_add_single_msgid, NULL);
168
169         /*
170          * If new messages have arrived, tell the client about them.
171          */
172         if (IMAP->num_msgs > original_num_msgs) {
173                 cprintf("* %d EXISTS\r\n", IMAP->num_msgs);
174         }
175
176 }
177
178
179
180
181
182
183
184 /*
185  * This cleanup function blows away the temporary memory and files used by
186  * the IMAP server.
187  */
188 void imap_cleanup_function(void) {
189
190         /* Don't do this stuff if this is not a IMAP session! */
191         if (CC->h_command_function != imap_command_loop) return;
192
193         lprintf(9, "Performing IMAP cleanup hook\n");
194         imap_free_msgids();
195         lprintf(9, "Finished IMAP cleanup hook\n");
196 }
197
198
199
200 /*
201  * Here's where our IMAP session begins its happy day.
202  */
203 void imap_greeting(void) {
204
205         strcpy(CC->cs_clientname, "IMAP session");
206         CtdlAllocUserData(SYM_IMAP, sizeof(struct citimap));
207         IMAP->authstate = imap_as_normal;
208
209         cprintf("* OK %s Citadel/UX IMAP4rev1 server ready\r\n",
210                 config.c_fqdn);
211 }
212
213
214 /*
215  * implements the LOGIN command (ordinary username/password login)
216  */
217 void imap_login(int num_parms, char *parms[]) {
218         if (CtdlLoginExistingUser(parms[2]) == login_ok) {
219                 if (CtdlTryPassword(parms[3]) == pass_ok) {
220                         cprintf("%s OK login successful\r\n", parms[0]);
221                         return;
222                 }
223         }
224
225         cprintf("%s BAD Login incorrect\r\n", parms[0]);
226 }
227
228
229 /*
230  * Implements the AUTHENTICATE command
231  */
232 void imap_authenticate(int num_parms, char *parms[]) {
233         char buf[SIZ];
234
235         if (num_parms != 3) {
236                 cprintf("%s BAD incorrect number of parameters\r\n", parms[0]);
237                 return;
238         }
239
240         if (!strcasecmp(parms[2], "LOGIN")) {
241                 encode_base64(buf, "Username:");
242                 cprintf("+ %s\r\n", buf);
243                 IMAP->authstate = imap_as_expecting_username;
244                 strcpy(IMAP->authseq, parms[0]);
245                 return;
246         }
247
248         else {
249                 cprintf("%s NO AUTHENTICATE %s failed\r\n",
250                         parms[0], parms[1]);
251         }
252 }
253
254 void imap_auth_login_user(char *cmd) {
255         char buf[SIZ];
256
257         decode_base64(buf, cmd);
258         CtdlLoginExistingUser(buf);
259         encode_base64(buf, "Password:");
260         cprintf("+ %s\r\n", buf);
261         IMAP->authstate = imap_as_expecting_password;
262         return;
263 }
264
265 void imap_auth_login_pass(char *cmd) {
266         char buf[SIZ];
267
268         decode_base64(buf, cmd);
269         if (CtdlTryPassword(buf) == pass_ok) {
270                 cprintf("%s OK authentication succeeded\r\n", IMAP->authseq);
271         }
272         else {
273                 cprintf("%s NO authentication failed\r\n", IMAP->authseq);
274         }
275         IMAP->authstate = imap_as_normal;
276         return;
277 }
278
279
280
281 /*
282  * implements the CAPABILITY command
283  */
284 void imap_capability(int num_parms, char *parms[]) {
285         cprintf("* CAPABILITY IMAP4 IMAP4REV1 AUTH=LOGIN\r\n");
286         cprintf("%s OK CAPABILITY completed\r\n", parms[0]);
287 }
288
289
290
291
292
293 /*
294  * implements the SELECT command
295  */
296 void imap_select(int num_parms, char *parms[]) {
297         char towhere[SIZ];
298         char augmented_roomname[ROOMNAMELEN];
299         int c = 0;
300         int ok = 0;
301         int ra = 0;
302         struct quickroom QRscratch;
303         int msgs, new;
304         int floornum;
305         int roomflags;
306         int i;
307
308         /* Convert the supplied folder name to a roomname */
309         i = imap_roomname(towhere, sizeof towhere, parms[2]);
310         if (i < 0) {
311                 cprintf("%s NO Invalid mailbox name.\r\n", parms[0]);
312                 IMAP->selected = 0;
313                 return;
314         }
315         floornum = (i & 0x00ff);
316         roomflags = (i & 0xff00);
317
318         /* First try a regular match */
319         c = getroom(&QRscratch, towhere);
320
321         /* Then try a mailbox name match */
322         if (c != 0) {
323                 MailboxName(augmented_roomname, &CC->usersupp, towhere);
324                 c = getroom(&QRscratch, augmented_roomname);
325                 if (c == 0)
326                         strcpy(towhere, augmented_roomname);
327         }
328
329         /* If the room exists, check security/access */
330         if (c == 0) {
331                 /* See if there is an existing user/room relationship */
332                 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
333
334                 /* normal clients have to pass through security */
335                 if (ra & UA_KNOWN) {
336                         ok = 1;
337                 }
338         }
339
340         /* Fail here if no such room */
341         if (!ok) {
342                 cprintf("%s NO ... no such room, or access denied\r\n",
343                         parms[0]);
344                 IMAP->selected = 0;
345                 return;
346         }
347
348         /*
349          * usergoto() formally takes us to the desired room, happily returning
350          * the number of messages and number of new messages.
351          */
352         usergoto(QRscratch.QRname, 0, &msgs, &new);
353         IMAP->selected = 1;
354
355         if (!strcasecmp(parms[1], "EXAMINE")) {
356                 IMAP->readonly = 1;
357         }
358         else {
359                 IMAP->readonly = 0;
360         }
361
362         imap_load_msgids();
363
364         /* FIXME ... much more info needs to be supplied here */
365         cprintf("* %d EXISTS\r\n", msgs);
366         cprintf("* %d RECENT\r\n", new);
367         cprintf("* OK [UIDVALIDITY 0] UIDs valid\r\n");
368         cprintf("* FLAGS (\\Deleted)\r\n");
369         cprintf("%s OK [%s] %s completed\r\n",
370                 parms[0],
371                 (IMAP->readonly ? "READ-ONLY" : "READ-WRITE"),
372                 parms[1]);
373 }
374
375
376
377 /*
378  * implements the CLOSE command
379  */
380 void imap_close(int num_parms, char *parms[]) {
381         IMAP->selected = 0;
382         IMAP->readonly = 0;
383         imap_free_msgids();
384         cprintf("%s OK CLOSE completed\r\n", parms[0]);
385 }
386
387
388
389
390 /*
391  * Used by LIST and LSUB to show the floors in the listing
392  */
393 void imap_list_floors(char *cmd) {
394         int i;
395         struct floor *fl;
396
397         for (i=0; i<MAXFLOORS; ++i) {
398                 fl = cgetfloor(i);
399                 if (fl->f_flags & F_INUSE) {
400                         cprintf("* %s (\\NoSelect) \"|\" ", cmd);
401                         imap_strout(fl->f_name);
402                         cprintf("\r\n");
403                 }
404         }
405 }
406
407
408
409 /*
410  * Back end for imap_lsub()
411  *
412  * IMAP "subscribed folder" is equivocated to Citadel "known rooms."  This
413  * may or may not be the desired behavior in the future.
414  */
415 void imap_lsub_listroom(struct quickroom *qrbuf, void *data) {
416         char buf[SIZ];
417         int ra;
418
419         /* Only list rooms to which the user has access!! */
420         ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
421         if (ra & UA_KNOWN) {
422                 imap_mailboxname(buf, sizeof buf, qrbuf);
423                 cprintf("* LSUB () \"|\" ");
424                 imap_strout(buf);
425                 cprintf("\r\n");
426         }
427 }
428
429
430 /*
431  * Implements the LSUB command
432  *
433  * FIXME: Handle wildcards, please.
434  */
435 void imap_lsub(int num_parms, char *parms[]) {
436         imap_list_floors("LSUB");
437         ForEachRoom(imap_lsub_listroom, NULL);
438         cprintf("%s OK LSUB completed\r\n", parms[0]);
439 }
440
441
442
443 /*
444  * Back end for imap_list()
445  */
446 void imap_list_listroom(struct quickroom *qrbuf, void *data) {
447         char buf[SIZ];
448         int ra;
449
450         /* Only list rooms to which the user has access!! */
451         ra = CtdlRoomAccess(qrbuf, &CC->usersupp);
452         if ( (ra & UA_KNOWN) 
453           || ((ra & UA_GOTOALLOWED) && (ra & UA_ZAPPED))) {
454                 imap_mailboxname(buf, sizeof buf, qrbuf);
455                 cprintf("* LIST () \"|\" ");
456                 imap_strout(buf);
457                 cprintf("\r\n");
458         }
459 }
460
461
462 /*
463  * Implements the LIST command
464  *
465  * FIXME: Handle wildcards, please.
466  */
467 void imap_list(int num_parms, char *parms[]) {
468         imap_list_floors("LIST");
469         ForEachRoom(imap_list_listroom, NULL);
470         cprintf("%s OK LIST completed\r\n", parms[0]);
471 }
472
473
474
475 /*
476  * Implements the CREATE command
477  *
478  */
479 void imap_create(int num_parms, char *parms[]) {
480         int ret;
481         char roomname[ROOMNAMELEN];
482         int floornum;
483         int flags;
484         int newroomtype;
485
486         ret = imap_roomname(roomname, sizeof roomname, parms[2]);
487         if (ret < 0) {
488                 cprintf("%s NO Invalid mailbox name or location\r\n",
489                         parms[0]);
490                 return;
491         }
492         floornum = ( ret & 0x00ff );    /* lower 8 bits = floor number */
493         flags =    ( ret & 0xff00 );    /* upper 8 bits = flags        */
494
495         if (flags & IR_MAILBOX) {
496                 newroomtype = 4;        /* private mailbox */
497         }
498         else {
499                 newroomtype = 0;        /* public folder */
500         }
501
502         lprintf(7, "Create new room <%s> on floor <%d> with type <%d>\n",
503                 roomname, floornum, newroomtype);
504
505         ret = create_room(roomname, newroomtype, "", floornum, 1);
506         if (ret == 0) {
507                 cprintf("%s NO Mailbox already exists, or create failed\r\n",
508                         parms[0]);
509         }
510         else {
511                 cprintf("%s OK CREATE completed\r\n", parms[0]);
512         }
513 }
514
515
516 /*
517  * Implements the STATUS command (sort of)
518  *
519  */
520 void imap_status(int num_parms, char *parms[]) {
521         int ret;
522         char augmented_roomname[ROOMNAMELEN];
523         char roomname[ROOMNAMELEN];
524         char buf[SIZ];
525         int c;
526         struct quickroom QRscratch;
527         int ra;
528         int ok = 0;
529         char savedroom[ROOMNAMELEN];
530         int msgs, new;
531
532         ret = imap_roomname(roomname, sizeof roomname, parms[2]);
533         if (ret < 0) {
534                 cprintf("%s NO Invalid mailbox name or location\r\n",
535                         parms[0]);
536                 return;
537         }
538
539         /* First try a regular match */
540         c = getroom(&QRscratch, roomname);
541
542         /* Then try a mailbox name match */
543         if (c != 0) {
544                 MailboxName(augmented_roomname, &CC->usersupp, roomname);
545                 c = getroom(&QRscratch, augmented_roomname);
546                 if (c == 0)
547                         strcpy(roomname, augmented_roomname);
548         }
549
550         /* If the room exists, check security/access */
551         if (c == 0) {
552                 /* See if there is an existing user/room relationship */
553                 ra = CtdlRoomAccess(&QRscratch, &CC->usersupp);
554
555                 /* normal clients have to pass through security */
556                 if (ra & UA_KNOWN) {
557                         ok = 1;
558                 }
559         }
560
561         /* Fail here if no such room */
562         if (!ok) {
563                 cprintf("%s NO ... no such room, or access denied\r\n",
564                         parms[0]);
565                 return;
566         }
567
568         /*
569          * usergoto() formally takes us to the desired room, happily returning
570          * the number of messages and number of new messages.  (If another
571          * folder is selected, save its name so we can return there!!!!!)
572          */
573         if (IMAP->selected) {
574                 strcpy(savedroom, CC->quickroom.QRname);
575         }
576         usergoto(QRscratch.QRname, 0, &msgs, &new);
577
578         /*
579          * Tell the client what it wants to know.  In fact, tell it *more* than
580          * it wants to know.  We happily IGnore the supplied status data item
581          * names and simply spew all possible data items.  It's far easier to
582          * code and probably saves us some processing time too.
583          *
584          * FIXME we need to implement RECENT and UNSEEN eventually...
585          */
586
587         imap_mailboxname(buf, sizeof buf, &QRscratch);
588         cprintf("* STATUS ");
589         imap_strout(buf);
590         cprintf(" (MESSAGES %d RECENT 0 UIDNEXT %ld "
591                 "UIDVALIDITY 0 UNSEEN 0)\r\n",
592                 msgs,
593                 CitControl.MMhighest + 1
594         );
595
596         /*
597          * If another folder is selected, go back to that room so we can resume
598          * our happy day without violent explosions.
599          */
600         if (IMAP->selected) {
601                 usergoto(savedroom, 0, &msgs, &new);
602         }
603
604         /*
605          * Oooh, look, we're done!
606          */
607         cprintf("%s OK STATUS completed\r\n", parms[0]);
608 }
609
610
611
612
613 /* 
614  * Main command loop for IMAP sessions.
615  */
616 void imap_command_loop(void) {
617         char *icmdbuf;
618         char *parms[SIZ];
619         int num_parms;
620
621         time(&CC->lastcmd);
622         if (client_gets(&icmdbuf) < 1) {
623                 lprintf(3, "IMAP socket is broken.  Ending session.\r\n");
624                 CC->kill_me = 1;
625                 return;
626         }
627
628         lprintf(5, "citserver[%3d]: %s\r\n", CC->cs_pid, icmdbuf); 
629         while (strlen(icmdbuf) < 5) strcat(icmdbuf, " ");
630
631
632         /* strip off l/t whitespace and CRLF */
633         if (icmdbuf[strlen(icmdbuf)-1]=='\n') icmdbuf[strlen(icmdbuf)-1]=0;
634         if (icmdbuf[strlen(icmdbuf)-1]=='\r') icmdbuf[strlen(icmdbuf)-1]=0;
635         striplt(icmdbuf);
636
637         /* If we're in the middle of a multi-line command, handle that */
638         if (IMAP->authstate == imap_as_expecting_username) {
639             if (strlen(icmdbuf) >= SIZ) /* I'm going to impose some kinda limit here */
640               *(icmdbuf+SIZ) = '\0';   /* because ialu uses SIZ */
641                 imap_auth_login_user(icmdbuf);
642                 return;
643         }
644         if (IMAP->authstate == imap_as_expecting_password) {
645             if (strlen(icmdbuf) >= SIZ) 
646               *(icmdbuf+SIZ) = '\0';
647                 imap_auth_login_pass(icmdbuf);
648                 return;
649         }
650
651
652         /* Ok, at this point we're in normal command mode */
653
654         /*
655          * Before processing the command that was just entered... if we happen
656          * to have a folder selected, we'd like to rescan that folder for new
657          * messages, and for deletions/changes of existing messages.  This
658          * could probably be optimized somehow, but IMAP sucks...
659          */
660         if (IMAP->selected) {
661                 imap_rescan_msgids();
662         }
663
664         /* Now for the command set. */
665
666         /* Grab the tag, command, and parameters.  Check syntax. */
667         num_parms = imap_parameterize(parms, icmdbuf);
668         if (num_parms < 2) {
669                 cprintf("BAD syntax error\r\n");
670         }
671
672         /* The commands below may be executed in any state */
673
674         else if ( (!strcasecmp(parms[1], "NOOP"))
675            || (!strcasecmp(parms[1], "CHECK")) ) {
676                 cprintf("%s OK This command successfully did nothing.\r\n",
677                         parms[0]);
678         }
679
680         else if (!strcasecmp(parms[1], "LOGOUT")) {
681                 cprintf("* BYE %s logging out\r\n", config.c_fqdn);
682                 cprintf("%s OK thank you for using Citadel IMAP\r\n", parms[0]);
683                 CC->kill_me = 1;
684                 return;
685         }
686
687         else if (!strcasecmp(parms[1], "LOGIN")) {
688                 imap_login(num_parms, parms);
689         }
690
691         else if (!strcasecmp(parms[1], "AUTHENTICATE")) {
692                 imap_authenticate(num_parms, parms);
693         }
694
695         else if (!strcasecmp(parms[1], "CAPABILITY")) {
696                 imap_capability(num_parms, parms);
697         }
698
699         else if (!CC->logged_in) {
700                 cprintf("%s BAD Not logged in.\r\n", parms[0]);
701         }
702
703         /* The commans below require a logged-in state */
704
705         else if (!strcasecmp(parms[1], "SELECT")) {
706                 imap_select(num_parms, parms);
707         }
708
709         else if (!strcasecmp(parms[1], "EXAMINE")) {
710                 imap_select(num_parms, parms);
711         }
712
713         else if (!strcasecmp(parms[1], "LSUB")) {
714                 imap_lsub(num_parms, parms);
715         }
716
717         else if (!strcasecmp(parms[1], "LIST")) {
718                 imap_list(num_parms, parms);
719         }
720
721         else if (!strcasecmp(parms[1], "CREATE")) {
722                 imap_create(num_parms, parms);
723         }
724
725         else if (!strcasecmp(parms[1], "STATUS")) {
726                 imap_status(num_parms, parms);
727         }
728
729         else if (IMAP->selected == 0) {
730                 cprintf("%s BAD no folder selected\r\n", parms[0]);
731         }
732
733         /* The commands below require the SELECT state on a mailbox */
734
735         else if (!strcasecmp(parms[1], "FETCH")) {
736                 imap_fetch(num_parms, parms);
737         }
738
739         else if ( (!strcasecmp(parms[1], "UID"))
740                 && (!strcasecmp(parms[2], "FETCH")) ) {
741                 imap_uidfetch(num_parms, parms);
742         }
743
744         else if (!strcasecmp(parms[1], "SEARCH")) {
745                 imap_search(num_parms, parms);
746         }
747
748         else if ( (!strcasecmp(parms[1], "UID"))
749                 && (!strcasecmp(parms[2], "SEARCH")) ) {
750                 imap_uidsearch(num_parms, parms);
751         }
752
753         else if (!strcasecmp(parms[1], "STORE")) {
754                 imap_store(num_parms, parms);
755         }
756
757         else if ( (!strcasecmp(parms[1], "UID"))
758                 && (!strcasecmp(parms[2], "STORE")) ) {
759                 imap_uidstore(num_parms, parms);
760         }
761
762         else if (!strcasecmp(parms[1], "CLOSE")) {
763                 imap_close(num_parms, parms);
764         }
765
766         /* End of commands.  If we get here, the command is either invalid
767          * or unimplemented.
768          */
769
770         else {
771                 cprintf("%s BAD command unrecognized\r\n", parms[0]);
772         }
773
774 }
775
776
777
778 /*
779  * This function is called by dynloader.c to register the IMAP module
780  * with the Citadel server.
781  */
782 char *Dynamic_Module_Init(void)
783 {
784         SYM_IMAP = CtdlGetDynamicSymbol();
785         CtdlRegisterServiceHook(config.c_imap_port,
786                                 NULL,
787                                 imap_greeting,
788                                 imap_command_loop);
789         CtdlRegisterSessionHook(imap_cleanup_function, EVT_STOP);
790         return "$Id$";
791 }