4 * Reject incoming SMTP messages containing strings that tell us that the
5 * message is probably spam.
18 #include <sys/types.h>
20 #if TIME_WITH_SYS_TIME
21 # include <sys/time.h>
25 # include <sys/time.h>
34 #include <sys/socket.h>
37 #include "sysdep_decls.h"
38 #include "citserver.h"
42 #include "dynloader.h"
49 #include "internet_addressing.h"
50 #include "clientsocket.h"
54 #ifdef ___NOT_CURRENTLY_IN_USE___
55 /* Scan a message for spam */
56 int spam_filter(struct CtdlMessage *msg) {
57 int spam_strings_found = 0;
58 struct spamstrings_t *sptr;
61 /* Bail out if there's no message text */
62 if (msg->cm_fields['M'] == NULL) return(0);
66 ptr = msg->cm_fields['M'];
67 while (ptr++[0] != 0) {
68 for (sptr = spamstrings; sptr != NULL; sptr = sptr->next) {
69 if (!strncasecmp(ptr, sptr->string,
70 strlen(sptr->string))) {
76 if (spam_strings_found) {
77 if (msg->cm_fields['0'] != NULL) {
78 phree(msg->cm_fields['0']);
80 msg->cm_fields['0'] = strdoop("Unsolicited spam rejected");
81 return(spam_strings_found);
91 * Connect to the SpamAssassin server and scan a message.
93 int spam_assassin(struct CtdlMessage *msg) {
98 #define SPAMASSASSIN_HOST "127.0.0.1"
99 #define SPAMASSASSIN_PORT "783"
101 /* Connect to the SpamAssassin server */
102 lprintf(9, "Connecting to SpamAssassin\n");
103 sock = sock_connect(SPAMASSASSIN_HOST, SPAMASSASSIN_PORT, "tcp");
105 /* If the service isn't running, just pass the mail
106 * through. Potentially throwing away mails isn't good.
112 lprintf(9, "Transmitting command\n");
113 sprintf(buf, "CHECK SPAMC/1.2\r\n\r\n");
115 lprintf(9, "sock_write() returned %d\n",
116 sock_write(sock, buf, strlen(buf))
120 CtdlRedirectOutput(NULL, sock);
121 CtdlOutputPreLoadedMsg(msg, 0L, MT_RFC822, 0, 0, 1);
122 CtdlRedirectOutput(NULL, -1);
124 /* Close one end of the socket connection; this tells SpamAssassin
127 lprintf(9, "sock_shutdown() returned %d\n",
128 sock_shutdown(sock, SHUT_WR)
132 lprintf(9, "Awaiting response\n");
133 if (sock_gets(sock, buf) < 0) {
136 lprintf(9, "<%s\n", buf);
137 if (strncasecmp(buf, "SPAMD", 5)) {
140 if (sock_gets(sock, buf) < 0) {
143 lprintf(9, "<%s\n", buf);
144 if (!strncasecmp(buf, "Spam: True", 10)) {
149 if (msg->cm_fields['0'] != NULL) {
150 phree(msg->cm_fields['0']);
152 msg->cm_fields['0'] = strdoop(
153 "Message rejected by SpamAssassin");
162 char *Dynamic_Module_Init(void)
165 /* ** This one isn't in use. It's a spam filter I wrote, but we're going to
166 try the SpamAssassin stuff instead.
167 CtdlRegisterMessageHook(spam_filter, EVT_SMTPSCAN);
171 CtdlRegisterMessageHook(spam_assassin, EVT_SMTPSCAN);