~ubuntu-branches/ubuntu/saucy/wl/saucy-proposed

« back to all changes in this revision

Viewing changes to elmo/elsp-bsfilter.el

  • Committer: Bazaar Package Importer
  • Author(s): Tatsuya Kinoshita
  • Date: 2007-01-02 21:08:54 UTC
  • mfrom: (3.1.3 edgy)
  • Revision ID: james.westby@ubuntu.com-20070102210854-nw929130dlxgi6q3
Tags: 2.14.0-4
elmo/elmo-imap4.el: Fix "IMAP error: No `OK' response from server",
patch from upstream CVS version. (closes: #405284)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;;; elsp-bsfilter.el --- Bsfilter support for elmo-spam.
 
2
 
 
3
;; Copyright (C) 2004 Hiroya Murata <lapis-lazuli@pop06.odn.ne.jp>
 
4
;; Copyright (C) 2004 Yuuichi Teranishi <teranisi@gohome.org>
 
5
 
 
6
;; Author: Hiroya Murata <lapis-lazuli@pop06.odn.ne.jp>
 
7
;; Keywords: mail, net news, spam
 
8
 
 
9
;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
 
10
 
 
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)
 
14
;; any later version.
 
15
;;
 
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.
 
20
;;
 
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.
 
25
;;
 
26
 
 
27
;;; Commentary:
 
28
;;
 
29
 
 
30
;;; Code:
 
31
;;
 
32
(require 'elmo-spam)
 
33
(require 'luna)
 
34
 
 
35
(defgroup elmo-spam-bsfilter nil
 
36
  "Spam bsfilter configuration."
 
37
  :group 'elmo-spam)
 
38
 
 
39
(defcustom elmo-spam-bsfilter-shell-program "ruby"
 
40
  "*"
 
41
  :type 'string
 
42
  :group 'elmo-spam-bsfilter)
 
43
 
 
44
(defcustom elmo-spam-bsfilter-shell-switch nil
 
45
  "*"
 
46
  :type 'string
 
47
  :group 'elmo-spam-bsfilter)
 
48
 
 
49
(defcustom elmo-spam-bsfilter-program (exec-installed-p "bsfilter")
 
50
  "*Program name of the Bsfilter."
 
51
  :type '(string :tag "Program name of the bsfilter")
 
52
  :group 'elmo-spam-bsfilter)
 
53
 
 
54
(defcustom elmo-spam-bsfilter-args nil
 
55
  "*Argument list for bsfilter."
 
56
  :type '(repeat string)
 
57
  :group 'elmo-spam-bsfilter)
 
58
 
 
59
(defcustom elmo-spam-bsfilter-update-switch "--synchronous-auto-update"
 
60
  "*The switch that Bsfilter uses to update database with classify."
 
61
  :type 'string
 
62
  :group 'elmo-spam-bsfilter)
 
63
 
 
64
(defcustom elmo-spam-bsfilter-database-directory nil
 
65
  "*Directory path of the Bsfilter databases."
 
66
  :type '(choice (directory :tag "Location of the Bsfilter database directory")
 
67
                 (const :tag "Use the default"))
 
68
  :group 'elmo-spam-bsfilter)
 
69
 
 
70
(defcustom elmo-spam-bsfilter-debug nil
 
71
  "Non-nil to debug elmo bsfilter spam backend."
 
72
  :type 'boolean
 
73
  :group 'elmo-spam-bsfilter-debug)
 
74
 
 
75
(eval-and-compile
 
76
  (luna-define-class elsp-bsfilter (elsp-generic)))
 
77
 
 
78
(defsubst elsp-bsfilter-call-bsfilter (&rest args)
 
79
  (apply #'call-process-region
 
80
         (point-min) (point-max)
 
81
         elmo-spam-bsfilter-shell-program
 
82
         nil (if elmo-spam-bsfilter-debug
 
83
                 (get-buffer-create "*Debug ELMO Bsfilter*"))
 
84
         nil (delq nil
 
85
                   (append (list elmo-spam-bsfilter-shell-switch
 
86
                                 elmo-spam-bsfilter-program)
 
87
                           elmo-spam-bsfilter-args
 
88
                           (elmo-flatten args)))))
 
89
 
 
90
(luna-define-method elmo-spam-buffer-spam-p ((processor elsp-bsfilter)
 
91
                                             buffer &optional register)
 
92
  (with-current-buffer buffer
 
93
    (= 0 (elsp-bsfilter-call-bsfilter
 
94
          (if register elmo-spam-bsfilter-update-switch)
 
95
          (if elmo-spam-bsfilter-database-directory
 
96
              (list "--homedir" elmo-spam-bsfilter-database-directory))))))
 
97
 
 
98
(defsubst elsp-bsfilter-register-buffer (buffer spam restore)
 
99
  (with-current-buffer buffer
 
100
    (elsp-bsfilter-call-bsfilter
 
101
     "--update"
 
102
     (if elmo-spam-bsfilter-database-directory
 
103
         (list "--homedir" elmo-spam-bsfilter-database-directory))
 
104
     (if restore (if spam "--sub-clean" "--sub-spam"))
 
105
     (if spam "--add-spam" "--add-clean"))))
 
106
 
 
107
(luna-define-method elmo-spam-register-spam-buffer ((processor elsp-bsfilter)
 
108
                                                    buffer &optional restore)
 
109
  (elsp-bsfilter-register-buffer buffer t restore))
 
110
 
 
111
(luna-define-method elmo-spam-register-good-buffer ((processor elsp-bsfilter)
 
112
                                                    buffer &optional restore)
 
113
  (elsp-bsfilter-register-buffer buffer nil restore))
 
114
 
 
115
(require 'product)
 
116
(product-provide (provide 'elsp-bsfilter) (require 'elmo-version))
 
117
 
 
118
;;; elsp-bsfilter.el ends here