]> code.citadel.org Git - citadel.git/blob - citadel/serv_imap.c
* added imap files
[citadel.git] / citadel / serv_imap.c
1 /* $Id$ 
2  *
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.
6  *
7  * Current status of standards conformance:
8  *
9  *               ***  ABSOLUTELY NOTHING WORKS  ***
10  * 
11  */
12
13 #include "sysdep.h"
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include <stdio.h>
17 #include <fcntl.h>
18 #include <signal.h>
19 #include <pwd.h>
20 #include <errno.h>
21 #include <sys/types.h>
22 #include <sys/time.h>
23 #include <sys/wait.h>
24 #include <string.h>
25 #include <limits.h>
26 #include "citadel.h"
27 #include "server.h"
28 #include <time.h>
29 #include "sysdep_decls.h"
30 #include "citserver.h"
31 #include "support.h"
32 #include "config.h"
33 #include "dynloader.h"
34 #include "room_ops.h"
35 #include "user_ops.h"
36 #include "policy.h"
37 #include "database.h"
38 #include "msgbase.h"
39 #include "tools.h"
40 #include "internet_addressing.h"
41 #include "serv_imap.h"
42
43
44 long SYM_IMAP;
45
46
47 /*
48  * This cleanup function blows away the temporary memory and files used by
49  * the IMAP server.
50  */
51 void imap_cleanup_function(void) {
52
53         /* Don't do this stuff if this is not a IMAP session! */
54         if (CC->h_command_function != imap_command_loop) return;
55
56         lprintf(9, "Performing IMAP cleanup hook\n");
57
58
59         lprintf(9, "Finished IMAP cleanup hook\n");
60 }
61
62
63
64 /*
65  * Here's where our IMAP session begins its happy day.
66  */
67 void imap_greeting(void) {
68
69         strcpy(CC->cs_clientname, "IMAP session");
70         CC->internal_pgm = 1;
71         CtdlAllocUserData(SYM_IMAP, sizeof(struct citimap));
72
73         cprintf("don't go here!  this doesn't work!\r\n");
74 }
75
76
77
78
79 /* 
80  * Main command loop for IMAP sessions.
81  */
82 void imap_command_loop(void) {
83         char cmdbuf[256];
84
85         time(&CC->lastcmd);
86         memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
87         if (client_gets(cmdbuf) < 1) {
88                 lprintf(3, "IMAP socket is broken.  Ending session.\r\n");
89                 CC->kill_me = 1;
90                 return;
91         }
92         lprintf(5, "citserver[%3d]: %s\r\n", CC->cs_pid, cmdbuf);
93         while (strlen(cmdbuf) < 5) strcat(cmdbuf, " ");
94
95         if (!strncasecmp(cmdbuf, "NOOP", 4)) {  /* FIXME */
96                 cprintf("+OK This command successfully did nothing.\r\n");
97         }
98
99         else if (!strncasecmp(cmdbuf, "QUIT", 4)) {  /* FIXME */
100                 cprintf("+OK Goodbye...\r\n");
101                 CC->kill_me = 1;
102                 return;
103         }
104
105         /*   FIXME   ...   implement login commands HERE      */
106
107         else if (!CC->logged_in) {      /* FIXME */
108                 cprintf("-ERR Not logged in.\r\n");
109         }
110
111         /*    FIXME    ...   implement commands requiring login here   */
112
113
114         else {  /* FIXME */
115                 cprintf("500 I'm afraid I can't do that, Dave.\r\n");
116         }
117
118 }
119
120
121
122 char *Dynamic_Module_Init(void)
123 {
124         SYM_IMAP = CtdlGetDynamicSymbol();
125         CtdlRegisterServiceHook(143,            /* FIXME */
126                                 NULL,
127                                 imap_greeting,
128                                 imap_command_loop);
129         CtdlRegisterSessionHook(imap_cleanup_function, EVT_STOP);
130         return "$Id$";
131 }