1 ;;; elsp-bogofilter.el --- Bogofilter support for elmo-spam.
3 ;; Copyright (C) 2003 Hiroya Murata <lapis-lazuli@pop06.odn.ne.jp>
4 ;; Copyright (C) 2003 Yuuichi Teranishi <teranisi@gohome.org>
6 ;; Author: Hiroya Murata <lapis-lazuli@pop06.odn.ne.jp>
7 ;; Keywords: mail, net news, spam
9 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
35 (defgroup elmo-spam-bogofilter nil
36 "Spam bogofilter configuration."
39 (defcustom elmo-spam-bogofilter-program "bogofilter"
40 "*Program name of the Bogofilter."
41 :type '(string :tag "Program name of the bogofilter")
42 :group 'elmo-spam-bogofilter)
44 (defcustom elmo-spam-bogofilter-args nil
45 "*Argument list for bogofilter."
46 :type '(repeat string)
47 :group 'elmo-spam-bogofilter)
49 (defcustom elmo-spam-bogofilter-database-directory nil
50 "*Directory path of the Bogofilter databases."
51 :type '(choice (directory :tag "Location of the Bogofilter database directory")
52 (const :tag "Use the default"))
53 :group 'elmo-spam-bogofilter)
55 (defcustom elmo-spam-bogofilter-arguments-alist
56 '((classify . ("-v" "-2"
58 (if elmo-spam-bogofilter-database-directory
59 (list "-d" elmo-spam-bogofilter-database-directory))))
62 (if restore (if spam "-N" "-S"))
63 (if elmo-spam-bogofilter-database-directory
64 (list "-d" elmo-spam-bogofilter-database-directory)))))
65 "*An alist of options that are used with call bogofilter process.
66 Each element is a list of following:
68 TYPE is a symbol from `classify' or `register'.
69 LIST-EXP is an expression to get list of options."
70 :type '(repeat (cons (choice (const :tag "Classify" classify)
71 (const :tag "Register" register))
73 :group 'elmo-spam-bogofilter)
75 (defcustom elmo-spam-bogofilter-debug nil
76 "Non-nil to debug elmo bogofilter spam backend."
78 :group 'elmo-spam-bogofilter)
82 (luna-define-class elsp-bogofilter (elsp-generic)))
84 (defsubst elmo-spam-bogofilter-call (&rest args)
85 (apply #'call-process-region
86 (point-min) (point-max)
87 elmo-spam-bogofilter-program
88 nil (if elmo-spam-bogofilter-debug
89 (get-buffer-create "*Debug ELMO SPAM Bogofilter*"))
91 (delq nil (append elmo-spam-bogofilter-args
92 (elmo-flatten args)))))
94 (defmacro elmo-spam-bogofilter-arguments (type)
96 (cdr (assq ,type elmo-spam-bogofilter-arguments-alist))))
98 (luna-define-method elmo-spam-buffer-spam-p ((processor elsp-bogofilter)
99 buffer &optional register)
100 (with-current-buffer buffer
101 (= 0 (elmo-spam-bogofilter-call
102 (elmo-spam-bogofilter-arguments 'classify)))))
104 (defsubst elsp-bogofilter-register-buffer (buffer spam restore)
105 (with-current-buffer buffer
106 (elmo-spam-bogofilter-call
107 (elmo-spam-bogofilter-arguments 'register))))
109 (luna-define-method elmo-spam-register-spam-buffer ((processor elsp-bogofilter)
110 buffer &optional restore)
111 (elsp-bogofilter-register-buffer buffer t restore))
113 (luna-define-method elmo-spam-register-good-buffer ((processor elsp-bogofilter)
114 buffer &optional restore)
115 (elsp-bogofilter-register-buffer buffer nil restore))
118 (product-provide (provide 'elsp-bogofilter) (require 'elmo-version))
120 ;;; elsp-bogofilter.el ends here