info-gnus-english
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to use the new code in spam.el?


From: John Wiegley
Subject: Re: How to use the new code in spam.el?
Date: Sun, 08 Jul 2012 12:44:31 -0500
User-agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.1 (darwin)

>>>>> Tassilo Horn <tassilo@member.fsf.org> writes:

>> In Gnus, I want to be able to mark spam in INBOX with $, and ham in
>> mail.spam with M-u, and have each moved to the right place.

> I do exactly that.  Here're the relevant settings:

Your setting only move Spam around, they don't truly process it.  I want
ham/spam sent to sa-learn, and spam sent to spamassassin -r.

Here's what I had to do: In my gnus-parameters, I have this:

 ("INBOX"
  (total-expire . t)
  (expiry-wait . 14)
  (expiry-target . "mail.archive")
  (spam-process-destination . "mail.spam")
  (spam-contents gnus-group-spam-classification-ham)
  (spam-process
   ((spam spam-use-spamassassin)
    (ham spam-use-spamassassin))))

 ("mail\\.spam"
  (gnus-article-sort-functions gnus-article-sort-by-chars)
  (ham-process-destination . "INBOX")
  (spam-contents gnus-group-spam-classification-spam)
  (spam-process
   ((spam spam-use-spamassassin)
    (ham spam-use-spamassassin))))

And then I had to enrich the definition of
spam-spamassassin-register-with-sa-learn, since there is currently no way to
have Gnus report Spam to Razor.  Also note that this version is fully
asynchronous, since there's no reason for me to have to wait on spam
reporting:

(require 'spam)
(require 'async)

(defun spam-spamassassin-register-with-sa-learn (articles spam
                                                          &optional unregister)
  "Register articles with spamassassin's sa-learn as spam or non-spam."
  (if articles
      (let ((action (if unregister spam-sa-learn-unregister-switch
                      (if spam spam-sa-learn-spam-switch
                        spam-sa-learn-ham-switch)))
            (summary-buffer-name (buffer-name)))
        (with-temp-buffer
          ;; group the articles into mbox format
          (dolist (article articles)
            (let (article-string)
              (with-current-buffer summary-buffer-name
                (setq article-string (spam-get-article-as-string article)))
              (when (stringp article-string)
                ;; mbox separator
                (insert (concat "From nobody " (current-time-string) "\n"))
                (insert article-string)
                (insert "\n"))))
          ;; call sa-learn on all messages at the same time, and also report
          ;; them as SPAM to the Internet
          (async-start
           `(lambda ()
              (with-temp-buffer
                (insert ,(buffer-substring-no-properties
                          (point-min) (point-max)))
                (call-process-region (point-min) (point-max)
                                     ,spam-sa-learn-program
                                     nil nil nil "--mbox"
                                     ,@(if spam-sa-learn-rebuild
                                           (list action)
                                         (list "--no-rebuild" action)))
                (if ,spam
                    (call-process-region (point-min) (point-max)
                                         ,(executable-find "spamassassin-5.12")
                                         nil nil nil "--mbox" "-r"))))
           `(lambda (&optional ignore)
              (message  "Finished learning messsages as %s"
                        ,(if spam "spam" "ham"))))))))

Do note that I have a hard-coded executable name in that function.  Change
"spamassassin-5.12" to just "spamassassin", for your system.

John




reply via email to

[Prev in Thread] Current Thread [Next in Thread]