(gnus-read-group): Added check to ask confirmation if
[gnus] / lisp / spam-stat.el
index 7a01ec3..dcebb70 100644 (file)
@@ -1,6 +1,6 @@
 ;;; spam-stat.el --- detecting spam based on statistics
 
-;; Copyright (C) 2002  Free Software Foundation, Inc.
+;; Copyright (C) 2002, 2003 Free Software Foundation, Inc.
 
 ;; Author: Alex Schroeder <alex@gnu.org>
 ;; Keywords: network
   "Statistical spam detection for Emacs.
 Use the functions to build a dictionary of words and their statistical
 distribution in spam and non-spam mails.  Then use a function to determine
-wether a buffer contains spam or not."
+whether a buffer contains spam or not."
   :group 'gnus)
 
 (defcustom spam-stat-file "~/.spam-stat.el"
@@ -136,6 +136,12 @@ See `spam-stat-to-hash-table' for the format of the file."
   :type 'file
   :group 'spam-stat)
 
+(defcustom spam-stat-install-hooks t
+  "Whether spam-stat should install its hooks in Gnus.
+This is set to nil if you use spam-stat through spam.el."
+  :type 'boolean
+  :group 'spam-stat)
+
 (defcustom spam-stat-unknown-word-score 0.2
   "The score to use for unknown words.
 Also used for words that don't appear often enough."
@@ -155,10 +161,16 @@ This variable says how many characters this will be."
 
 (defcustom spam-stat-split-fancy-spam-group "mail.spam"
   "Name of the group where spam should be stored, if
-`spam-stat-split-fancy' is used in fancy splitting rules."
+`spam-stat-split-fancy' is used in fancy splitting rules.  Has no
+effect when spam-stat is invoked through spam.el."
   :type 'string
   :group 'spam-stat)
 
+(defcustom spam-stat-split-fancy-spam-threshhold 0.9
+  "Spam score threshhold in spam-stat-split-fancy."
+  :type 'number
+  :group 'spam-stat)
+
 (defvar spam-stat-syntax-table
   (let ((table (copy-syntax-table text-mode-syntax-table)))
     (modify-syntax-entry ?- "w" table)
@@ -226,11 +238,6 @@ This uses `gnus-article-buffer'."
     (set-buffer gnus-original-article-buffer)
     (spam-stat-store-current-buffer)))
 
-(add-hook 'nnmail-prepare-incoming-message-hook
-         'spam-stat-store-current-buffer)
-(add-hook 'gnus-select-article-hook
-         'spam-stat-store-gnus-article-buffer)
-
 ;; Data -- not using defstruct in order to save space and time
 
 (defvar spam-stat (make-hash-table :test 'equal)
@@ -385,7 +392,8 @@ Use `spam-stat-ngood', `spam-stat-nbad', `spam-stat-good',
   "Save the `spam-stat' hash table as lisp file."
   (interactive)
   (with-temp-buffer
-    (let ((standard-output (current-buffer)))
+    (let ((standard-output (current-buffer))
+         (font-lock-maximum-size 0))
       (insert "(setq spam-stat-ngood "
               (number-to-string spam-stat-ngood)
               " spam-stat-nbad "
@@ -396,8 +404,8 @@ Use `spam-stat-ngood', `spam-stat-nbad', `spam-stat-good',
                              (spam-stat-good entry)
                              (spam-stat-bad entry))))
               spam-stat)
-      (insert ")))"))
-    (write-file spam-stat-file)))
+      (insert ")))")
+    (write-file spam-stat-file))))
 
 (defun spam-stat-load ()
   "Read the `spam-stat' hash table from disk."
@@ -471,7 +479,7 @@ check the variable `spam-stat-score-data'."
       (progn
        (set-buffer spam-stat-buffer)
        (goto-char (point-min))
-       (when (> (spam-stat-score-buffer) 0.9)
+       (when (> (spam-stat-score-buffer) spam-stat-split-fancy-spam-threshhold)
          (when (boundp 'nnmail-split-trace)
            (mapc (lambda (entry)
                    (push entry nnmail-split-trace))
@@ -490,7 +498,8 @@ check the variable `spam-stat-score-data'."
     (with-temp-buffer
       (dolist (f files)
        (when (and (file-readable-p f)
-                  (file-regular-p f))
+                  (file-regular-p f)
+                   (> (nth 7 (file-attributes f)) 0))
          (setq count (1+ count))
          (message "Reading %s: %.2f%%" dir (/ count max))
          (insert-file-contents f)
@@ -526,7 +535,8 @@ You can use this to determine error rates."
     (with-temp-buffer
       (dolist (f files)
        (when (and (file-readable-p f)
-                  (file-regular-p f))
+                  (file-regular-p f)
+                   (> (nth 7 (file-attributes f)) 0))
          (setq count (1+ count))
          (message "Reading %.2f%%, score %.2f%%"
                   (/ count max) (/ score count))
@@ -551,6 +561,25 @@ COUNT defaults to 5"
               (remhash key spam-stat)))
           spam-stat))
 
+(defun spam-stat-install-hooks-function ()
+  "Install the spam-stat function hooks"
+  (interactive)
+  (add-hook 'nnmail-prepare-incoming-message-hook
+           'spam-stat-store-current-buffer)
+  (add-hook 'gnus-select-article-hook
+           'spam-stat-store-gnus-article-buffer))
+
+(when spam-stat-install-hooks
+  (spam-stat-install-hooks-function))
+
+(defun spam-stat-unload-hook ()
+  "Uninstall the spam-stat function hooks"
+  (interactive)
+  (remove-hook 'nnmail-prepare-incoming-message-hook
+              'spam-stat-store-current-buffer)
+  (remove-hook 'gnus-select-article-hook
+              'spam-stat-store-gnus-article-buffer))
+
 (provide 'spam-stat)
 
 ;;; spam-stat.el ends here