[cvs] bogofilter/src format.c,1.36,1.37 token.c,1.80,1.81 token.h,1.14,1.15
Fast Bayesian spam filter along lines suggested by Paul Graham
Brought to you by:
m-a
From: <re...@us...> - 2004-06-14 23:45:54
|
Update of /cvsroot/bogofilter/bogofilter/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28044/src Modified Files: format.c token.c token.h Log Message: Add formatting specification '%I' for outputting the source IP address. Index: format.c =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/src/format.c,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- format.c 22 Feb 2004 16:57:01 -0000 1.36 +++ format.c 14 Jun 2004 23:45:44 -0000 1.37 @@ -26,6 +26,7 @@ #include "bogofilter.h" #include "format.h" #include "score.h" +#include "token.h" #include "xstrdup.h" /* Function Prototypes */ @@ -355,6 +356,9 @@ case 'h': /* h - spam_header_name, e.g. "X-Bogosity" */ buff += format_string(buff, spam_header_name, 0, prec, flags, end); break; + case 'I': /* I - received IP address */ + buff += format_string(buff, ipaddr->text, 0, prec, flags, end); + break; case 'l': /* l - logging tag */ buff += format_string(buff, logtag, 0, prec, flags, end); break; Index: token.c =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/src/token.c,v retrieving revision 1.80 retrieving revision 1.81 diff -u -d -r1.80 -r1.81 --- token.c 18 May 2004 00:22:52 -0000 1.80 +++ token.c 14 Jun 2004 23:45:44 -0000 1.81 @@ -30,12 +30,16 @@ #include "token.h" #include "xmemrchr.h" +typedef enum { R_INIT, R_SAVE, R_DONE } R_STATE; + /* Local Variables */ word_t *yylval = NULL; +word_t *ipaddr = NULL; /* First IP Address in Received: statement */ static token_t save_class = NONE; static word_t *ipsave = NULL; +static R_STATE r_state; static word_t *w_to = NULL; /* To: */ static word_t *w_from = NULL; /* From: */ @@ -174,6 +178,13 @@ break; case IPADDR: + if ((token_prefix == w_recv) && + (r_state == R_INIT || r_state == R_SAVE) && + (strcmp(yylval->text, "127.0.0.1") != 0)) { + r_state = R_SAVE; + word_free(ipaddr); + ipaddr = word_dup(yylval); + } if (block_on_subnets) { const byte *prefix = (wordlist_version >= IP_PREFIX) ? (const byte *)"ip:" : (const byte *)"url:"; @@ -265,6 +276,8 @@ { yyinit(); + r_state = R_INIT; + if (!msg_count_file) mime_reset(); @@ -319,8 +332,11 @@ case 'r': if (tolower(text[2]) == 't') token_prefix = w_rtrn; /* Return-Path: */ - else + else { token_prefix = w_recv; /* Received: */ + if (r_state == R_SAVE) + r_state = R_DONE; + } break; case 's': token_prefix = w_subj; /* Subject: */ @@ -348,4 +364,5 @@ WFREE(w_recv); WFREE(w_head); WFREE(w_mime); + WFREE(ipaddr); } Index: token.h =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/src/token.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- token.h 14 Oct 2003 20:19:38 -0000 1.14 +++ token.h 14 Jun 2004 23:45:45 -0000 1.15 @@ -13,6 +13,7 @@ #include "lexer.h" extern word_t *yylval; +extern word_t *ipaddr; /* First IP Address in Received: statement */ extern token_t get_token(void); |