Patch for review.

bwmlist at satx.rr.com bwmlist at satx.rr.com
Tue Nov 18 17:57:50 CET 2003


I couldn't find this functionality anywhere in the documentation, and needed it for an implementation.  That functionality being: redirect spam message to a specified mailbox.  I didn't want to use a script and pipe output through any other 3rd party tools, due to speed.  Here's the patch,  i'm not a great coder, so if there are better ways of implementing please tell me.

and if this is duplicated effort... sorry i haven't been able to search the archives and i just joined the list.

[Patch]

diff -r -u3 bogofilter-0.15.8/bogofilter.cf.example bogofilter-0.15.8.bwm/bogofilter.cf.example
--- bogofilter-0.15.8/bogofilter.cf.example	Thu Oct 02 06:29:51 2003
+++ bogofilter-0.15.8.bwm/bogofilter.cf.example	Mon Nov 17 19:46:02 2003
@@ -53,6 +53,13 @@
 
 ##spam_subject_tag=***SPAM***
 
+#### SPAM_TO_TAG
+#
+#	tag to replace "To:" line to forward spam to
+#	default is nothing.
+
+##spam_to_tag=***TO ADDRESS***
+
 
 ##### STATS_IN_HEADER
 #
diff -r -u3 bogofilter-0.15.8/src/format.c bogofilter-0.15.8.bwm/src/format.c
--- bogofilter-0.15.8/src/format.c	Sat Sep 06 18:52:23 2003
+++ bogofilter-0.15.8.bwm/src/format.c	Mon Nov 17 19:20:18 2003
@@ -46,6 +46,7 @@
 
 const char *spam_header_name = SPAM_HEADER_NAME;	/* used by lexer */
 const char *spam_subject_tag = NULL;			/* used in passthrough mode */
+const char *spam_to_tag = NULL;				/* used in passthrough mode */
 
 /*
 **	formatting characters:
@@ -96,6 +97,7 @@
 {
     { "spam_header_name",  CP_STRING,	{ &spam_header_name } },
     { "spam_subject_tag",  CP_STRING,	{ &spam_subject_tag } },
+    { "spam_to_tag",	   CP_STRING,	{ &spam_to_tag } },
     { "header_format",	   CP_STRING,	{ &header_format } },
     { "terse_format",	   CP_STRING,	{ &terse_format } },
     { "log_header_format", CP_STRING,	{ &log_header_format } },
diff -r -u3 bogofilter-0.15.8/src/format.h bogofilter-0.15.8.bwm/src/format.h
--- bogofilter-0.15.8/src/format.h	Fri Aug 29 07:43:31 2003
+++ bogofilter-0.15.8.bwm/src/format.h	Mon Nov 17 19:17:46 2003
@@ -11,6 +11,7 @@
 
 extern const char *spam_header_name;
 extern const char *spam_subject_tag;
+extern const char *spam_to_tag;
 
 /* needed by bogoconfig.c */

--- bogofilter-0.15.8/src/passthrough.c	Tue Oct 28 17:48:11 2003
+++ bogofilter-0.15.8.bwm/src/passthrough.c	Mon Nov 17 22:07:19 2003
@@ -128,12 +128,18 @@
     char *out;
     textdata_t *text;
     int seen_subj = 0;
+	int seen_to = 0;
 
     if (passthrough) {
 	int hadlf = 1;
 	int bogolen = strlen(spam_header_name);
 	const char *subjstr = "Subject:";
 	int subjlen = strlen(subjstr);
+	const char *tostr = "To:";
+	int tolen = strlen(tostr);
+	const char *otostr = "Old_";
+	int otolen = strlen(otostr);
+	
 	/* initialize */
 	switch (passmode) {
 	    case PASS_MEM:
@@ -179,6 +185,18 @@
 		continue;
 	    }
 
+		/* append Old to To line and add new To: line header */
+		if (status == RC_SPAM &&
+			rd >= tolen &&
+			spam_to_tag != NULL &&
+			strncasecmp(out,tostr,tolen) == 0 ) {
+				int out_len_b = strlen(out);
+				(void) fprintf(fpo, "%.*s%.*s",otolen, otostr, out_len_b, out);
+				(void) fprintf(fpo, "To: %s\n", spam_to_tag);
+				seen_to =1;
+				continue;
+		}
+
 	    hadlf = (out[rd-1] == '\n');
 	    (void) fwrite(out, 1, rd, fpo);
 	    if (ferror(fpo)) cleanup_exit(2, 1);
@@ -187,6 +205,7 @@
 	if (!hadlf)
 	    fputc('\n', fpo);
     }
+
 
     if (passthrough || verbose || terse) {
 	typedef char *formatter(char *buff, size_t size);
 







More information about the bogofilter-dev mailing list