* gnus.el (ham-process-destination): added new parameter for
authorTeodor Zlatanov <tzz@lifelogs.com>
Wed, 8 Jan 2003 16:18:38 +0000 (16:18 +0000)
committerTeodor Zlatanov <tzz@lifelogs.com>
Wed, 8 Jan 2003 16:18:38 +0000 (16:18 +0000)
destination of ham articles found in spam groups at summary exit

* spam.el (spam-get-ifile-database-parameter): use spam-ifile-database-path
(spam-check-ifile, spam-ifile-register-with-ifile): use spam-get-ifile-database-parameter
(spam-ifile-database-path): added new parameter for ifile's database
(spam-move-spam-nonspam-groups-only): new parameter to determine
if spam should be moved from all groups or only some
(spam-summary-prepare-exit): fixed logic to use
spam-move-spam-nonspam-groups-only when deciding to invoke
spam-mark-spam-as-expired-and-move-routine; always invoke that
routine after the spam has been expired-or-moved in case there's
some spam left over; use spam-ham-move-routine in spam groups
(spam-ham-move-routine): new function to move ham articles to the
ham-process-destinations group parameter

lisp/ChangeLog
lisp/gnus.el
lisp/spam.el

index c0ffced..ac308a3 100644 (file)
@@ -1,3 +1,21 @@
+2003-01-08  Teodor Zlatanov  <tzz@lifelogs.com>
+
+       * gnus.el (ham-process-destination): added new parameter for
+       destination of ham articles found in spam groups at summary exit
+
+       * spam.el (spam-get-ifile-database-parameter): use spam-ifile-database-path
+       (spam-check-ifile, spam-ifile-register-with-ifile): use spam-get-ifile-database-parameter
+       (spam-ifile-database-path): added new parameter for ifile's database
+       (spam-move-spam-nonspam-groups-only): new parameter to determine
+       if spam should be moved from all groups or only some
+       (spam-summary-prepare-exit): fixed logic to use
+       spam-move-spam-nonspam-groups-only when deciding to invoke
+       spam-mark-spam-as-expired-and-move-routine; always invoke that
+       routine after the spam has been expired-or-moved in case there's
+       some spam left over; use spam-ham-move-routine in spam groups
+       (spam-ham-move-routine): new function to move ham articles to the
+       ham-process-destinations group parameter
+
 2003-01-08  Lars Magne Ingebrigtsen  <larsi@gnus.org>
 
        * gnus-spec.el (gnus-parse-complex-format): %~ => ~*.
