* elmo-spam.el (elmo-spam-scheme): Add 'sa' as a candidate.
[elisp/wanderlust.git] / elmo / elsp-sa.el
1 ;;; elsp-sa.el --- SpamAssassin support for elmo-spam.
2 ;; Copyright (C) 2004 Yuuichi Teranishi <teranisi@gohome.org>
3
4 ;; Author: Yuuichi Teranishi <teranisi@gohome.org>
5 ;; Keywords: mail, net news, spam
6
7 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
8
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13 ;;
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18 ;;
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23 ;;
24
25 ;;; Commentary:
26 ;;
27
28 ;;; Code:
29 ;;
30 (require 'elmo-spam)
31
32 (defgroup elmo-spam-spamassassin nil
33   "Spam SpamAssassin configuration."
34   :group 'elmo-spam)
35
36 (defcustom elmo-spam-spamassassin-program "spamassassin"
37   "Program name for SpamAssassin."
38   :type '(file :tag "Program name of SpamAssassin.")
39   :group 'elmo-spam-spamassassin)
40
41 (defcustom elmo-spam-spamassassin-learn-program "sa-learn"
42   "Program name for SpamAssassin Learner."
43   :type '(file :tag "Program name of SpamAssassin Learner.")
44   :group 'elmo-spam-spamassassin)
45
46 (defcustom elmo-spam-spamassassin-program-arguments '("-e")
47   "Program argument list for SpamAssassin."
48   :type '(file :tag "Program name of SpamAssassin Learner.")
49   :group 'elmo-spam-spamassassin)
50
51 (defcustom elmo-spam-spamassassin-learn-program-arguments nil
52   "Program argument list for SpamAssassin Learner."
53   :type '(file :tag "Program name of SpamAssassin Learner.")
54   :group 'elmo-spam-spamassassin)
55
56 (defcustom elmo-spamassassin-debug nil
57   "Non-nil to debug elmo spamassassin spam backend."
58   :type 'boolean
59   :group 'elmo-spam-spamassassin)
60
61 (eval-and-compile
62   (luna-define-class elsp-sa (elsp-generic))
63   (luna-define-internal-accessors 'elsp-sa))
64
65 (defun elmo-spamassassin-call (type &rest args)
66   (let ((pair (cond
67                ((eq type 'check)
68                 (cons elmo-spam-spamassassin-program
69                       elmo-spam-spamassassin-program-arguments))
70                ((eq type 'learn)
71                 (cons
72                  elmo-spam-spamassassin-learn-program
73                  elmo-spam-spamassassin-learn-program-arguments))
74                (t (error "Internal error.")))))
75     (apply #'call-process-region
76            (point-min) (point-max)
77            (car pair)
78            nil (if elmo-spamassassin-debug
79                    (get-buffer-create "*Debug ELMO SpamAssassin*"))
80            nil (delq nil (append (cdr pair) args)))))
81
82 (luna-define-method elmo-spam-buffer-spam-p ((processor elsp-sa)
83                                              buffer &optional register)
84   (let ((result (with-current-buffer buffer
85                   (not (eq 0 (elmo-spamassassin-call 'check))))))
86     (when register
87       (if result
88           (elmo-spam-register-spam-buffer processor buffer)
89         (elmo-spam-register-good-buffer processor buffer)))
90     result))
91
92 (luna-define-method elmo-spam-register-spam-buffer ((processor elsp-sa)
93                                                     buffer &optional restore)
94   (with-current-buffer buffer
95     (eq 0 (apply 'elmo-spamassassin-call 'learn
96                  (list (when restore "--forget") "--spam")))))
97
98 (luna-define-method elmo-spam-register-good-buffer ((processor elsp-sa)
99                                                     buffer &optional restore)
100   (with-current-buffer buffer
101     (eq 0 (apply 'elmo-spamassassin-call 'learn
102                  (list (when restore "--forget") "--ham")))))
103
104 (require 'product)
105 (product-provide (provide 'elsp-sa) (require 'elmo-version))
106
107 ;;; elsp-sa.el ends here