;;; Code:
(eval-when-compile (require 'cl))
+(eval-when-compile (require 'spam-report))
(require 'path-util)
(require 'gnus-sum)
: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
+ :group 'spam)
+
(defcustom spam-process-ham-in-nonham-groups nil
"Whether ham should be processed in non-ham groups."
:type 'boolean
(defun spam-group-spam-contents-p (group)
"Is GROUP a spam group?"
- (if (stringp group)
+ (if (and (stringp group) (< 0 (length group)))
(or (member group spam-junk-mailgroups)
(memq 'gnus-group-spam-classification-spam
(gnus-parameter-spam-contents group)))
nil))
(defvar spam-list-of-processors
- ;; note the CRM114, resend and gmane processors are not defined in gnus.el
- '((gnus-group-spam-exit-processor-report-gmane spam spam-use-gmane)
- (gnus-group-spam-exit-processor-report-resend spam spam-use-resend)
+ ;; note the nil processors are not defined in gnus.el
+ '((nil spam spam-use-gmane)
+ (nil spam spam-use-resend)
(gnus-group-spam-exit-processor-bogofilter spam spam-use-bogofilter)
(gnus-group-spam-exit-processor-bsfilter spam spam-use-bsfilter)
(gnus-group-spam-exit-processor-blacklist spam spam-use-blacklist)
(gnus-group-spam-exit-processor-ifile spam spam-use-ifile)
(gnus-group-spam-exit-processor-stat spam spam-use-stat)
(gnus-group-spam-exit-processor-spamoracle spam spam-use-spamoracle)
- (gnus-group-spam-exit-processor-crm114 spam spam-use-crm114)
+ (nil spam spam-use-crm114)
(gnus-group-spam-exit-processor-spamassassin spam spam-use-spamassassin)
+
+ (nil ham spam-use-resend)
(gnus-group-ham-exit-processor-ifile ham spam-use-ifile)
(gnus-group-ham-exit-processor-bogofilter ham spam-use-bogofilter)
(gnus-group-ham-exit-processor-bsfilter ham spam-use-bsfilter)
(gnus-group-ham-exit-processor-copy ham spam-use-ham-copy)
(gnus-group-ham-exit-processor-spamassassin ham spam-use-spamassassin)
(gnus-group-ham-exit-processor-spamoracle ham spam-use-spamoracle)
- (gnus-group-ham-exit-processor-crm114 ham spam-use-crm114))
+ (nil ham spam-use-crm114))
"The `spam-list-of-processors' list.
-This list contains pairs associating a ham/spam exit processor
-variable with a classification and a spam-use-* variable.")
-
-(defun spam-group-processor-p (group processor)
+This list contains pairs associating the obsolete ham/spam exit
+processor variables with a classification and a spam-use-*
+variable. When the processor variable is nil, just the
+classification and spam-use-* check variable are used.")
+
+(defun spam-group-processor-p (group check &optional classification)
+ "Checks if GROUP has a CHECK with CLASSIFICATION registered.
+Also accepts the obsolete processors, which can be found in
+gnus.el and in spam-list-of-processors."
(if (and (stringp group)
- (symbolp processor))
- (or (member processor (nth 0 (gnus-parameter-spam-process group)))
- (spam-group-processor-multiple-p
- group
- (cdr-safe (assoc processor spam-list-of-processors))))
+ (symbolp check))
+ (let ((old-style (assq check spam-list-of-processors))
+ (parameters (nth 0 (gnus-parameter-spam-process group)))
+ found)
+ (if old-style ; old-style processor
+ (spam-group-processor-p group (nth 2 old-style) (nth 1 old-style))
+ ;; now search for the parameter
+ (dolist (parameter parameters)
+ (when (and (null found)
+ (listp parameter)
+ (eq classification (nth 0 parameter))
+ (eq check (nth 1 parameter)))
+ (setq found t)))
+ found))
nil))
-(defun spam-group-processor-multiple-p (group processor-info)
- (let* ((classification (nth 0 processor-info))
- (check (nth 1 processor-info))
- (parameters (nth 0 (gnus-parameter-spam-process group)))
- found)
- (dolist (parameter parameters)
- (when (and (null found)
- (listp parameter)
- (eq classification (nth 0 parameter))
- (eq check (nth 1 parameter)))
- (setq found t)))
- found))
-
-(defun spam-group-spam-processor-report-gmane-p (group)
- (spam-group-processor-p group 'gnus-group-spam-exit-processor-report-gmane))
-
-(defun spam-group-spam-processor-report-resend-p (group)
- (spam-group-processor-p group 'gnus-group-spam-exit-processor-report-resend))
-
-(defun spam-group-spam-processor-bogofilter-p (group)
- (spam-group-processor-p group 'gnus-group-spam-exit-processor-bogofilter))
-
-(defun spam-group-spam-processor-blacklist-p (group)
- (spam-group-processor-p group 'gnus-group-spam-exit-processor-blacklist))
-
-(defun spam-group-spam-processor-ifile-p (group)
- (spam-group-processor-p group 'gnus-group-spam-exit-processor-ifile))
-
-(defun spam-group-ham-processor-ifile-p (group)
- (spam-group-processor-p group 'gnus-group-ham-exit-processor-ifile))
-
-(defun spam-group-spam-processor-spamoracle-p (group)
- (spam-group-processor-p group 'gnus-group-spam-exit-processor-spamoracle))
-
-(defun spam-group-spam-processor-crm114-p (group)
- (spam-group-processor-p group 'gnus-group-spam-exit-processor-crm114))
-
-(defun spam-group-ham-processor-bogofilter-p (group)
- (spam-group-processor-p group 'gnus-group-ham-exit-processor-bogofilter))
-
-(defun spam-group-spam-processor-stat-p (group)
- (spam-group-processor-p group 'gnus-group-spam-exit-processor-stat))
-
-(defun spam-group-ham-processor-stat-p (group)
- (spam-group-processor-p group 'gnus-group-ham-exit-processor-stat))
-
-(defun spam-group-ham-processor-whitelist-p (group)
- (spam-group-processor-p group 'gnus-group-ham-exit-processor-whitelist))
-
-(defun spam-group-ham-processor-BBDB-p (group)
- (spam-group-processor-p group 'gnus-group-ham-exit-processor-BBDB))
-
-(defun spam-group-ham-processor-copy-p (group)
- (spam-group-processor-p group 'gnus-group-ham-exit-processor-copy))
-
-(defun spam-group-ham-processor-spamoracle-p (group)
- (spam-group-processor-p group 'gnus-group-ham-exit-processor-spamoracle))
-
-(defun spam-group-ham-processor-crm114-p (group)
- (spam-group-processor-p group 'gnus-group-ham-exit-processor-crm114))
-
(defun spam-report-articles-gmane (n)
"Report the current message as spam via Gmane.
Respects the process/prefix convention."
(gnus-summary-remove-process-mark article)
(spam-report-gmane article)))
-(defun spam-report-articles-resend (n)
+(defun spam-report-articles-resend (n &optional ham)
"Report the current message as spam by resending it.
Respects the process/prefix convention. Also see
-`spam-report-resend-to'."
+`spam-report-resend-to'. Operates as ham when HAM is set."
(interactive "P")
- (let ((articles (gnus-summary-work-articles n)))
- (spam-report-resend articles)
+ (let* ((gp
+ (if ham
+ (gnus-parameter-ham-resend-to gnus-newsgroup-name)
+ (gnus-parameter-spam-resend-to gnus-newsgroup-name)))
+ (spam-report-resend-to (or (car-safe gp)
+ spam-report-resend-to))
+ (articles (gnus-summary-work-articles n)))
+ (spam-report-resend articles ham)
(dolist (article articles)
(gnus-summary-remove-process-mark article))))
(classification (nth 1 processor-param))
(check (nth 2 processor-param)))
(when (and (eq 'spam classification)
- (spam-group-processor-p gnus-newsgroup-name processor))
+ (spam-group-processor-p gnus-newsgroup-name check classification))
(spam-register-routine classification check))))
(unless (and spam-move-spam-nonspam-groups-only
(num (spam-mark-spam-as-expired-and-move-routine group)))
(when (> num 0)
(gnus-message 6
- "%d spam messages are marked as expired and moved it to %s"
- num group))))
+ "%d spam messages are marked as expired%s."
+ num
+ (if group
+ (format " and moved it to %s" group)
+ "")))))
;; now we redo spam-mark-spam-as-expired-and-move-routine to only
;; expire spam, in case the above did not expire them
(let ((num (spam-mark-spam-as-expired-and-move-routine nil)))
(when (> num 0)
(gnus-message 6
- "%d spam messages are markd as expired without moving it"
+ "%d spam messages were marked as expired."
num)))
(when (or (spam-group-ham-contents-p gnus-newsgroup-name)
(classification (nth 1 processor-param))
(check (nth 2 processor-param)))
(when (and (eq 'ham classification)
- (spam-group-processor-p gnus-newsgroup-name processor))
+ (spam-group-processor-p gnus-newsgroup-name check classification))
(spam-register-routine classification check)))))
- (when (spam-group-ham-processor-copy-p gnus-newsgroup-name)
+ (when (spam-group-processor-p gnus-newsgroup-name 'ham 'spam-use-ham-copy)
(let ((num
(spam-ham-copy-routine
(gnus-parameter-ham-process-destination gnus-newsgroup-name))))
(when (> num 0)
- (gnus-message 6 "%d ham messages are copied" num))))
+ (gnus-message 6 "%d ham messages were copied" num))))
;; 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))))
(when (> num 0)
- (gnus-message 6 "%d ham messages are moved from spam group" num)))))
+ (gnus-message 6 "%d ham messages were moved from spam group" num)))))
(setq spam-old-ham-articles nil)
(setq spam-old-spam-articles nil))
(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)))
(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
;; does Gmane support unregistration?
nil
nil)
- (spam-use-resend nil
+ (spam-use-resend spam-report-resend-register-ham-routine
spam-report-resend-register-routine
nil
nil)
gnus-newsgroup-articles
classification)))
;; process them
- (gnus-message 5 "%s %d %s articles as %s using backend %s"
- (if unregister "Unregistering" "Registering")
- (length articles)
- (if specific-articles "specific" "")
- (symbol-name classification)
- (symbol-name check))
- (funcall run-function articles)
- ;; now log all the registrations (or undo them, depending on unregister)
- (dolist (article articles)
- (funcall log-function
- (spam-fetch-field-message-id-fast article)
- 'process
- classification
- check
- gnus-newsgroup-name))))))
+ (when (> (length articles) 0)
+ (gnus-message 5 "%s %d %s articles as %s using backend %s"
+ (if unregister "Unregistering" "Registering")
+ (length articles)
+ (if specific-articles "specific" "")
+ (symbol-name classification)
+ (symbol-name check))
+ (funcall run-function articles)
+ ;; now log all the registrations (or undo them, depending on unregister)
+ (dolist (article articles)
+ (funcall log-function
+ (spam-fetch-field-message-id-fast article)
+ 'process
+ classification
+ check
+ gnus-newsgroup-name)))))))
;;; log a ham- or spam-processor invocation to the registry
(defun spam-log-processing-to-registry (id type classification check group)
(when articles
(apply 'spam-report-gmane articles)))
-(defun spam-report-resend-register-routine (articles)
- (spam-report-resend articles))
+(defun spam-report-resend-register-ham-routine (articles)
+ (spam-report-resend-register-routine articles t))
+
+(defun spam-report-resend-register-routine (articles &optional ham)
+ (let* ((resend-to-gp
+ (if ham
+ (gnus-parameter-ham-resend-to gnus-newsgroup-name)
+ (gnus-parameter-spam-resend-to gnus-newsgroup-name)))
+ (spam-report-resend-to (or (car-safe resend-to-gp)
+ spam-report-resend-to)))
+ (spam-report-resend articles ham)))
\f
;;;; Bogofilter