gnus-summary-sort-by-spamicity (bogofilter) (was: Dealing with wordlist mails)

Lars Clausen lc at statsbiblioteket.dk
Thu Jan 29 12:42:41 CET 2004


On Wed, 2004-01-28 at 14:13, Reiner Steib wrote:
> [ Resent to bogofilter list.  My first attempt didn't get thru because
>   I wasn't subscribed to the bogofilter list.  Sorry, if you see this
>   message twice. ]
> 
> On Wed, Jan 28 2004, Lars Clausen wrote:
> 
> > P.S. Has anyone tried to make Gnus sort mails by bogosity?
> 
> See this thread on Ding (Gnus developer list):
> <URL:http://thread.gmane.org/v9fzim72ry.fsf@marauder.physik.uni-ulm.de>.

Since those articles just expired from the gmane server, I'll post my
Bogofilter-adapted version here.  The nnml+Mail:... group should be
replaced with the group your Bogofilter mail ends in.  Please don't ask
me for help on setting this up, I had to fight hard enough to get it to
work myself (hint: string-to-number doesn't like strings like "0.995, ")

(gnus-group-set-parameter "nnml+Mail:mail.bogofilter"
                          'nnmail-extra-headers '(X-Bogosity To
Newsgroups))
(gnus-group-set-parameter "nnml+Mail:mail.bogofilter"
                          'gnus-extra-headers '(X-Bogosity To
Newsgroups))
(gnus-group-set-parameter "nnml+Mail:mail.bogofilter"
                          'gnus-show-threads nil)
(gnus-group-set-parameter "nnml+Mail:mail.bogofilter"
                          'gnus-article-sort-functions
'(gnus-article-sort-by-x-bogosity))

(defun gnus-summary-sort-by-x-bogosity (&optional reverse)
    "Sort the summary buffer by bogosity alphabetically.
Argument REVERSE means reverse order."
    (interactive "P")
    (gnus-summary-sort 'x-bogosity reverse))

(defun spamicity-to-float (string)
  (string-to-number
  (gnus-replace-in-string string
                          ".*spamicity=\\([^,]+\\), .*" "\\1"))
)

(defun gnus-article-sort-by-x-bogosity (h1 h2)
  "Sort articles by score from the X-Bogosity: header."
  (let ((num1 (spamicity-to-float (gnus-extra-header 'X-Bogosity h1)))
        (num2 (spamicity-to-float (gnus-extra-header 'X-Bogosity h2))))
    (< num1 num2)))

-Lars





More information about the Bogofilter mailing list