(spam-verify-bogofilter): new function
authorTeodor Zlatanov <tzz@lifelogs.com>
Tue, 28 Sep 2004 14:50:26 +0000 (14:50 +0000)
committerTeodor Zlatanov <tzz@lifelogs.com>
Tue, 28 Sep 2004 14:50:26 +0000 (14:50 +0000)
(spam-check-bogofilter)
(spam-bogofilter-register-with-bogofilter): use it

lisp/ChangeLog
lisp/spam.el

index 9c97c2c..b59f807 100644 (file)
@@ -1,3 +1,9 @@
+2004-09-28  Teodor Zlatanov  <tzz@lifelogs.com>
+
+       * spam.el (spam-verify-bogofilter): new function
+       (spam-check-bogofilter)
+       (spam-bogofilter-register-with-bogofilter): use it
+
 2004-09-28  Simon Josefsson  <jas@extundo.com>
 
        * hashcash.el (hashcash-generate-payment): Revert.
index 9777d1a..a112877 100644 (file)
@@ -2353,46 +2353,56 @@ REMOVE not nil, remove the ADDRESSES."
       (message "Spamicity score %s" score)
       (or score "0"))))
 
+(defun spam-verify-bogofilter ()
+  "Verify the Bogofilter version is sufficient."
+  (when (string-match "^bogofilter version 0\\.\\([0-9]\\|1[01]\\)\\."
+                     (shell-command-to-string 
+                      (format "%s -sV" spam-bogofilter-path)))))
+
 (defun spam-check-bogofilter (&optional score)
-  "Check the Bogofilter backend for the classification of this message"
-  (let ((article-buffer-name (buffer-name))
-       (db spam-bogofilter-database-directory)
+  "Check the Bogofilter backend for the classification of this message."
+  (if (spam-verify-bogofilter)
+      (let ((article-buffer-name (buffer-name))
+           (db spam-bogofilter-database-directory)
+           return)
+       (with-temp-buffer
+         (let ((temp-buffer-name (buffer-name)))
+           (save-excursion
+             (set-buffer article-buffer-name)
+             (apply 'call-process-region
+                    (point-min) (point-max)
+                    spam-bogofilter-path
+                    nil temp-buffer-name nil
+                    (if db `("-d" ,db "-v") `("-v"))))
+           (setq return (spam-check-bogofilter-headers score))))
        return)
-    (with-temp-buffer
-      (let ((temp-buffer-name (buffer-name)))
-       (save-excursion
-         (set-buffer article-buffer-name)
-         (apply 'call-process-region
-                (point-min) (point-max)
-                spam-bogofilter-path
-                nil temp-buffer-name nil
-                (if db `("-d" ,db "-v") `("-v"))))
-       (setq return (spam-check-bogofilter-headers score))))
-    return))
+    (gnus-error "`spam.el' doesnt support obsolete bogofilter versions")))
 
 (defun spam-bogofilter-register-with-bogofilter (articles
                                                 spam
                                                 &optional unregister)
   "Register an article, given as a string, as spam or non-spam."
-  (dolist (article articles)
-    (let ((article-string (spam-get-article-as-string article))
-         (db spam-bogofilter-database-directory)
-         (switch (if unregister
-                     (if spam
-                         spam-bogofilter-spam-strong-switch
-                       spam-bogofilter-ham-strong-switch)
-                   (if spam
-                       spam-bogofilter-spam-switch
-                     spam-bogofilter-ham-switch))))
-      (when (stringp article-string)
-       (with-temp-buffer
-         (insert article-string)
-
-         (apply 'call-process-region
-                (point-min) (point-max)
-                spam-bogofilter-path
-                nil nil nil switch
-                (if db `("-d" ,db "-v") `("-v"))))))))
+  (if (spam-verify-bogofilter)
+      (dolist (article articles)
+       (let ((article-string (spam-get-article-as-string article))
+             (db spam-bogofilter-database-directory)
+             (switch (if unregister
+                         (if spam
+                             spam-bogofilter-spam-strong-switch
+                           spam-bogofilter-ham-strong-switch)
+                       (if spam
+                           spam-bogofilter-spam-switch
+                         spam-bogofilter-ham-switch))))
+         (when (stringp article-string)
+           (with-temp-buffer
+             (insert article-string)
+             
+             (apply 'call-process-region
+                    (point-min) (point-max)
+                    spam-bogofilter-path
+                    nil nil nil switch
+                    (if db `("-d" ,db "-v") `("-v")))))))
+    (gnus-error "`spam.el' doesnt support obsolete bogofilter versions")))
 
 (defun spam-bogofilter-register-spam-routine (articles &optional unregister)
   (spam-bogofilter-register-with-bogofilter articles t unregister))