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 . ((if register "-u")
57 (if elmo-spam-bogofilter-database-directory
58 (list "-d" elmo-spam-bogofilter-database-directory))))
59 (register . ((if spam "-s" "-n")
60 (if restore (if spam "-N" "-S"))
61 (if elmo-spam-bogofilter-database-directory
62 (list "-d" elmo-spam-bogofilter-database-directory)))))
63 "*An alist of options that are used with call bogofilter process.
64 Each element is a list of following:
66 TYPE is a symbol from `classify' or `register'.
67 LIST-EXP is an expression to get list of options."
68 :type '(repeat (cons (choice (const :tag "Classify" classify)
69 (const :tag "Register" register))
71 :group 'elmo-spam-bogofilter)
73 (defcustom elmo-spam-bogofilter-debug nil
74 "Non-nil to debug elmo bogofilter spam backend."
76 :group 'elmo-spam-bogofilter)
80 (luna-define-class elsp-bogofilter (elsp-generic)))
82 (defsubst elmo-spam-bogofilter-call (&rest args)
83 (apply #'call-process-region
84 (point-min) (point-max)
85 elmo-spam-bogofilter-program
86 nil (if elmo-spam-bogofilter-debug
87 (get-buffer-create "*Debug ELMO SPAM Bogofilter*"))
89 (delq nil (append elmo-spam-bogofilter-args
90 (elmo-flatten args)))))
92 (defmacro elmo-spam-bogofilter-arguments (type)
94 (cdr (assq ,type elmo-spam-bogofilter-arguments-alist))))
96 (luna-define-method elmo-spam-buffer-spam-p ((processor elsp-bogofilter)
97 buffer &optional register)
98 (with-current-buffer buffer
99 (= 0 (elmo-spam-bogofilter-call
100 (elmo-spam-bogofilter-arguments 'classify)))))
102 (defsubst elsp-bogofilter-register-buffer (buffer spam restore)
103 (with-current-buffer buffer
104 (elmo-spam-bogofilter-call
105 (elmo-spam-bogofilter-arguments 'register))))
107 (luna-define-method elmo-spam-register-spam-buffer ((processor elsp-bogofilter)
108 buffer &optional restore)
109 (elsp-bogofilter-register-buffer buffer t restore))
111 (luna-define-method elmo-spam-register-good-buffer ((processor elsp-bogofilter)
112 buffer &optional restore)
113 (elsp-bogofilter-register-buffer buffer nil restore))
116 (product-provide (provide 'elsp-bogofilter) (require 'elmo-version))
118 ;;; elsp-bogofilter.el ends here