(spam-group-spam-contents-p, spam-group-ham-contents-p)
authorTeodor Zlatanov <tzz@lifelogs.com>
Fri, 3 Jan 2003 01:32:46 +0000 (01:32 +0000)
committerTeodor Zlatanov <tzz@lifelogs.com>
Fri, 3 Jan 2003 01:32:46 +0000 (01:32 +0000)
(spam-group-processor-p, spam-group-processor-bogofilter-p)
(spam-group-processor-ifile-p, spam-group-processor-blacklist-p)
(spam-group-processor-whitelist-p, spam-group-processor-BBDB-p)
(spam-mark-spam-as-expired-and-move-routine)
(spam-generic-register-routine, spam-BBDB-register-routine)
(spam-ifile-register-routine, spam-blacklist-register-routine)
(spam-whitelist-register-routine): new functions
(spam-summary-prepare-exit): added summary exit processing (expire
or move) of spam-marked articles for spam groups; added slots for
all the spam-*-register-routine functions

lisp/ChangeLog
lisp/spam.el

index cce5b84..e777440 100644 (file)
@@ -1,3 +1,17 @@
+2003-01-02  Teodor Zlatanov  <tzz@lifelogs.com>
+
+       * spam.el (spam-group-spam-contents-p, spam-group-ham-contents-p)
+       (spam-group-processor-p, spam-group-processor-bogofilter-p) 
+       (spam-group-processor-ifile-p, spam-group-processor-blacklist-p) 
+       (spam-group-processor-whitelist-p, spam-group-processor-BBDB-p) 
+       (spam-mark-spam-as-expired-and-move-routine) 
+       (spam-generic-register-routine, spam-BBDB-register-routine) 
+       (spam-ifile-register-routine, spam-blacklist-register-routine) 
+       (spam-whitelist-register-routine): new functions
+       (spam-summary-prepare-exit): added summary exit processing (expire
+       or move) of spam-marked articles for spam groups; added slots for
+       all the spam-*-register-routine functions
+
 2003-01-03  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
        * gnus-msg.el (gnus-setup-message): Get the evaliation order
index c067ceb..946135e 100644 (file)
@@ -233,7 +233,27 @@ articles before they get registered by Bogofilter."
   (if (stringp group)
       (memq 'gnus-group-spam-classification-ham (gnus-parameter-spam-contents group))
     nil))
-  
+
+(defun spam-group-processor-p (group processor)
+  (if (and (stringp group)
+          (symbolp processor))
+      (member processor (car (gnus-parameter-spam-process group)))
+    nil))
+
+(defun spam-group-processor-bogofilter-p (group)
+  (spam-group-processor-p group 'gnus-group-spam-exit-processor-bogofilter))
+
+(defun spam-group-processor-ifile-p (group)
+  (spam-group-processor-p group 'gnus-group-spam-exit-processor-ifile))
+
+(defun spam-group-processor-blacklist-p (group)
+  (spam-group-processor-p group 'gnus-group-spam-exit-processor-blacklist))
+
+(defun spam-group-processor-whitelist-p (group)
+  (spam-group-processor-p group 'gnus-group-ham-exit-processor-whitelist))
+
+(defun spam-group-processor-BBDB-p (group)
+  (spam-group-processor-p group 'gnus-group-ham-exit-processor-BBDB))
 
 ;;; Hooks dispatching.  A bit raw for now.
 
@@ -241,16 +261,31 @@ articles before they get registered by Bogofilter."
   (spam-mark-junk-as-spam-routine))
 
 (defun spam-summary-prepare-exit ()
-  (spam-bogofilter-register-routine)
+  ;; The spam processors are invoked for any group, spam or ham or neither
+  (when (or (and spam-use-bogofilter spam-bogofilter-path)
+           (spam-group-processor-bogofilter-p gnus-newsgroup-name))
+    (spam-bogofilter-register-routine))
+  
+  (when (or spam-use-ifile
+           (spam-group-processor-ifile-p gnus-newsgroup-name))
+    (spam-ifile-register-routine))
+  
+  (when (or spam-use-blacklist
+           (spam-group-processor-bogofilter-p gnus-newsgroup-name))
+    (spam-blacklist-register-routine))
+
+  ;; Only for spam groups, we expire and maybe move articles
   (when (spam-group-spam-contents-p gnus-newsgroup-name)
-    (                                
-     ;; TODO: the spam processors here
-     ;; TODO: the spam-processed articles will be moved here
-     ))
+    (spam-mark-spam-as-expired-and-move-routine (gnus-parameter-spam-process-destination gnus-newsgroup-name)))
+
   (when (spam-group-ham-contents-p gnus-newsgroup-name)
-    (
-     ;; TODO: the ham processors here
-     )))
+    ;; TODO: the ham processors here
+    (when (or spam-use-whitelist
+             (spam-group-processor-whitelist-p gnus-newsgroup-name))
+      (spam-whitelist-register-routine))
+    (when (or spam-use-BBDB
+             (spam-group-processor-BBDB-p gnus-newsgroup-name))
+      (spam-BBDB-register-routine))))
 
 (add-hook 'gnus-summary-prepare-hook 'spam-summary-prepare)
 (add-hook 'gnus-summary-prepare-exit-hook 'spam-summary-prepare-exit)
@@ -264,6 +299,41 @@ articles before they get registered by Bogofilter."
        (setq article (pop articles))
        (when (eq (gnus-summary-article-mark article) gnus-unread-mark)
          (gnus-summary-mark-article article gnus-spam-mark))))))
+
+(defun spam-mark-spam-as-expired-and-move-routine (&optional group)
+  (let ((articles gnus-newsgroup-articles)
+       article)
+    (while articles
+      (setq article (pop articles))
+      (when (eq (gnus-summary-article-mark article) gnus-spam-mark)
+       (gnus-summary-mark-article article gnus-expirable-mark)
+       (when (stringp group)
+         (let ((gnus-current-article article))
+           (gnus-summary-move-article nil group)))))))
+(defun spam-generic-register-routine (spam-func ham-func)
+  (let ((articles gnus-newsgroup-articles)
+       article mark ham-articles spam-articles spam-mark-values ham-mark-values)
+
+    ;; marks are stored as symbolic values, so we have to dereference them for memq to work
+    ;; we wouldn't have to do this if gnus-summary-article-mark returned a symbol.
+    (dolist (mark spam-ham-marks)
+      (push (symbol-value mark) ham-mark-values))
+
+    (dolist (mark spam-spam-marks)
+      (push (symbol-value mark) spam-mark-values))
+
+    (while articles
+      (setq article (pop articles)
+           mark (gnus-summary-article-mark article))
+      (cond ((memq mark spam-mark-values) (push article spam-articles))
+           ((memq article gnus-newsgroup-saved))
+           ((memq mark ham-mark-values) (push article ham-articles))))
+    (when (and ham-articles ham-func)
+      (funcall ham-func ham-articles))
+    (when (and spam-articles spam-func)
+      (funcall spam-func spam-articles))))
+
 \f
 ;;;; Spam determination.
 
@@ -389,12 +459,20 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details."
                    (delete (assoc 'spam-use-bbdb spam-list-of-checks)
                            spam-list-of-checks))))
 
