From 0eb5b2378e511875de90ec2ebc33d9f493865c9d Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 9 Oct 2008 14:08:27 +0000 Subject: [PATCH] Applied dtx's patch which adds the option to flag spam with an extra header instead of rejecting it. --- citadel/control.c | 4 ++ citadel/include/dtds/config-defs.h | 1 + citadel/modules/spam/serv_spam.c | 49 ++++++++++++++++++--- citadel/tuiconfig.c | 6 ++- webcit/siteconfig.c | 11 ++++- webcit/static/t/tab_siteconfig_network.html | 3 ++ 6 files changed, 65 insertions(+), 9 deletions(-) diff --git a/citadel/control.c b/citadel/control.c index 989e36c9f..305ed3d23 100644 --- a/citadel/control.c +++ b/citadel/control.c @@ -383,6 +383,7 @@ void cmd_conf(char *argbuf) cprintf("%d\n", config.c_xmpp_s2s_port); cprintf("%ld\n", config.c_pop3_fetch); cprintf("%ld\n", config.c_pop3_fastest); + cprintf("%d\n", config.c_spam_flag_only); cprintf("000\n"); } @@ -636,6 +637,9 @@ void cmd_conf(char *argbuf) case 65: config.c_pop3_fastest = atol(buf); break; + case 66: + config.c_spam_flag_only = atoi(buf); + break; } ++a; } diff --git a/citadel/include/dtds/config-defs.h b/citadel/include/dtds/config-defs.h index a71510faa..d14b3b4f4 100644 --- a/citadel/include/dtds/config-defs.h +++ b/citadel/include/dtds/config-defs.h @@ -88,3 +88,4 @@ CFG_VALUE(INTEGER(c_xmpp_c2s_port), " XMPP client-to-server port (usually 5222) CFG_VALUE(INTEGER(c_xmpp_s2s_port), " XMPP server-to-server port (usually 5269)"); CFG_VALUE(TIME(c_pop3_fetch), " How often to fetch POP3 messages"); CFG_VALUE(TIME(c_pop3_fastest), " Users can specify POP3 fetching this often"); +CFG_VALUE(INTEGER(c_spam_flag_only), " 1 = flag instead of reject spam"); diff --git a/citadel/modules/spam/serv_spam.c b/citadel/modules/spam/serv_spam.c index 249f52e3e..b8ccfb8d6 100644 --- a/citadel/modules/spam/serv_spam.c +++ b/citadel/modules/spam/serv_spam.c @@ -129,15 +129,50 @@ int spam_assassin(struct CtdlMessage *msg) { goto bail; } CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf); - if (!strncasecmp(buf, "Spam: True", 10)) { - is_spam = 1; - } + 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("message rejected by spam filter"); } bail: close(sock); diff --git a/citadel/tuiconfig.c b/citadel/tuiconfig.c index 15461953e..5197abeae 100644 --- a/citadel/tuiconfig.c +++ b/citadel/tuiconfig.c @@ -63,7 +63,7 @@ extern int screenwidth; void do_system_configuration(CtdlIPC *ipc) { -#define NUM_CONFIGS 65 +#define NUM_CONFIGS 67 char buf[256]; char sc[NUM_CONFIGS][256]; @@ -186,6 +186,10 @@ void do_system_configuration(CtdlIPC *ipc) a = (a ? 0 : 1); snprintf(sc[25], sizeof sc[25], "%d", a); + snprintf(sc[66], sizeof sc[66], "%d", (boolprompt( + "Flag messages as spam instead of rejecting", + atoi(&sc[66][0])))); + /* This logic flips the question around, because it's one of those * situations where 0=yes and 1=no */ diff --git a/webcit/siteconfig.c b/webcit/siteconfig.c index 3022304ad..27271e334 100644 --- a/webcit/siteconfig.c +++ b/webcit/siteconfig.c @@ -679,6 +679,14 @@ void display_siteconfig(void) sprintf(&pop3[strlen(pop3)], "\n", buf); sprintf(&pop3[strlen(pop3)], "\n"); break; + case 66: /* Flag spam */ + sprintf(&network[strlen(network)], ""); + sprintf(&network[strlen(network)], _("Flag message as spam, instead of rejecting it")); + sprintf(&network[strlen(network)], ""); + sprintf(&network[strlen(network)], "", + (atoi(buf) ? "CHECKED" : "")); + sprintf(&network[strlen(network)], "\n"); + break; } @@ -857,7 +865,8 @@ CfgMapping ServerConfig[] = { {CFG_STR, HKEY("c_xmpp_c2s_port")}, {CFG_STR, HKEY("c_xmpp_s2s_port")}, {CFG_STR, HKEY("c_pop3_fetch")}, - {CFG_STR, HKEY("c_pop3_fastest")} + {CFG_STR, HKEY("c_pop3_fastest")}, + {CFG_YES , HKEY("c_spam_flag_only")} }; diff --git a/webcit/static/t/tab_siteconfig_network.html b/webcit/static/t/tab_siteconfig_network.html index 4380663b2..061a1d672 100644 --- a/webcit/static/t/tab_siteconfig_network.html +++ b/webcit/static/t/tab_siteconfig_network.html @@ -10,6 +10,9 @@ > + +> + -- 2.30.2