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
57 (if elmo-spam-bogofilter-debug "-vv")
59 (if elmo-spam-bogofilter-database-directory
60 (list "-d" elmo-spam-bogofilter-database-directory)))
62 (if elmo-spam-bogofilter-debug "-vv")
64 (if restore (if spam "-N" "-S"))
65 (if elmo-spam-bogofilter-database-directory
66 (list "-d" elmo-spam-bogofilter-database-directory))))
67 "*An alist of options that are used with call bogofilter process.
68 Each element is a list of following:
70 TYPE is a symbol from `classify' or `register'.
71 SEXP is an expression to get options.
72 Must be return a string or list of string."
73 :type '(repeat (cons (choice (const :tag "Classify" classify)
74 (const :tag "Register" register))
76 :group 'elmo-spam-bogofilter)
78 (defcustom elmo-spam-bogofilter-debug nil
79 "Non-nil to debug elmo bogofilter spam backend."
81 :group 'elmo-spam-bogofilter)
85 (luna-define-class elsp-bogofilter (elsp-generic)))
87 (defsubst elmo-spam-bogofilter-call (&optional args)
88 (apply #'call-process-region
89 (point-min) (point-max)
90 elmo-spam-bogofilter-program
91 nil (if elmo-spam-bogofilter-debug
92 (get-buffer-create "*Debug ELMO SPAM Bogofilter*"))
94 (append elmo-spam-bogofilter-args
97 (defmacro elmo-spam-bogofilter-arguments (type)
100 (cdr (assq ,type elmo-spam-bogofilter-arguments-alist)))))
102 (luna-define-method elmo-spam-buffer-spam-p ((processor elsp-bogofilter)
103 buffer &optional register)
104 (with-current-buffer buffer
105 (= 0 (elmo-spam-bogofilter-call
106 (elmo-spam-bogofilter-arguments 'classify)))))
108 (defsubst elsp-bogofilter-register-buffer (buffer spam restore)
109 (with-current-buffer buffer
110 (elmo-spam-bogofilter-call
111 (elmo-spam-bogofilter-arguments 'register))))
113 (luna-define-method elmo-spam-register-spam-buffer ((processor elsp-bogofilter)
114 buffer &optional restore)
115 (elsp-bogofilter-register-buffer buffer t restore))
117 (luna-define-method elmo-spam-register-good-buffer ((processor elsp-bogofilter)
118 buffer &optional restore)
119 (elsp-bogofilter-register-buffer buffer nil restore))
122 (product-provide (provide 'elsp-bogofilter) (require 'elmo-version))
124 ;;; elsp-bogofilter.el ends here