+;; TODO: add BBDB registration
+(defun spam-BBDB-register-routine
+  (spam-generic-register-routine nil nil))
+
 ;;; check the ifile backend; return nil if the mail was NOT classified as spam
 ;;; TODO: we can't (require) ifile, because it will insinuate itself automatically
 (defun spam-check-ifile ()
   (let ((ifile-primary-spam-group spam-split-group))
     (ifile-spam-filter nil)))
 
+;; TODO: add ifile registration
+(defun spam-ifile-register-routine
+  (spam-generic-register-routine nil nil))
+
 (defun spam-check-blacklist ()
   ;; FIXME!  Should it detect when file timestamps change?
   (unless spam-blacklist-cache
@@ -430,6 +508,12 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details."
              cache nil)))
     found))
 
+;; TODO: add blacklist and whitelist registrations
+(defun spam-blacklist-register-routine
+  (spam-generic-register-routine nil nil))
+(defun spam-whitelist-register-routine
+  (spam-generic-register-routine nil nil))
+
 \f
 ;;;; Training via Bogofilter.   Last updated 2002-09-02.
 
@@ -549,28 +633,27 @@ spamicity coefficient of each, and the overall article spamicity."
          (display-buffer (current-buffer)))))))
 
 (defun spam-bogofilter-register-routine ()
-  (when (and spam-use-bogofilter spam-bogofilter-path)
-    (let ((articles gnus-newsgroup-articles)
-         article mark ham-articles spam-articles spam-mark-values ham-mark-values)
-
-      ;; marks are stored as symbolic values, so we have to dereference them for memq to work
-      ;; we wouldn't have to do this if gnus-summary-article-mark returned a symbol.
-      (dolist (mark spam-ham-marks)
-       (push (symbol-value mark) ham-mark-values))
-
-      (dolist (mark spam-spam-marks)
-       (push (symbol-value mark) spam-mark-values))
-
-      (while articles
-       (setq article (pop articles)
-             mark (gnus-summary-article-mark article))
-       (cond ((memq mark spam-mark-values) (push article spam-articles))
-             ((memq article gnus-newsgroup-saved))
-             ((memq mark ham-mark-values) (push article ham-articles))))
-      (when ham-articles
-       (spam-bogofilter-articles "ham" "-n" ham-articles))
-      (when spam-articles
-       (spam-bogofilter-articles "SPAM" "-s" spam-articles)))))
+  (let ((articles gnus-newsgroup-articles)
+       article mark ham-articles spam-articles spam-mark-values ham-mark-values)
+
+    ;; marks are stored as symbolic values, so we have to dereference them for memq to work
+    ;; we wouldn't have to do this if gnus-summary-article-mark returned a symbol.
+    (dolist (mark spam-ham-marks)
+      (push (symbol-value mark) ham-mark-values))
+
+    (dolist (mark spam-spam-marks)
+      (push (symbol-value mark) spam-mark-values))
+
+    (while articles
+      (setq article (pop articles)
+           mark (gnus-summary-article-mark article))
+      (cond ((memq mark spam-mark-values) (push article spam-articles))
+           ((memq article gnus-newsgroup-saved))
+           ((memq mark ham-mark-values) (push article ham-articles))))
+    (when ham-articles
+      (spam-bogofilter-articles "ham" "-n" ham-articles))
+    (when spam-articles
+      (spam-bogofilter-articles "SPAM" "-s" spam-articles))))
 
 (defun spam-bogofilter-articles (type option articles)
   (let ((output-buffer (get-buffer-create spam-bogofilter-output-buffer-name))