X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fspam%2Fserv_spam.c;h=0744fe28333f7c5b0f3b6af7bfb32fe4a08bb540;hb=8c47559cb5ae97ec0fa35660ee16fd61a9451c72;hp=cdf81557af86511a10eafab7d5ae49dc25bb00b2;hpb=e024165eb98df86eb314c5ddea3cb38fcf478e67;p=citadel.git diff --git a/citadel/modules/spam/serv_spam.c b/citadel/modules/spam/serv_spam.c index cdf81557a..0744fe283 100644 --- a/citadel/modules/spam/serv_spam.c +++ b/citadel/modules/spam/serv_spam.c @@ -5,6 +5,22 @@ * arriving via SMTP. For more information on SpamAssassin, visit * http://www.spamassassin.org (the SpamAssassin project is not in any way * affiliated with the Citadel project). + * + * Copyright (c) 1998-2009 by the citadel.org team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #define SPAMASSASSIN_PORT "783" @@ -34,6 +50,7 @@ #include #include #include +#include #include "citadel.h" #include "server.h" #include "citserver.h" @@ -45,7 +62,6 @@ #include "policy.h" #include "database.h" #include "msgbase.h" -#include "tools.h" #include "internet_addressing.h" #include "domain.h" #include "clientsocket.h" @@ -80,9 +96,9 @@ int spam_assassin(struct CtdlMessage *msg) { /* Try them one by one until we get a working one */ for (sa=0; sa\n", buf); + CtdlLogPrintf(CTDL_INFO, "Connecting to SpamAssassin at <%s>\n", buf); sock = sock_connect(buf, SPAMASSASSIN_PORT, "tcp"); - if (sock >= 0) lprintf(CTDL_DEBUG, "Connected!\n"); + if (sock >= 0) CtdlLogPrintf(CTDL_DEBUG, "Connected!\n"); } if (sock < 0) { @@ -93,7 +109,7 @@ int spam_assassin(struct CtdlMessage *msg) { } /* Command */ - lprintf(CTDL_DEBUG, "Transmitting command\n"); + CtdlLogPrintf(CTDL_DEBUG, "Transmitting command\n"); sprintf(buf, "CHECK SPAMC/1.2\r\n\r\n"); sock_write(sock, buf, strlen(buf)); @@ -101,7 +117,7 @@ int spam_assassin(struct CtdlMessage *msg) { CC->redirect_buffer = malloc(SIZ); CC->redirect_len = 0; CC->redirect_alloc = SIZ; - CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ALL, 0, 1); + CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ALL, 0, 1, 0); msgtext = CC->redirect_buffer; msglen = CC->redirect_len; CC->redirect_buffer = NULL; @@ -117,27 +133,62 @@ int spam_assassin(struct CtdlMessage *msg) { sock_shutdown(sock, SHUT_WR); /* Response */ - lprintf(CTDL_DEBUG, "Awaiting response\n"); + CtdlLogPrintf(CTDL_DEBUG, "Awaiting response\n"); if (sock_getln(sock, buf, sizeof buf) < 0) { goto bail; } - lprintf(CTDL_DEBUG, "<%s\n", buf); + CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf); if (strncasecmp(buf, "SPAMD", 5)) { goto bail; } if (sock_getln(sock, buf, sizeof buf) < 0) { goto bail; } - lprintf(CTDL_DEBUG, "<%s\n", buf); - if (!strncasecmp(buf, "Spam: True", 10)) { - is_spam = 1; - } + CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf); + CtdlLogPrintf(CTDL_DEBUG, "c_spam_flag_only setting %d\n", config.c_spam_flag_only); + if (config.c_spam_flag_only) { + CtdlLogPrintf(CTDL_DEBUG, "flag spam code used"); + int headerlen; + int newmsgsize; + int oldmsgsize; + + char sastatus[10]; + char sascore[10]; + char saoutof[10]; + int numscore; + + extract_token(sastatus, buf, 1, ' ', sizeof sastatus); + extract_token(sascore, buf, 3, ' ', sizeof sascore); + extract_token(saoutof, buf, 5, ' ', sizeof saoutof); + + sprintf(buf,"X-Spam-Level: "); + char *cur = buf + 14; + for (numscore = atoi(sascore); numscore>0; numscore--) + *(cur++) = '*'; + *cur = '\0'; + + sprintf(cur,"\r\nX-Spam-Status: %s, score=%s required=%s\r\n", sastatus, sascore, saoutof); + headerlen = strlen(buf); + oldmsgsize = strlen(msg->cm_fields['M']) + 1; + newmsgsize = headerlen + oldmsgsize; + + msg->cm_fields['M'] = realloc(msg->cm_fields['M'], newmsgsize); + + memmove(msg->cm_fields['M']+headerlen,msg->cm_fields['M'],oldmsgsize); + memcpy(msg->cm_fields['M'],buf,headerlen); + + } else { + CtdlLogPrintf(CTDL_DEBUG, "reject spam code used"); + if (!strncasecmp(buf, "Spam: True", 10)) { + is_spam = 1; + } - if (is_spam) { - if (msg->cm_fields['0'] != NULL) { - free(msg->cm_fields['0']); + if (is_spam) { + if (msg->cm_fields['0'] != NULL) { + free(msg->cm_fields['0']); + } + msg->cm_fields['0'] = strdup("message rejected by spam filter"); } - msg->cm_fields['0'] = strdup("5.7.1 message rejected by spam filter"); } bail: close(sock); @@ -148,8 +199,11 @@ bail: close(sock); CTDL_MODULE_INIT(spam) { - CtdlRegisterMessageHook(spam_assassin, EVT_SMTPSCAN); - + if (!threading) + { + CtdlRegisterMessageHook(spam_assassin, EVT_SMTPSCAN); + } + /* return our Subversion id for the Log */ return "$Id$"; }