(gnus-article-decode-hook): Add IDNA.
[gnus] / lisp / spam.el
index e259933..e95baf5 100644 (file)
@@ -40,6 +40,9 @@
 (require 'gnus)        ; for the definitions of group content classification and spam processors
 (require 'message)                     ;for the message-fetch-field functions
 
+;; for nnimap-split-download-body-default
+(eval-when-compile (require 'nnimap))
+
 ;; autoload executable-find
 (eval-and-compile
   ;; executable-find is not autoloaded in Emacs 20
@@ -69,7 +72,15 @@ 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)
+  :group 'spam)
+
+(defcustom spam-mark-ham-unread-before-move-from-spam-group nil
+  "Whether ham should be marked unread before it's moved out of a spam
+group according to ham-process-destination.  This variable is an
+official entry in the international Longest Variable Name
+Competition."
+  :type 'boolean
+  :group 'spam)
 
 (defcustom spam-whitelist (expand-file-name "whitelist" spam-directory)
   "The location of the whitelist.
@@ -112,6 +123,11 @@ are considered spam."
   :type 'boolean
   :group 'spam)
 
+(defcustom spam-use-hashcash nil
+  "Whether hashcash payments should be detected by spam-split."
+  :type 'boolean
+  :group 'spam)
+
 (defcustom spam-use-regex-headers nil
   "Whether a header regular expression match should be used by spam-split.
 Also see the variable `spam-spam-regex-headers' and `spam-ham-regex-headers'."
@@ -262,6 +278,16 @@ your main source of newsgroup names."
   :type 'string
   :group 'spam-bogofilter)
 
+(defcustom spam-bogofilter-spam-switch "-s"
+  "The switch that Bogofilter uses to register spam messages."
+  :type 'string
+  :group 'spam-bogofilter)
+
+(defcustom spam-bogofilter-ham-switch "-n"
+  "The switch that Bogofilter uses to register ham messages."
+  :type 'string
+  :group 'spam-bogofilter)
+
 (defcustom spam-bogofilter-bogosity-positive-spam-header "^\\(Yes\\|Spam\\)"
   "The regex on `spam-bogofilter-header' for positive spam identification."
   :type 'regexp
@@ -455,6 +481,8 @@ your main source of newsgroup names."
       ;; now do the actual move
       (when tomove
        (dolist (article tomove)
+         (when spam-mark-ham-unread-before-move-from-spam-group
+           (gnus-summary-mark-article article gnus-unread-mark))           
          (gnus-summary-set-process-mark article))
        (if copy
            (gnus-summary-copy-article nil group)
@@ -548,6 +576,7 @@ your main source of newsgroup names."
     (spam-use-ifile                    .       spam-check-ifile)
     (spam-use-stat                     .       spam-check-stat)
     (spam-use-blackholes               .       spam-check-blackholes)
+    (spam-use-hashcash                 .       spam-check-hashcash)
     (spam-use-bogofilter-headers       .       spam-check-bogofilter-headers)
     (spam-use-bogofilter               .       spam-check-bogofilter))
 "The spam-list-of-checks list contains pairs associating a parameter
@@ -562,6 +591,11 @@ should go, and further checks are also inhibited.  The usual mailgroup
 name is the value of `spam-split-group', meaning that the message is
 definitely a spam.")
 
+(defvar spam-list-of-statistical-checks
+  '(spam-use-ifile spam-use-stat spam-use-bogofilter)
+"The spam-list-of-statistical-checks list contains all the mail
+splitters that need to have the full message body available.")
+
 (defun spam-split ()
   "Split this message into the `spam' group if it is spam.
 This function can be used as an entry in `nnmail-split-fancy', for
@@ -569,10 +603,14 @@ example like this: (: spam-split)
 
 See the Info node `(gnus)Fancy Mail Splitting' for more details."
   (interactive)
-  
-  ;; load the spam-stat tables if needed
-  (when spam-use-stat (spam-stat-load))
 
+  (dolist (check spam-list-of-statistical-checks)
+    (when (symbol-value check)
+      (widen)
+      (gnus-message 8 "spam-split: widening the buffer (%s requires it)"
+                   (symbol-name check))
+      (return)))
+;;   (progn (widen) (debug (buffer-string)))
   (let ((list-of-checks spam-list-of-checks)
        decision)
     (while (and list-of-checks (not decision))
@@ -583,6 +621,14 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details."
     (if (eq decision t)
        nil
       decision)))
+
+(defun spam-setup-widening ()
+  (dolist (check spam-list-of-statistical-checks)
+    (when (symbol-value check)
+      (setq nnimap-split-download-body-default t))))
+
+(add-hook 'gnus-get-new-news-hook 'spam-setup-widening)
+
 \f
 ;;;; Regex headers
 
@@ -630,7 +676,8 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details."
              (if spam-use-dig
                  (let ((query-result (query-dig query-string)))
                    (when query-result
-                     (gnus-message 5 "(DIG): positive blackhole check '%s'" query-result)
+                     (gnus-message 5 "(DIG): positive blackhole check '%s'" 
+                                   query-result)
                      (push (list ip server query-result)
                            matches)))
                ;; else, if not using dig.el
@@ -641,6 +688,20 @@ See the Info node `(gnus)Fancy Mail Splitting' for more details."
     (when matches
       spam-split-group)))
 \f
+;;;; Hashcash.
+
+(condition-case nil
+    (progn
+      (require 'hashcash)
+      
+      (defun spam-check-hashcash ()
+       "Check the headers for hashcash payments."
+       (mail-check-payment)))          ;mail-check-payment returns a boolean
+
+  (file-error (progn
+               (defalias 'mail-check-payment 'ignore)
+               (defalias 'spam-check-hashcash 'ignore))))
+\f
 ;;;; BBDB 
 
 ;;; original idea for spam-check-BBDB from Alexander Kotelnikov
@@ -792,8 +853,16 @@ Uses `gnus-newsgroup-name' if category is nil (for ham registration)."
               (insert article-string)
               (spam-stat-buffer-is-non-spam))))))
 
-      (when spam-use-stat
-       (add-hook 'gnus-save-newsrc-hook 'spam-stat-save)))
+      (defun spam-maybe-spam-stat-load ()
+       (when spam-use-stat (spam-stat-load)))
+      
+      (defun spam-maybe-spam-stat-save ()
+       (when spam-use-stat (spam-stat-save)))
+
+      ;; Add hooks for loading and saving the spam stats
+      (add-hook 'gnus-save-newsrc-hook 'spam-maybe-spam-stat-save)
+      (add-hook 'gnus-get-top-new-news-hook 'spam-maybe-spam-stat-load)
+      (add-hook 'gnus-startup-hook 'spam-maybe-spam-stat-load))
 
   (file-error (progn
                (defalias 'spam-stat-register-ham-routine 'ignore)
@@ -943,7 +1012,8 @@ Uses `gnus-newsgroup-name' if category is nil (for ham registration)."
 (defun spam-bogofilter-register-with-bogofilter (article-string spam)
   "Register an article, given as a string, as spam or non-spam."
   (when (stringp article-string)
-    (let ((switch (if spam "-s" "-n")))
+    (let ((switch (if spam spam-bogofilter-spam-switch 
+                   spam-bogofilter-ham-switch)))
       (with-temp-buffer
        (insert article-string)
        (if spam-bogofilter-database-directory