[cvs] bogofilter/src main.c,1.12,1.13 format.c,1.4,1.5 format.h,1.3,1.4
Fast Bayesian spam filter along lines suggested by Paul Graham
Brought to you by:
m-a
From: <re...@us...> - 2003-03-03 12:54:07
|
Update of /cvsroot/bogofilter/bogofilter/src In directory sc8-pr-cvs1:/tmp/cvs-serv10519/src Modified Files: main.c format.c format.h Log Message: Add config file option 'set_subject_tag' for use in identifying received spam. Index: main.c =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/src/main.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- main.c 2 Mar 2003 00:38:22 -0000 1.12 +++ main.c 3 Mar 2003 12:54:03 -0000 1.13 @@ -200,15 +200,16 @@ static void write_message(FILE *fp) { - ssize_t rd = 0; /* assignment to quench warning */ - readfunc_t rf = 0; /* dito */ - void *rfarg = 0; /* dito */ + ssize_t rd = 0; /* assignment to quench warning */ + readfunc_t rf = 0; /* assignment to quench warning */ + void *rfarg = 0; /* assignment to quench warning */ char *out; textdata_t *text; if (passthrough) { int hadlf = 1; - int hdrlen; + int bogolen = strlen(spam_header_name); + int subjlen = strlen("Subject:"); /* initialize */ switch (passmode) { case PASS_MEM: @@ -225,19 +226,29 @@ abort(); } - hdrlen = strlen(spam_header_name); /* print headers */ while ((rd = rf(&out, rfarg)) > 0) { /* detect end of headers */ if ((rd == 1 && memcmp(out, NL, 1) == 0) || - (rd == 2 && memcmp(out, CRLF, 2) == 0)) { + (rd == 2 && memcmp(out, CRLF, 2) == 0)) { break; } /* skip over spam_header ("X-Bogosity:") lines */ - if (rd >= hdrlen && 0 == memcmp(out, spam_header_name, hdrlen)) + if (rd >= bogolen && memcmp(out, spam_header_name, bogolen) == 0) + continue; + + /* rewrite "Subject: " line */ + if (rd >= subjlen && + spam_subject_tag != NULL && + memcmp(out, "Subject:", subjlen) == 0) { + (void) fprintf(fp, "Subject: %s", spam_subject_tag); + if (out[subjlen] != ' ') + fputc(' ', fp); + (void) fwrite(out + subjlen, 1, rd - subjlen, fp); continue; + } hadlf = (out[rd-1] == '\n'); (void) fwrite(out, 1, rd, fp); Index: format.c =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/src/format.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- format.c 1 Mar 2003 02:26:39 -0000 1.4 +++ format.c 3 Mar 2003 12:54:03 -0000 1.5 @@ -44,6 +44,7 @@ /* initialized static variables */ const char *spam_header_name = SPAM_HEADER_NAME; /* used by lexer */ +const char *spam_subject_tag = NULL; /* used in passthrough mode */ /* ** formatting characters: @@ -88,6 +89,7 @@ const parm_desc format_parms[] = { { "spam_header_name", CP_STRING, { &spam_header_name } }, + { "spam_subject_tag", CP_STRING, { &spam_subject_tag } }, { "header_format", CP_STRING, { &header_format } }, { "terse_format", CP_STRING, { &terse_format } }, { "log_header_format", CP_STRING, { &log_header_format } }, Index: format.h =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/src/format.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- format.h 27 Feb 2003 21:17:32 -0000 1.3 +++ format.h 3 Mar 2003 12:54:03 -0000 1.4 @@ -8,6 +8,8 @@ /* Global variables */ extern const char *spam_header_name; +extern const char *spam_subject_tag; + /* ** extern const char *header_format; ** extern const char *terse_format; |