index b1de540..e40badd 100644 (file)
@@ -1869,15 +1869,46 @@ to do spam-processed article moving, associated with the destination
 group or `nil' for explicit expiration.  This only makes sense for
 mail groups."
  :variable-group spam
- :variable-type '(repeat :tag "Spam-processed articles destination" 
-                        (list
-                         (regexp :tag "Group Regexp") 
-                         (choice :tag "Destination for spam-processed articles at summary exit"
-                                 (string :tag "Move to a group")
-                                 (other :tag "Expire" nil))))
+ :variable-type '(repeat 
+                 :tag "Spam-processed articles destination" 
+                 (list
+                  (regexp :tag "Group Regexp") 
+                  (choice 
+                   :tag "Destination for spam-processed articles at summary exit"
+                   (string :tag "Move to a group")
+                   (other :tag "Expire" nil))))
  :parameter-document
  "Where spam-processed articles will go at summary exit.")
 
+(gnus-define-group-parameter
+ ham-process-destination
+ :parameter-type '(choice 
+                  :tag "Destination for ham articles at summary exit from a spam group"
+                         (string :tag "Move to a group")
+                         (other :tag "Do nothing" nil))
+ :function-document
+ "Where ham articles will go at summary exit from a spam group."
+ :variable gnus-ham-process-destinations
+ :variable-default nil
+ :variable-document
+ "*Groups in which to explicitly send ham articles to
+another group, or do nothing (the default).  If non-nil, this should
+be a list of group name regexps that should match all groups in which
+to do ham article moving, associated with the destination
+group or `nil' for explicit ignoring.  This only makes sense for
+mail groups, and only works in spam groups."
+ :variable-group spam
+ :variable-type '(repeat 
+                 :tag "Ham articles destination" 
+                 (list
+                  (regexp :tag "Group Regexp") 
+                  (choice 
+                   :tag "Destination for ham articles at summary exit from spam group"
+                   (string :tag "Move to a group")
+                   (other :tag "Expire" nil))))
+ :parameter-document
+ "Where ham articles will go at summary exit from a spam group.")
+
 (defcustom gnus-group-uncollapsed-levels 1
   "Number of group name elements to leave alone when making a short group name."
   :group 'gnus-group-visual
index e0a463b..db3b22e 100644 (file)
   :type 'directory
   :group 'spam)
 
+(defcustom spam-move-spam-nonspam-groups-only t
+  "Whether spam should be moved in non-spam groups only.
+When nil, only ham and unclassified groups will have their spam moved
+to the spam-process-destination.  When t, spam will also be moved from
+spam groups."
+  :type 'boolean
+  :group 'spam-ifile)
+
 (defcustom spam-whitelist (expand-file-name "whitelist" spam-directory)
   "The location of the whitelist.
 The file format is one regular expression per line.
@@ -167,6 +175,12 @@ Such articles will be transmitted to `bogofilter -s' on group exit."
                 (const :tag "ifile is not installed"))
   :group 'spam-ifile)
 
+(defcustom spam-ifile-database-path nil
+  "File path of the ifile database."
+  :type '(choice (file :tag "Location of the ifile database")
+                (const :tag "Use the default"))
+  :group 'spam-ifile)
+
 (defcustom spam-ifile-spam-category "spam"
   "Name of the spam ifile category."  
   :type 'string
@@ -291,18 +305,29 @@ articles before they get registered by Bogofilter."
   (when (spam-group-spam-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)
+  (if spam-move-spam-nonspam-groups-only      
+      (when (not (spam-group-spam-contents-p gnus-newsgroup-name))
+       (spam-mark-spam-as-expired-and-move-routine
+        (gnus-parameter-spam-process-destination gnus-newsgroup-name)))
     (spam-mark-spam-as-expired-and-move-routine 
      (gnus-parameter-spam-process-destination gnus-newsgroup-name)))
 
+  ;; now we redo spam-mark-spam-as-expired-and-move-routine to only
+  ;; expire spam, in case the above did not expire them
+  (spam-mark-spam-as-expired-and-move-routine nil)
+
   (when (spam-group-ham-contents-p gnus-newsgroup-name)
     (when (spam-group-ham-processor-whitelist-p gnus-newsgroup-name)
       (spam-whitelist-register-routine))
     (when (spam-group-ham-processor-ifile-p gnus-newsgroup-name)
       (spam-ifile-register-ham-routine))
     (when (spam-group-ham-processor-BBDB-p gnus-newsgroup-name)
-      (spam-BBDB-register-routine))))
+      (spam-BBDB-register-routine)))
+
+  ;; now move all ham articles out of spam groups
+  (when (spam-group-spam-contents-p gnus-newsgroup-name)
+    (spam-ham-move-routine
+     (gnus-parameter-ham-process-destination gnus-newsgroup-name))))
 
 (add-hook 'gnus-summary-prepare-exit-hook 'spam-summary-prepare-exit)
 
@@ -328,13 +353,26 @@ articles before they get registered by Bogofilter."
          (let ((gnus-current-article article))
            (gnus-summary-move-article nil group)))))))
  
+(defun spam-ham-move-routine (&optional group)
+  (let ((articles gnus-newsgroup-articles)
+       article ham-mark-values mark)
+    (dolist (mark spam-ham-marks)
+      (push (symbol-value mark) ham-mark-values))
+
+    (while articles
+      (setq article (pop articles))
+      (when (and (memq mark ham-mark-values)
+                (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
+    ;; 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))
@@ -508,6 +546,12 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details."
 ;;; 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)
+    ""))
+    
 (defun spam-check-ifile ()
   "Check the ifile backend for the classification of this message"
   (let ((article-buffer-name (buffer-name)) 
@@ -517,7 +561,8 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details."
        (save-excursion
          (set-buffer article-buffer-name)
          (call-process-region (point-min) (point-max) spam-ifile-path 
-                              nil temp-buffer-name nil "-q" "-c"))
+                              nil temp-buffer-name nil 
+                              "-q" "-c" (spam-get-ifile-database-parameter)))
        (goto-char (point-min))
        (if (not (eobp))
            (setq category (buffer-substring (point) (spam-point-at-eol))))
@@ -526,7 +571,8 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details."
              (setq return category)
            ;; else, if spam-ifile-all-categories is not set...
            (when (string-equal spam-ifile-spam-category category)
-             (setq return spam-split-group))))))       ; always accept the ifile category
+             ;; always accept the ifile category
+             (setq return spam-split-group))))))       
     return))
 
 (defun spam-ifile-register-with-ifile (article-string category)
@@ -537,7 +583,9 @@ Uses `gnus-newsgroup-name' if category is nil (for ham registration)."
       (with-temp-buffer
        (insert-string article-string)
        (call-process-region (point-min) (point-max) spam-ifile-path 
-                            nil nil nil "-h" "-i" category)))))
+                            nil nil nil 
+                            "-h" "-i" category 
+                            (spam-get-ifile-database-parameter))))))
 
 (defun spam-ifile-register-spam-routine ()
   (spam-generic-register-routine