Hi again,

Here is a patch that enables you to select whether you want to reject an
e-mail based on SpamAssassin, or to do add X-Spam-Status and X-Spam-Flag
headers and accept.  Please review and apply.

Edward Flick
Index: citadel/control.c
===================================================================
--- citadel/control.c	(revision 6669)
+++ citadel/control.c	(working copy)
@@ -383,6 +383,7 @@
 		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 @@
 			case 65:
 				config.c_pop3_fastest = atol(buf);
 				break;
+			case 66:
+				config.c_spam_flag_only = atoi(buf);
+				break;
 			}
 			++a;
 		}
Index: citadel/include/dtds/config-defs.h
===================================================================
--- citadel/include/dtds/config-defs.h	(revision 6669)
+++ citadel/include/dtds/config-defs.h	(working copy)
@@ -88,3 +88,4 @@
 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 = reject all potential spam");
Index: citadel/tuiconfig.c
===================================================================
--- citadel/tuiconfig.c	(revision 6669)
+++ citadel/tuiconfig.c	(working copy)
@@ -63,7 +63,7 @@
 void do_system_configuration(CtdlIPC *ipc)
 {
 
-#define NUM_CONFIGS 65
+#define NUM_CONFIGS 66
 
 	char buf[256];
 	char sc[NUM_CONFIGS][256];
@@ -189,6 +189,16 @@
 	/* This logic flips the question around, because it's one of those
 	 * situations where 0=yes and 1=no
 	 */
+	a = atoi(sc[66]);
+	a = (a ? 0 : 1);
+	a = boolprompt("Flag messages as spam instead of rejecting",
+		a);
+	a = (a ? 0 : 1);
+	snprintf(sc[25], sizeof sc[66], "%d", a);
+
+	/* This logic flips the question around, because it's one of those
+	 * situations where 0=yes and 1=no
+	 */
 	a = atoi(sc[61]);
 	a = (a ? 0 : 1);
 	a = boolprompt("Force IMAP posts in public rooms to be from the user who submitted them", a);
Index: citadel/modules/upgrade/serv_upgrade.c
===================================================================
--- citadel/modules/upgrade/serv_upgrade.c	(revision 6669)
+++ citadel/modules/upgrade/serv_upgrade.c	(working copy)
@@ -229,7 +229,12 @@
 		config.c_xmpp_c2s_port = 5222;
 		config.c_xmpp_s2s_port = 5269;
 	}
+	
+	if (CitControl.version < 739) {
+		config.c_spam_flag_only = 1;
+	}
 
+
 	put_config();
 }
 
Index: citadel/modules/spam/serv_spam.c
===================================================================
--- citadel/modules/spam/serv_spam.c	(revision 6669)
+++ citadel/modules/spam/serv_spam.c	(working copy)
@@ -129,15 +129,49 @@
                 goto bail;
         }
         CtdlLogPrintf(CTDL_DEBUG, "<%s\n", buf);
-	if (!strncasecmp(buf, "Spam: True", 10)) {
-		is_spam = 1;
-	}
+        if (config.c_spam_flag_only==1) {
+                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");
+	} else {
+                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);
+
 	}
 
 bail:	close(sock);
Index: webcit/siteconfig.c
===================================================================
--- webcit/siteconfig.c	(revision 6669)
+++ webcit/siteconfig.c	(working copy)
@@ -679,6 +679,14 @@
 			sprintf(&pop3[strlen(pop3)], "<input type=\"text\" name=\"c_pop3_fastest\" MAXLENGTH=\"5\" value=\"%s\">\n", buf);
 			sprintf(&pop3[strlen(pop3)], "</TD></TR>\n");
 			break;
+		case 66:	/* note: reverse bool */
+			sprintf(&network[strlen(network)], "<TR><TD>");
+			sprintf(&network[strlen(network)], _("Flag message as spam, instead of rejecting it"));
+			sprintf(&network[strlen(network)], "</TD><TD>");
+			sprintf(&network[strlen(network)], "<input type=\"checkbox\" NAME=\"c_spam_flag_only\" VALUE=\"yes\" %s>",
+				((atoi(buf) == 0) ? "CHECKED" : ""));
+			sprintf(&network[strlen(network)], "</TD></TR>\n");
+			break;
 			
 		}
 	
@@ -857,7 +865,8 @@
 	{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_NO , HKEY("c_spam_flag_only")}	/* note: reverse bool */
 };
 
 
Index: webcit/static/t/tab_siteconfig_network.html
===================================================================
--- webcit/static/t/tab_siteconfig_network.html	(revision 6669)
+++ webcit/static/t/tab_siteconfig_network.html	(working copy)
@@ -10,6 +10,9 @@
 <tr><td><?_("Correct forged From: lines during authenticated SMTP")></td><td>
 <input type="checkbox" NAME="c_rfc822_strict_from" VALUE="yes" <?%("COND:SERVCFG", 1, "c_rfc822_strict_from", 1, "", "CHECKED")>></td></tr>
 
+<tr><td><?_("Flag message as spam, instead of rejecting it")></td><td>
+<input type="checkbox" NAME="c_spam_flag_only" VALUE="yes" <?%("COND:SERVCFG", 1, "c_spam_flag_only", 1, "", "CHECKED")>></td></tr>
+
 <tr><td><?_("IMAP listener port (-1 to disable)")></td><td>
 <input type="text" NAME="c_imap_port" MAXLENGTH="5" VALUE='<?SERV:CFG("c_imap_port")>'></td></tr>
 

Reply via email to