Emacs crashes with segmentation fault when mime-view tries to display malformed
[more-wl.git] / elmo / elsp-spamoracle.el
blob1c57b10a334849fb97ccca7499457c7abf9f0f53
1 ;;; elsp-spamoracle.el --- SpamOracle support for elmo-spam.
3 ;; Copyright (C) 2004 Daishi Kato <daishi@axlight.com>
5 ;; Author: Daishi Kato <daishi@axlight.com>
6 ;; Keywords: mail, net news, spam
8 ;; This file is part of Wanderlust (Yet Another Message Interface on Emacsen).
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
26 ;;; Commentary:
29 ;;; Code:
31 (require 'elmo-spam)
33 (defgroup elmo-spam-spamoracle nil
34 "Spam spamoracle configuration."
35 :group 'elmo-spam)
37 (defcustom elmo-spam-spamoracle-program "spamoracle"
38 "Program name of the SpamOracle."
39 :type '(string :tag "Program name of the SpamOracle")
40 :group 'elmo-spam-spamoracle)
42 (defcustom elmo-spam-spamoracle-config-filename nil
43 "Filename of the SpamOracle config."
44 :type '(file :tag "Filename of the SpamOracle config")
45 :group 'elmo-spam-spamoracle)
47 (defcustom elmo-spam-spamoracle-database-filename
48 (expand-file-name ".spamoracle.db" elmo-msgdb-directory)
49 "Filename of the SpamOracle database."
50 :type '(file :tag "Filename of the SpamOracle database")
51 :group 'elmo-spam-spamoracle)
53 (defcustom elmo-spam-spamoracle-spam-header-regexp "^X-Spam: yes;"
54 "Regexp of the SpamOracle spam header."
55 :type '(string :tag "Regexp of the SpamOracle spam header")
56 :group 'elmo-spam-spamoracle)
58 (eval-and-compile
59 (luna-define-class elsp-spamoracle (elsp-generic)))
61 (defsubst elmo-spam-spamoracle-call (type)
62 (let ((args (cond
63 ((eq type 'check)
64 (list "mark"))
65 ((eq type 'add-spam)
66 (list "add" "-v" "-spam"))
67 ((eq type 'add-good)
68 (list "add" "-v" "-good"))))
69 (output-buffer (get-buffer-create "*Output ELMO SpamOracle*")))
70 (with-current-buffer output-buffer
71 (erase-buffer))
72 (apply #'call-process-region
73 (point-min) (point-max)
74 elmo-spam-spamoracle-program
75 nil output-buffer
76 nil (delq nil
77 (append (if elmo-spam-spamoracle-config-filename
78 (list "-config"
79 elmo-spam-spamoracle-config-filename))
80 (if elmo-spam-spamoracle-database-filename
81 (list "-f"
82 elmo-spam-spamoracle-database-filename))
83 args)))
84 (if (eq type 'check)
85 (with-current-buffer output-buffer
86 (goto-char (point-min))
87 (let ((body-point (re-search-forward "^$" nil t)))
88 (goto-char (point-min))
89 (re-search-forward elmo-spam-spamoracle-spam-header-regexp
90 body-point t)))
91 t)))
93 (luna-define-method elmo-spam-buffer-spam-p ((processor elsp-spamoracle)
94 buffer &optional register)
95 (let ((result (with-current-buffer buffer
96 (elmo-spam-spamoracle-call 'check))))
97 (when register
98 (if result
99 (elmo-spam-register-spam-buffer processor buffer)
100 (elmo-spam-register-good-buffer processor buffer)))
101 result))
103 (luna-define-method elmo-spam-register-spam-buffer ((processor elsp-spamoracle)
104 buffer &optional restore)
105 (with-current-buffer buffer
106 (elmo-spam-spamoracle-call 'add-spam)))
108 (luna-define-method elmo-spam-register-good-buffer ((processor elsp-spamoracle)
109 buffer &optional restore)
110 (with-current-buffer buffer
111 (elmo-spam-spamoracle-call 'add-good)))
113 (require 'product)
114 (product-provide (provide 'elsp-spamoracle) (require 'elmo-version))
116 ;;; elsp-spamoracle.el ends here