]> code.delx.au - gnu-emacs/blobdiff - lisp/mh-e/mh-junk.el
; Merge from origin/emacs-25
[gnu-emacs] / lisp / mh-e / mh-junk.el
index 196b39ed233a3414c4b6d9820adc7be336552d7b..8e19ef20f9a9f0464350e3ef0fc8593a6ba38fe6 100644 (file)
@@ -1,7 +1,6 @@
 ;;; mh-junk.el --- MH-E interface to anti-spam measures
 
 ;;; mh-junk.el --- MH-E interface to anti-spam measures
 
-;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 2003-2016 Free Software Foundation, Inc.
 
 ;; Author: Satyaki Das <satyaki@theforce.stanford.edu>,
 ;;         Bill Wohler <wohler@newt.com>
 
 ;; Author: Satyaki Das <satyaki@theforce.stanford.edu>,
 ;;         Bill Wohler <wohler@newt.com>
@@ -53,27 +52,64 @@ program, see:
   - `mh-bogofilter-blacklist'
   - `mh-spamprobe-blacklist'"
   (interactive (list (mh-interactive-range "Blacklist")))
   - `mh-bogofilter-blacklist'
   - `mh-spamprobe-blacklist'"
   (interactive (list (mh-interactive-range "Blacklist")))
+  (mh-iterate-on-range () range (mh-blacklist-a-msg nil))
+  (if (looking-at mh-scan-blacklisted-msg-regexp)
+      (mh-next-msg)))
+
+(defun mh-blacklist-a-msg (message)
+  "Blacklist MESSAGE.
+If MESSAGE is nil then the message at point is blacklisted.
+The hook `mh-blacklisted-msg-hook' is called after you mark a message
+for blacklisting."
+  (save-excursion
+    (if (numberp message)
+        (mh-goto-msg message nil t)
+      (beginning-of-line)
+      (setq message (mh-get-msg-num t)))
+    (cond ((looking-at mh-scan-refiled-msg-regexp)
+           (error "Message %d is refiled; undo refile before blacklisting"
+                  message))
+          ((looking-at mh-scan-deleted-msg-regexp)
+           (error "Message %d is deleted; undo delete before blacklisting"
+                  message))
+          ((looking-at mh-scan-whitelisted-msg-regexp)
+           (error "Message %d is whitelisted; undo before blacklisting"
+                  message))
+          ((looking-at mh-scan-blacklisted-msg-regexp) nil)
+          (t
+           (mh-set-folder-modified-p t)
+           (setq mh-blacklist (cons message mh-blacklist))
+           (if (not (memq message mh-seen-list))
+               (setq mh-seen-list (cons message mh-seen-list)))
+           (mh-notate nil mh-note-blacklisted mh-cmd-note)
+           (run-hooks 'mh-blacklist-msg-hook)))))
+
+;;;###mh-autoload
+(defun mh-junk-blacklist-disposition ()
+  "Determines the fate of the selected spam."
+  (cond ((null mh-junk-disposition) nil)
+        ((equal mh-junk-disposition "") "+")
+        ((eq (aref mh-junk-disposition 0) ?+)
+         mh-junk-disposition)
+        ((eq (aref mh-junk-disposition 0) ?@)
+         (concat mh-current-folder "/"
+                 (substring mh-junk-disposition 1)))
+        (t (concat "+" mh-junk-disposition))))
+
+;;;###mh-autoload
+(defun mh-junk-process-blacklist (range)
+  "Blacklist RANGE as spam.
+This command trains the spam program in use (see the option
+`mh-junk-program') with the content of RANGE and then handles the
+message(s) as specified by the option `mh-junk-disposition'."
   (let ((blacklist-func (nth 1 (assoc mh-junk-choice mh-junk-function-alist))))
     (unless blacklist-func
       (error "Customize `mh-junk-program' appropriately"))
   (let ((blacklist-func (nth 1 (assoc mh-junk-choice mh-junk-function-alist))))
     (unless blacklist-func
       (error "Customize `mh-junk-program' appropriately"))
-    (let ((dest (cond ((null mh-junk-disposition) nil)
-                      ((equal mh-junk-disposition "") "+")
-                      ((eq (aref mh-junk-disposition 0) ?+)
-                       mh-junk-disposition)
-                      ((eq (aref mh-junk-disposition 0) ?@)
-                       (concat mh-current-folder "/"
-                               (substring mh-junk-disposition 1)))
-                      (t (concat "+" mh-junk-disposition)))))
-      (mh-iterate-on-range msg range
-        (message "Blacklisting message %d..." msg)
-        (funcall (symbol-function blacklist-func) msg)
-        (message "Blacklisting message %d...done" msg)
-        (if (not (memq msg mh-seen-list))
-            (setq mh-seen-list (cons msg mh-seen-list)))
-        (if dest
-            (mh-refile-a-msg nil (intern dest))
-          (mh-delete-a-msg nil)))
-      (mh-next-msg))))
+    (mh-iterate-on-range msg range
+      (message "Blacklisting message %d..." msg)
+      (funcall (symbol-function blacklist-func) msg)
+      (message "Blacklisting message %d...done" msg))
+    (mh-next-msg)))
 
 ;;;###mh-autoload
 (defun mh-junk-whitelist (range)
 
 ;;;###mh-autoload
 (defun mh-junk-whitelist (range)
@@ -86,14 +122,49 @@ refiles the message into the \"+inbox\" folder.
 Check the documentation of `mh-interactive-range' to see how
 RANGE is read in interactive use."
   (interactive (list (mh-interactive-range "Whitelist")))
 Check the documentation of `mh-interactive-range' to see how
 RANGE is read in interactive use."
   (interactive (list (mh-interactive-range "Whitelist")))
+  (mh-iterate-on-range () range (mh-junk-whitelist-a-msg nil))
+  (if (looking-at mh-scan-whitelisted-msg-regexp)
+      (mh-next-msg)))
+
+(defun mh-junk-whitelist-a-msg (message)
+  "Whitelist MESSAGE.
+If MESSAGE is nil then the message at point is whitelisted. The
+hook `mh-whitelist-msg-hook' is called after you mark a message
+for whitelisting."
+  (save-excursion
+    (if (numberp message)
+        (mh-goto-msg message nil t)
+      (beginning-of-line)
+      (setq message (mh-get-msg-num t)))
+    (cond ((looking-at mh-scan-refiled-msg-regexp)
+           (error "Message %d is refiled; undo refile before whitelisting"
+                  message))
+          ((looking-at mh-scan-deleted-msg-regexp)
+           (error "Message %d is deleted; undo delete before whitelisting"
+                  message))
+          ((looking-at mh-scan-blacklisted-msg-regexp)
+           (error "Message %d is blacklisted; undo before whitelisting"
+                  message))
+          ((looking-at mh-scan-whitelisted-msg-regexp) nil)
+          (t
+           (mh-set-folder-modified-p t)
+           (setq mh-whitelist (cons message mh-whitelist))
+           (mh-notate nil mh-note-whitelisted mh-cmd-note)
+           (run-hooks 'mh-whitelist-msg-hook)))))
+
+;;;###mh-autoload
+(defun mh-junk-process-whitelist (range)
+  "Whitelist RANGE as ham.
+
+This command reclassifies the RANGE as ham if it were incorrectly
+classified as spam (see the option `mh-junk-program')."
   (let ((whitelist-func (nth 2 (assoc mh-junk-choice mh-junk-function-alist))))
     (unless whitelist-func
       (error "Customize `mh-junk-program' appropriately"))
     (mh-iterate-on-range msg range
       (message "Whitelisting message %d..." msg)
       (funcall (symbol-function whitelist-func) msg)
   (let ((whitelist-func (nth 2 (assoc mh-junk-choice mh-junk-function-alist))))
     (unless whitelist-func
       (error "Customize `mh-junk-program' appropriately"))
     (mh-iterate-on-range msg range
       (message "Whitelisting message %d..." msg)
       (funcall (symbol-function whitelist-func) msg)
-      (message "Whitelisting message %d...done" msg)
-      (mh-refile-a-msg nil (intern mh-inbox)))
+      (message "Whitelisting message %d...done" msg))
     (mh-next-msg)))
 
 \f
     (mh-next-msg)))
 
 \f
