X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fspam%2Fserv_spam.c;h=479ea5fecf93be76c2edd76668bcabba212b2877;hb=7a9b0685e406cc83597171cc39d008c7e5459ca8;hp=7c24672ef4b2b1d5bd5d8f2541e649b6bc18b0ec;hpb=d3a29d82d6492191ae8208617e8ac1f088bcf14a;p=citadel.git diff --git a/citadel/modules/spam/serv_spam.c b/citadel/modules/spam/serv_spam.c index 7c24672ef..479ea5fec 100644 --- a/citadel/modules/spam/serv_spam.c +++ b/citadel/modules/spam/serv_spam.c @@ -4,21 +4,15 @@ * http://www.spamassassin.org (the SpamAssassin project is not in any way * affiliated with the Citadel project). * - * Copyright (c) 1998-2012 by the citadel.org team + * Copyright (c) 1998-2015 by the citadel.org team * * This program is open source software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3. - * - * * * 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. - * - * - * - * */ #define SPAMASSASSIN_PORT "783" @@ -32,18 +26,7 @@ #include #include #include - -#if TIME_WITH_SYS_TIME -# include -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif - +#include #include #include #include @@ -70,7 +53,7 @@ /* * Connect to the SpamAssassin server and scan a message. */ -int spam_assassin(struct CtdlMessage *msg) { +int spam_assassin(struct CtdlMessage *msg, recptypes *recp) { int sock = (-1); char sahosts[SIZ]; int num_sahosts; @@ -141,37 +124,33 @@ int spam_assassin(struct CtdlMessage *msg) { goto bail; } syslog(LOG_DEBUG, "<%s\n", buf); - syslog(LOG_DEBUG, "c_spam_flag_only setting %d\n", config.c_spam_flag_only); - if (config.c_spam_flag_only) { - syslog(LOG_DEBUG, "flag spam code used"); + syslog(LOG_DEBUG, "c_spam_flag_only setting %d\n", CtdlGetConfigInt("c_spam_flag_only")); + if (CtdlGetConfigInt("c_spam_flag_only")) { int headerlen; - int newmsgsize; - int oldmsgsize; - + char *cur; char sastatus[10]; char sascore[10]; char saoutof[10]; int numscore; + syslog(LOG_DEBUG, "flag spam code used"); + 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; + memcpy(buf, HKEY("X-Spam-Level: ")); + 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); + headerlen = cur - buf; + headerlen += snprintf(cur, (sizeof(buf) - headerlen), + "\r\nX-Spam-Status: %s, score=%s required=%s\r\n", + sastatus, sascore, saoutof); - memmove(msg->cm_fields['M']+headerlen,msg->cm_fields['M'],oldmsgsize); - memcpy(msg->cm_fields['M'],buf,headerlen); + CM_PrependToField(msg, eMesageText, buf, headerlen); } else { syslog(LOG_DEBUG, "reject spam code used"); @@ -180,10 +159,7 @@ int spam_assassin(struct CtdlMessage *msg) { } if (is_spam) { - if (msg->cm_fields['0'] != NULL) { - free(msg->cm_fields['0']); - } - msg->cm_fields['0'] = strdup("message rejected by spam filter"); + CM_SetField(msg, eErrorMsg, HKEY("message rejected by spam filter")); } }