]> code.delx.au - gnu-emacs/blobdiff - lisp/gnus/spam.el
Merge from emacs--rel--22
[gnu-emacs] / lisp / gnus / spam.el
index 8b722c95586293ce7959da9a4da7380a35d626b1..512192857abe272710e8bfd077b484a40e3d6f65 100644 (file)
@@ -1,6 +1,6 @@
 ;;; spam.el --- Identifying spam
 
-;; Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 ;; Keywords: network
@@ -100,6 +100,12 @@ spam groups."
   :type 'boolean
   :group 'spam)
 
+(defcustom spam-mark-new-messages-in-spam-group-as-spam t
+  "Whether new messages in a spam group should get the spam-mark."
+  :type 'boolean
+  ;; :version "22.1" ;; Gnus 5.10.8 / No Gnus 0.3
+  :group 'spam)
+
 (defcustom spam-log-to-registry nil
   "Whether spam/ham processing should be logged in the registry."
   :type 'boolean
@@ -345,14 +351,18 @@ All unmarked article in such group receive the spam mark on group entry."
   "Spam ifile configuration."
   :group 'spam)
 
-(defcustom spam-ifile-path (executable-find "ifile")
-  "File path of the ifile executable program."
+(make-obsolete-variable 'spam-ifile-path 'spam-ifile-program)
+;; "22.1" ;; Gnus 5.10.9
+(defcustom spam-ifile-program (executable-find "ifile")
+  "Name of the ifile program."
   :type '(choice (file :tag "Location of ifile")
                 (const :tag "ifile is not installed"))
   :group 'spam-ifile)
 
-(defcustom spam-ifile-database-path nil
-  "File path of the ifile database."
+(make-obsolete-variable 'spam-ifile-database-path 'spam-ifile-database)
+;; "22.1" ;; Gnus 5.10.9
+(defcustom spam-ifile-database nil
+  "File name of the ifile database."
   :type '(choice (file :tag "Location of the ifile database")
                 (const :tag "Use the default"))
   :group 'spam-ifile)
@@ -380,8 +390,10 @@ your main source of newsgroup names."
   "Spam bogofilter configuration."
   :group 'spam)
 
-(defcustom spam-bogofilter-path (executable-find "bogofilter")
-  "File path of the Bogofilter executable program."
+(make-obsolete-variable 'spam-bogofilter-path 'spam-bogofilter-program)
+;; "22.1" ;; Gnus 5.10.9
+(defcustom spam-bogofilter-program (executable-find "bogofilter")
+  "Name of the Bogofilter program."
   :type '(choice (file :tag "Location of bogofilter")
                 (const :tag "Bogofilter is not installed"))
   :group 'spam-bogofilter)
@@ -417,7 +429,8 @@ your main source of newsgroup names."
   :group 'spam-bogofilter)
 
 (defcustom spam-bogofilter-database-directory nil
-  "Directory path of the Bogofilter databases."
+  "Location of the Bogofilter database.
+When nil, use the default location."
   :type '(choice (directory
                  :tag "Location of the Bogofilter database directory")
                 (const :tag "Use the default"))
@@ -428,8 +441,8 @@ your main source of newsgroup names."
   :group 'spam)
 
 (defcustom spam-spamoracle-database nil
-  "Location of spamoracle database file. When nil, use the default
-spamoracle database."
+  "Location of spamoracle database file.
+When nil, use the default spamoracle database."
   :type '(choice (directory :tag "Location of spamoracle database file.")
                 (const :tag "Use the default"))
   :group 'spam-spamoracle)
@@ -467,14 +480,28 @@ spamoracle database."
   "Logical exclusive `or'."
   (and (or a b) (not (and a b))))
 
+(defun spam-group-ham-mark-p (group mark &optional spam)
+  (when (stringp group)
+    (let* ((marks (spam-group-ham-marks group spam))
+          (marks (if (symbolp mark)
+                     marks
+                   (mapcar 'symbol-value marks))))
+      (memq mark marks))))
+
+(defun spam-group-spam-mark-p (group mark)
+  (spam-group-ham-mark-p group mark t))
+
 (defun spam-group-ham-marks (group &optional spam)
   (when (stringp group)
-    (let ((marks (car (if spam
-                         (gnus-parameter-spam-marks group)
-                       (gnus-parameter-ham-marks group)))))
-      (if (listp (car marks))
-         (car marks)
-       marks))))
+    (let* ((marks (if spam
+                     (gnus-parameter-spam-marks group)
+                   (gnus-parameter-ham-marks group)))
+          (marks (car marks))
+          (marks (if (listp (car marks)) (car marks) marks)))
+      marks)))
+
+(defun spam-group-spam-marks (group)
+  (spam-group-ham-marks group t))
 
 (defun spam-group-spam-contents-p (group)
   (if (stringp group)
@@ -662,15 +689,17 @@ spam-use-* variable.")
   ;; check the global list of group names spam-junk-mailgroups and the
   ;; group parameters
   (when (spam-group-spam-contents-p gnus-newsgroup-name)
-    (gnus-message 5 "Marking %s articles as spam"
+    (gnus-message 6 "Marking %s articles as spam"
                  (if spam-mark-only-unseen-as-spam
                      "unseen"
                    "unread"))
     (let ((articles (if spam-mark-only-unseen-as-spam
                        gnus-newsgroup-unseen
                      gnus-newsgroup-unreads)))
-      (dolist (article articles)
-       (gnus-summary-mark-article article gnus-spam-mark)))))
+      (if spam-mark-new-messages-in-spam-group-as-spam
+         (dolist (article articles)
+           (gnus-summary-mark-article article gnus-spam-mark))
+       (gnus-message 9 "Did not mark new messages as spam.")))))
 
 (defun spam-mark-spam-as-expired-and-move-routine (&rest groups)
   (if (and (car-safe groups) (listp (car-safe groups)))
@@ -718,7 +747,7 @@ spam-use-* variable.")
         (gnus-check-backend-function
          'request-move-article gnus-newsgroup-name))
        (respool-method (gnus-find-method-for-group gnus-newsgroup-name))
-       article mark todo deletep respool)
+       article mark deletep respool)
 
     (when (member 'respool groups)
       (setq respool t)                 ; boolean for later
@@ -1036,12 +1065,23 @@ functions")
       (nth 2 flist))))
 
 (defun spam-list-articles (articles classification)
-  (let ((marks (mapcar 'eval (spam-group-ham-marks gnus-newsgroup-name
-                                                  (eq classification 'spam))))
-       list)
+  (let ((mark-check (if (eq classification 'spam)
+                       'spam-group-spam-mark-p
+                     'spam-group-ham-mark-p))
+       list mark-cache-yes mark-cache-no)
     (dolist (article articles)
-      (if (memq (gnus-summary-article-mark article) marks)
-         (push article list)))
+      (let ((mark (gnus-summary-article-mark article)))
+       (unless (memq mark mark-cache-no)
+         (if (memq mark mark-cache-yes)
+             (push article list)
+           ;; else, we have to actually check the mark
+           (if (funcall mark-check
+                        gnus-newsgroup-name
+                        mark)
+               (progn
+                 (push article list)
+                 (push mark mark-cache-yes))
+             (push mark mark-cache-no))))))
     list))
 
 (defun spam-register-routine (classification
@@ -1337,11 +1377,12 @@ functions")
 ;;; check the ifile backend; return nil if the mail was NOT classified
 ;;; as spam
 
+
 (defun spam-get-ifile-database-parameter ()
-  "Get the command-line parameter for ifile's database from
-  spam-ifile-database-path."
-  (if spam-ifile-database-path
-      (format "--db-file=%s" spam-ifile-database-path)
+  "Return the command-line parameter for ifile's database.
+See `spam-ifile-database'."
+  (if spam-ifile-database
+      (format "--db-file=%s" spam-ifile-database)
     nil))
 
 (defun spam-check-ifile ()
@@ -1357,7 +1398,7 @@ functions")
        (save-excursion
          (set-buffer article-buffer-name)
          (apply 'call-process-region
-                (point-min) (point-max) spam-ifile-path
+                (point-min) (point-max) spam-ifile-program
                 nil temp-buffer-name nil "-c"
                 (if db-param `(,db-param "-q") `("-q"))))
        ;; check the return now (we're back in the temp buffer)
@@ -1385,7 +1426,7 @@ Uses `gnus-newsgroup-name' if category is nil (for ham registration)."
          (when (stringp article-string)
            (insert article-string))))
       (apply 'call-process-region
-            (point-min) (point-max) spam-ifile-path
+            (point-min) (point-max) spam-ifile-program
             nil nil nil
             add-or-delete-option category
             (if db `(,db "-h") `("-h"))))))
@@ -1669,7 +1710,7 @@ REMOVE not nil, remove the ADDRESSES."
          (set-buffer article-buffer-name)
          (apply 'call-process-region
                 (point-min) (point-max)
-                spam-bogofilter-path
+                spam-bogofilter-program
                 nil temp-buffer-name nil
                 (if db `("-d" ,db "-v") `("-v"))))
        (setq return (spam-check-bogofilter-headers score))))
@@ -1695,7 +1736,7 @@ REMOVE not nil, remove the ADDRESSES."
 
          (apply 'call-process-region
                 (point-min) (point-max)
-                spam-bogofilter-path
+                spam-bogofilter-program
                 nil nil nil switch
                 (if db `("-d" ,db "-v") `("-v"))))))))