@@ -108,8 +179,8 @@ RANGE is read in interactive use."
   "Blacklist MSG with SpamAssassin.
 
 SpamAssassin is one of the more popular spam filtering programs.
   "Blacklist MSG with SpamAssassin.
 
 SpamAssassin is one of the more popular spam filtering programs.
-Get it from your local distribution or from
-URL `http://spamassassin.org/'.
+Get it from your local distribution or from the SpamAssassin web
+site at URL `http://spamassassin.org/'.
 
 To use SpamAssassin, add the following recipes to
 \".procmailrc\":
 
 To use SpamAssassin, add the following recipes to
 \".procmailrc\":
@@ -313,9 +384,9 @@ information can be used so that you can replace multiple
     (delete-other-windows)
     (pop-to-buffer (get-buffer-create "*MH-E Spammer Frequencies*"))
     (erase-buffer)
     (delete-other-windows)
     (pop-to-buffer (get-buffer-create "*MH-E Spammer Frequencies*"))
     (erase-buffer)
-    (maphash '(lambda (key value) ""
-                (if (> value 2)
-                    (insert (format "%s %s\n" key value))))
+    (maphash (lambda (key value) ""
+               (if (> value 2)
+                   (insert (format "%s %s\n" key value))))
              domains)
     (sort-numeric-fields 2 (point-min) (point-max))
     (reverse-region (point-min) (point-max))
              domains)
     (sort-numeric-fields 2 (point-min) (point-max))
     (reverse-region (point-min) (point-max))
@@ -332,7 +403,8 @@ information can be used so that you can replace multiple
   "Blacklist MSG with bogofilter.
 
 Bogofilter is a Bayesian spam filtering program. Get it from your
   "Blacklist MSG with bogofilter.
 
 Bogofilter is a Bayesian spam filtering program. Get it from your
-local distribution or from URL `http://bogofilter.sourceforge.net/'.
+local distribution or from the bogofilter web site at URL
+`http://bogofilter.sourceforge.net/'.
 
 Bogofilter is taught by running:
 
 
 Bogofilter is taught by running:
 
@@ -411,8 +483,9 @@ See `mh-bogofilter-blacklist' for more information."
 (defun mh-spamprobe-blacklist (msg)
   "Blacklist MSG with SpamProbe.
 
 (defun mh-spamprobe-blacklist (msg)
   "Blacklist MSG with SpamProbe.
 
-SpamProbe is a Bayesian spam filtering program. Get it from your local
-distribution or from URL `http://spamprobe.sourceforge.net'.
+SpamProbe is a Bayesian spam filtering program. Get it from your
+local distribution or from the SpamProbe web site at URL
+`http://spamprobe.sourceforge.net'.
 
 To use SpamProbe, add the following recipes to \".procmailrc\":
 
 
 To use SpamProbe, add the following recipes to \".procmailrc\":
 
@@ -465,5 +538,4 @@ See `mh-spamprobe-blacklist' for more information."
 ;; sentence-end-double-space: nil
 ;; End:
 
 ;; sentence-end-double-space: nil
 ;; End:
 
-;; arch-tag: 603335f1-77ff-4306-8828-5d3dad51abe1
 ;;; mh-junk.el ends here
 ;;; mh-junk.el ends here