1 ;;; elmo-spam.el --- Spam filtering interface to processor.
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.
33 (eval-when-compile (require 'cl))
39 (defgroup elmo-spam nil
40 "Spam configuration for wanderlust."
43 (defcustom elmo-spam-scheme nil
44 "*Scheme of spam processor implementation. "
45 :type '(choice (const :tag "none" nil)
46 (const :tag "Bogofilter" bogofilter)
47 (const :tag "Spamfilter" spamfilter))
51 (luna-define-class elsp-generic ()))
54 (luna-define-generic elmo-spam-buffer-spam-p (processor buffer
56 "Return non-nil if contents of BUFFER is spam.
57 PROCESSOR is spam processor structure.
58 If optional augument REGISTER is non-nil,
59 register according to the classification.")
61 (luna-define-generic elmo-spam-register-spam-buffer (processor
64 "Register contents of BUFFER as spam.
65 PROCESSOR is spam processor structure.
66 If optional argument RESTORE is non-nil, unregister from non-spam list.")
68 (luna-define-generic elmo-spam-register-good-buffer (processor
71 "Register contents of BUFFER as non-spam.
72 PROCESSOR is spam processor structure.
73 If optional argument RESTORE is non-nil, unregister from spam list.")
76 (luna-define-generic elmo-spam-modified-p (processor)
77 "Return non-nil if status of PROCESSOR is modified.")
79 (luna-define-generic elmo-spam-save-status (processor)
80 "Save status of the PROCESSOR.")
82 (luna-define-generic elmo-spam-message-spam-p (processor folder number
84 "Return non-nil if the message in the FOLDER with NUMBER is spam.
85 PROCESSOR is spam processor structure.
86 If optional augument REGISTER is non-nil,
87 register according to the classification.")
89 (luna-define-generic elmo-spam-list-spam-messages (processor
90 folder &optional numbers)
91 "Return a list of message numbers which is gussed spam.
92 PROCESSOR is spam processor structure.
93 FOLDER is the ELMO folder structure.
94 If optional argument NUMBERS is specified and is a list of message numbers,
95 messages are searched from the list.")
97 (luna-define-generic elmo-spam-register-spam-messages (processor
101 "Register contents of messages as spam.
102 PROCESSOR is spam processor structure.
103 FOLDER is the ELMO folder structure.
104 If optional argument NUMBERS is specified and is a list of message numbers,
105 messages are searched from the list.
106 If optional argument RESTORE is non-nil, unregister from non-spam list.")
108 (luna-define-generic elmo-spam-register-good-messages (processor
112 "Register contents of messages as non spam.
113 PROCESSOR is spam processor structure.
114 FOLDER is the ELMO folder structure.
115 If optional argument NUMBERS is specified and is a list of message numbers,
116 messages are searched from the list.
117 If optional argument RESTORE is non-nil, unregister from spam list.")
120 (defun elmo-spam-message-fetch (folder number)
121 (let (elmo-message-fetch-threshold)
124 (elmo-find-fetch-strategy folder
125 (elmo-message-entity folder number))
126 nil (current-buffer) 'unread)))
129 (luna-define-method elmo-spam-message-spam-p ((processor elsp-generic)
130 folder number &optional register)
132 (elmo-spam-message-fetch folder number)
133 (elmo-spam-buffer-spam-p processor (current-buffer) register)))
135 (luna-define-method elmo-spam-list-spam-messages ((processor elsp-generic)
136 folder &optional numbers)
137 (let ((numbers (or numbers (elmo-folder-list-messages folder t t)))
139 (dolist (number numbers)
140 (when (elmo-spam-message-spam-p processor folder number)
141 (setq spam-list (cons number spam-list)))
142 (elmo-progress-notify 'elmo-spam-check-spam))
143 (nreverse spam-list)))
145 (luna-define-method elmo-spam-register-spam-messages ((processor elsp-generic)
149 (let ((numbers (or numbers (elmo-folder-list-messages folder t t))))
151 (buffer-disable-undo (current-buffer))
152 (dolist (number numbers)
154 (elmo-spam-message-fetch folder number)
155 (elmo-spam-register-spam-buffer processor (current-buffer) restore)
156 (elmo-progress-notify 'elmo-spam-register)))))
158 (luna-define-method elmo-spam-register-good-messages ((processor elsp-generic)
162 (let ((numbers (or numbers (elmo-folder-list-messages folder t t))))
164 (buffer-disable-undo (current-buffer))
165 (dolist (number numbers)
167 (elmo-spam-message-fetch folder number)
168 (elmo-spam-register-good-buffer processor (current-buffer) restore)
169 (elmo-progress-notify 'elmo-spam-register)))))
171 (provide 'elsp-generic)
173 (defvar elmo-spam-processor-internal nil)
175 (defun elmo-spam-processor (&optional if-exists)
176 (or elmo-spam-processor-internal
178 (let* ((scheme (or elmo-spam-scheme 'generic))
179 (class (intern (format "elsp-%s" scheme))))
181 (setq elmo-spam-processor-internal
182 (luna-make-entity class))))))
185 (product-provide (provide 'elmo-spam) (require 'elmo-version))
187 ;;; elmo-spam.el ends here