vm-bogofilter for use with Emacs VM and POP spool files

Olivier Cappe comcap at free.fr
Wed Apr 30 17:48:30 CEST 2003


Dear bogopeople,

Here is something which could be useful for those using Emacs VM to read their
mails. Note that compared to the original code of vm-spamassassin.el by Markus
Mohnen which I adapted, I suppressed the parts that deleted the tagged spam: For
bogofilter, it is important to keep the spam messages (detected or not) for the
training process. vm-bogofilter.el just passes the incoming emails through
bogofilter (when you read your mail with Emacs VM). What is done next is up to
you (although an example of the way I am using it is provided).

This file is intended for people who read their mail via POP and cannot (or
don't want to) use fetchmail. In all other cases, it is recommended to call
bogofilter using procmail which will be much faster than the solution above.

I am leaving a copy of this at http://comcap.free.fr/vm-bogofilter.html



;;; vm-bogofilter.el --- Calls the bogofilter spam filter from VM

;; Author:  Olivier Cappe, "comcap $at free $dot fr"
;; Version: 1.0
;; Date:    April 25, 2003 

;; Adapted from vm-spamassassin.el by Markus Mohnen

;; This file is part of nothing.

;;; This package invokes bogofilter, a mail filter to identify spam,
;;; from within VM.

;;; Requirements:
;;
;;  You need the external program formail, which is part of procmail.

;;; Usage:
;;
;;  Whenever you get new mail, bogofilter will be invoked on them. The mails
;;  are then tagged using the X-Bogosity header and no other action is
;;  performed.

;;; Installation:
;;
;;  Put this file on your Emacs-Lisp load path and add the following into your
;;  ~/.vm startup file
;;    (require 'vm-bogofilter)
;;
;;  If you want tagged mails to be auto archived each time you receive mail,
;;  add the following to your .vm file:
;;    (setq vm-auto-folder-alist '(("^X-Bogosity:" ("Yes" . "~/mail/Spam"))))
;;    (setq vm-delete-after-archiving t)
;;    (add-hook 'vm-arrived-messages-hook 'vm-auto-archive-messages)

;;; Code:

(eval-when-compile (require 'vm))

;;; Customisation:

(defgroup vm-bogofilter nil
  "VM Spam Filter Options"
  :group 'vm)

(defcustom vm-bogofilter-program "bogofilter"
  "*Name of the bogofilter program."
  :group 'vm-bogofilter
  :type 'string)

(defcustom vm-bogofilter-program-options "-p"
  "*Options for the bogofilter program. The -p option (passthrough) is REQUIRED.
 Add -u if you want to update the database after each classification."
  :group 'vm-bogofilter
  :type 'string)

(defcustom vm-bogofilter-formail-program "formail"
  "*Name of the program used to split a sequence of mails."
  :group 'vm-bogofilter
  :type 'string)

(defcustom vm-bogofilter-formail-program-options "-s"
  "*Options for the 'vm-bogofilter-formail-program'." 
  :group 'vm-bogofilter
  :type 'string)

(defun vm-bogofilter-arrived-message ()
  "The function used to do the actual filtering. It is used as a value for
vm-retrieved-spooled-mail-hook."
  (save-excursion
    (vm-save-restriction
     (let ((tail-cons (vm-last vm-message-list))
	   (buffer-read-only nil))
       (widen)
       (if (null tail-cons)
	   (goto-char (point-min))
	 (goto-char (vm-text-end-of (car tail-cons)))
	 (forward-line)
	 )
       (message "Filtering new mails... ")
       (call-process-region (point) (point-max)
			    (or shell-file-name "sh")
			    t t nil shell-command-switch
			    (concat vm-bogofilter-formail-program " "
				    vm-bogofilter-formail-program-options " "
				    vm-bogofilter-program " "
				    vm-bogofilter-program-options))
       (message "Filtering new mails... done")
       )
     )
    )
  )

;;; Hooking into VM

(add-hook 'vm-retrieved-spooled-mail-hook 'vm-bogofilter-arrived-message)

(provide 'vm-bogofilter)

;;; vm-bogofilter.el ends here





More information about the Bogofilter mailing list