]> code.citadel.org Git - citadel.git/blob - citadel/serv_spam.c
* add serv_spam
[citadel.git] / citadel / serv_spam.c
1 /*
2  * $Id$
3  *
4  * Reject incoming SMTP messages containing strings that tell us that the
5  * message is probably spam.
6  *
7  */
8
9
10 #include "sysdep.h"
11 #include <stdlib.h>
12 #include <unistd.h>
13 #include <stdio.h>
14 #include <fcntl.h>
15 #include <signal.h>
16 #include <pwd.h>
17 #include <errno.h>
18 #include <sys/types.h>
19
20 #if TIME_WITH_SYS_TIME
21 # include <sys/time.h>
22 # include <time.h>
23 #else
24 # if HAVE_SYS_TIME_H
25 #  include <sys/time.h>
26 # else
27 #  include <time.h>
28 # endif
29 #endif
30
31 #include <sys/wait.h>
32 #include <string.h>
33 #include <limits.h>
34 #include "citadel.h"
35 #include "server.h"
36 #include "sysdep_decls.h"
37 #include "citserver.h"
38 #include "support.h"
39 #include "config.h"
40 #include "control.h"
41 #include "dynloader.h"
42 #include "room_ops.h"
43 #include "user_ops.h"
44 #include "policy.h"
45 #include "database.h"
46 #include "msgbase.h"
47 #include "tools.h"
48 #include "internet_addressing.h"
49
50
51 /* Scan a message for spam */
52 int spam_filter(struct CtdlMessage *msg) {
53         int spam_strings_found = 0;
54         struct spamstrings_t *sptr;
55         char *ptr;
56
57         /* Bail out if there's no message text */
58         if (msg->cm_fields['M'] == NULL) return(0);
59
60
61         /* Scan! */
62         ptr = msg->cm_fields['M'];
63         while (ptr++[0] != 0) {
64                 for (sptr = spamstrings; sptr != NULL; sptr = sptr->next) {
65                         if (!strncasecmp(ptr, sptr->string,
66                            strlen(sptr->string))) {
67                                 ++spam_strings_found;
68                         }
69                 }
70         }
71
72         if (spam_strings_found) {
73                 if (msg->cm_fields['0'] != NULL) {
74                         phree(msg->cm_fields['0']);
75                 }
76                 msg->cm_fields['0'] = strdoop("Unsolicited spam rejected");
77                 return(spam_strings_found);
78         }
79
80         return(0);
81 }
82
83
84
85 char *Dynamic_Module_Init(void)
86 {
87         CtdlRegisterMessageHook(spam_filter, EVT_SMTPSCAN);
88         return "$Id$";
89 }