[PATCH] tilde expansion for 0.10.1.x

David Relson relson at osagesoftware.com
Tue Jan 28 17:38:16 CET 2003


pi,

Here's a patch so that tilde expansion will be done for files and
directories named in the config file.

Index: config.c
===================================================================
RCS file: /cvsroot/bogofilter/bogofilter/config.c,v
retrieving revision 1.97
diff -u -r1.97 config.c
--- config.c	24 Jan 2003 13:48:43 -0000	1.97
+++ config.c	28 Jan 2003 16:22:16 -0000
@@ -241,7 +241,7 @@
  	    {
  		char *dir = *arg->addr.s;
  		xfree(dir);
-		*arg->addr.s = dir = xstrdup((const char *)val);
+		*arg->addr.s = dir = tildeexpand((const char *)val);
  		if (DEBUG_CONFIG(0))
  		    fprintf(dbgout, "%s -> '%s'\n", arg->name, dir);
  		if (setup_wordlists(dir) != 0)
Index: wordlists.c
===================================================================
RCS file: /cvsroot/bogofilter/bogofilter/wordlists.c,v
retrieving revision 1.41
diff -u -r1.41 wordlists.c
--- wordlists.c	19 Jan 2003 20:39:49 -0000	1.41
+++ wordlists.c	28 Jan 2003 16:22:16 -0000
@@ -257,7 +257,7 @@
      *tmp++ = '\0';
      while (isspace((unsigned char)*tmp)) tmp += 1;

-    path=tmp;
+    path=tildeexpand(tmp);
      tmp += strcspn(tmp, ", \t");
      *tmp++ = '\0';
      while (isspace((unsigned char)*tmp)) tmp += 1;
@@ -293,6 +293,8 @@

      rc = init_wordlist(&list, name, path, weight, bad, override,
      ignore);
      ok = rc == 0;
+
+    free(path);

      return ok;
  }


Here's how I tested it....

For the tests below, I randomly picked message ../msg.d/msg.004.u-s.
As the first two tests, I evaluated it using good wordlists in
/var/lib/bogofilter and empty wordlists in ~/.bogofilter.  Here are
those results:

[relson at osage cvs]$ bogofilter -v -d /var/lib/bogofilter -C < 
../msg.d/msg.004.u-s
X-Bogosity: Yes, tests=bogofilter, spamicity=0.725670, 
version=0.10.1.2.cvs.20030128

[relson at osage cvs]$ bogofilter -v -d ~/.bogofilter -C < ../msg.d/msg.004.u-s
X-Bogosity: No, tests=bogofilter, spamicity=0.415000, 
version=0.10.1.2.cvs.20030128

Note that .0725670 is the score for /var/lib/bogofilter and that
0.41500 is the score for the empty wordlist in ~/.bogofilter


### Running without $BOGOFILTER_DIR ###

[relson at osage cvs]$ unset BOGOFILTER_DIR

[relson at osage cvs]$ echo $BOGOFILTER_DIR

[relson at osage cvs]$ bogofilter -v -C < ../msg.d/msg.004.u-s
X-Bogosity: No, tests=bogofilter, spamicity=0.415000, 
version=0.10.1.2.cvs.20030128

### Running with BOGOFILTER_DIR=/var/lib/bogofilter

[relson at osage cvs]$ export BOGOFILTER_DIR=/var/lib/bogofilter

[relson at osage cvs]$ bogofilter -v -C < ../msg.d/msg.004.u-s
X-Bogosity: Yes, tests=bogofilter, spamicity=0.725670, 
version=0.10.1.2.cvs.20030128


### Running with BOGOFILTER_DIR=~/.bogofilter

[relson at osage cvs]$ export BOGOFILTER_DIR=~/.bogofilter

[relson at osage cvs]$ bogofilter -v -C < ../msg.d/msg.004.u-s
X-Bogosity: No, tests=bogofilter, spamicity=0.415000, 
version=0.10.1.2.cvs.20030128

### Removing environment variable BOGOFILTER_DIR

[relson at osage cvs]$ unset BOGOFILTER_DIR
[relson at osage cvs]$ echo $BOGOFILTER_DIR

### Setting bogofilter_dir=/var/lib/bogofilter in config file
     (test.cf)

[relson at osage cvs]$ echo bogofilter_dir=/var/lib/bogofilter > test.cf

[relson at osage cvs]$ bogofilter -v -c test.cf < ../msg.d/msg.004.u-s
X-Bogosity: Yes, tests=bogofilter, spamicity=0.725670, 
version=0.10.1.2.cvs.20030128e

### Setting bogofilter_dir=~/.bogofilter in config file (test.cf)
### with shell expansion of ~ to /home/relson

[relson at osage cvs]$ echo bogofilter_dir=~/.bogofilter > test.cf

[relson at osage cvs]$ cat test.cf
bogofilter_dir=/home/relson/.bogofilter

[relson at osage cvs]$ bogofilter -v -c test.cf < ../msg.d/msg.004.u-s
X-Bogosity: No, tests=bogofilter, spamicity=0.415000, 
version=0.10.1.2.cvs.20030128

### Setting bogofilter_dir=~/.bogofilter in config file (test.cf)
### without shell expansion of ~

[relson at osage cvs]$ echo "bogofilter_dir=~/.bogofilter" > test.cf

[relson at osage cvs]$ cat test.cf
bogofilter_dir=~/.bogofilter

[relson at osage cvs]$ bogofilter -v -c test.cf < ../msg.d/msg.004.u-s
X-Bogosity: No, tests=bogofilter, spamicity=0.415000, 
version=0.10.1.2.cvs.20030128

For your convenience the usual rpms and tarballs are available at 
ftp://ftp.osagesoftware.com/pub/outgoing/bogofilter

David
--------------------------------------------------------
David Relson                   Osage Software Systems, Inc.
relson at osagesoftware.com       Ann Arbor, MI 48103
www.osagesoftware.com          tel:  734.821.8800





More information about the Bogofilter mailing list