diff -udNr vm-7.14/Makefile vm-7.14-filter/Makefile --- vm-7.14/Makefile 2003-03-20 10:50:02.000000000 -0800 +++ vm-7.14-filter/Makefile 2003-04-14 15:07:25.000000000 -0700 @@ -57,7 +57,8 @@ vm-save.elc \ vm-search.elc vm-sort.elc vm-summary.elc vm-startup.elc vm-thread.elc \ vm-toolbar.elc vm-undo.elc \ - vm-user.elc vm-vars.elc vm-virtual.elc vm-window.elc + vm-user.elc vm-vars.elc vm-virtual.elc vm-window.elc \ + vm-filter.elc SOURCES = \ vm-version.el \ @@ -68,7 +69,8 @@ vm-mouse.el vm-page.el vm-pop.el vm-reply.el vm-save.el \ vm-search.el vm-sort.el vm-startup.el vm-summary.el vm-thread.el \ vm-toolbar.el vm-undo.el \ - vm-user.el vm-vars.el vm-virtual.el vm-window.el + vm-user.el vm-vars.el vm-virtual.el vm-window.el \ + vm-filter.el UTILS = qp-decode qp-encode base64-decode base64-encode @@ -134,7 +136,7 @@ cp $(UTILS) $(BINDIR) clean: - rm -f $(UTILS) vm.info vm.info-* vm-autoload.el vm-autoload.elc $(OBJECTS) tapestry.elc + rm -f $(UTILS) vm.info vm.info-* vm-autoload.el vm-autoload.elc $(OBJECTS) tapestry.elc vm.el vm.elc vm.info: vm.texinfo @echo "making vm.info..." @@ -166,6 +168,10 @@ @echo compiling vm-edit.el... @$(EMACS) $(BATCHFLAGS) $(PRELOADS) -f batch-byte-compile vm-edit.el +vm-filter.elc: vm-filter.el $(CORE) + @echo compiling vm-filter.el... + @$(EMACS) $(BATCHFLAGS) $(PRELOADS) -f batch-byte-compile vm-filter.el + vm-folder.elc: vm-folder.el $(CORE) @echo compiling vm-folder.el... @$(EMACS) $(BATCHFLAGS) $(PRELOADS) -f batch-byte-compile vm-folder.el diff -udNr vm-7.14/vm-filter.el vm-7.14-filter/vm-filter.el --- vm-7.14/vm-filter.el 1969-12-31 16:00:00.000000000 -0800 +++ vm-7.14-filter/vm-filter.el 2003-04-14 15:19:55.000000000 -0700 @@ -0,0 +1,383 @@ +;;; Email filtering for VM +;;; Copyright (C) 2002 Adam Milazzo +;;; Thanks to Paul Graham for the statistics algorithms +;;; +;;; This program is free software; you can redistribute it and/or modify +;;; it under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 1, or (at your option) +;;; any later version. +;;; +;;; This program is distributed in the hope that it will be useful, +;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program; if not, write to the Free Software +;;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +(provide 'vm-filter) + +(defvar vm-filter-changed nil) + +(defun vm-filter-remove-duplicates(lst) + "Remove duplicate items from a list." + (let ((slst (sort lst #'string<)) + (ret nil) + (olp nil)) + (while slst + (if (not (equal (car slst) (car olp))) + (setq ret (cons (car slst) ret))) + (setq olp slst slst (cdr slst))) + ret)) + +(defun vm-filter-default(buf) + "The default filter function. Returns non-nil if the message is spam. + First, it checks the From: header against the whitelist. If the source + email doesn't pass the whitelist, it then uses the pseudo-bayesian stuff + (`vm-filter-probability-of-spam-buffer') to calculate a probability and + then returns non-nil if the probability is >= `vm-filter-default-spam-threshold'" + (not (or + (and vm-filter-whitelist + (save-excursion + (set-buffer buf) + (beginning-of-buffer) + (or case-fold-search (setq case-fold-search t)) + (and + (or (re-search-forward "^From:.*?< *\\(.*?\\) *> *$" nil t) + (re-search-forward "^From: *\\(.*?\\) *$" nil t)) + (member + (downcase (buffer-substring-no-properties (match-beginning 1) (match-end 1))) + vm-filter-whitelist)))) + (< (vm-filter-probability-of-spam-buffer buf) vm-filter-default-spam-threshold)))) + +(defun vm-filter-split-words(buf) + "Split a buffer into a list of lowercase words. It ignores HTML + comments and words that are too big or too small." + (save-excursion + (set-buffer buf) + (beginning-of-buffer) + (while (re-search-forward "\