87aef1acba845cd246834517110e0698cd65a1eb
[citadel.git] / citadel / serv_smtp.c
1 /* $Id$ */
2 #include "sysdep.h"
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <stdio.h>
6 #include <fcntl.h>
7 #include <signal.h>
8 #include <pwd.h>
9 #include <errno.h>
10 #include <sys/types.h>
11 #include <sys/time.h>
12 #include <sys/wait.h>
13 #include <string.h>
14 #include <limits.h>
15 #include "citadel.h"
16 #include "server.h"
17 #include <time.h>
18 #include "sysdep_decls.h"
19 #include "citserver.h"
20 #include "support.h"
21 #include "config.h"
22 #include "dynloader.h"
23 #include "room_ops.h"
24 #include "policy.h"
25 #include "database.h"
26 #include "msgbase.h"
27
28
29 /*
30  * Here's where our SMTP session begins its happy day.
31  */
32 void smtp_greeting(void) {
33
34         strcpy(CC->cs_clientname, "Citadel SMTP");
35
36         cprintf("220 %s Citadel/UX SMTP server ready\n",
37                 config.c_fqdn);
38 }
39
40
41 /* 
42  * Main command loop for SMTP sessions.
43  */
44 void smtp_command_loop(void) {
45         char cmdbuf[256];
46
47         time(&CC->lastcmd);
48         memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
49         if (client_gets(cmdbuf) < 1) {
50                 lprintf(3, "SMTP socket is broken.  Ending session.\n");
51                 CC->kill_me = 1;
52                 return;
53         }
54         lprintf(5, "citserver[%3d]: %s\n", CC->cs_pid, cmdbuf);
55
56         if (!strncasecmp(cmdbuf,"QUIT",4)) {
57                 cprintf("221 Later, dude!  Microsoft sucks!!\n");
58                 CC->kill_me = 1;
59                 return;
60                 }
61
62         else {
63                 cprintf("500 I'm afraid I can't do that, Dave.\n");
64         }
65
66 }
67
68
69
70 char *Dynamic_Module_Init(void)
71 {
72         CtdlRegisterServiceHook(2525,
73                                 smtp_greeting,
74                                 smtp_command_loop);
75         return "$Id$";
76 }