annotate lisp/mail/rmail-spam-filter.el @ 89957:c08afac24467

Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-26 Merge from emacs--cvs-trunk--0 Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-466 - miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-470 Update from CVS
author Miles Bader <miles@gnu.org>
date Wed, 28 Jul 2004 07:05:52 +0000
parents 68c22ea6027c
children b637c617432f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
1 ;;; rmail-spam-filter.el --- spam filter for rmail, the emacs mail reader.
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
2
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
3 ;; Copyright (C) 2002
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
4 ;; Free Software Foundation, Inc.
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
5 ;; Keywords: email, spam, filter, rmail
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
6 ;; Author: Eli Tziperman <eli AT deas.harvard.edu>
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
7
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
9
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
13 ;; any later version.
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
14
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
18 ;; GNU General Public License for more details.
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
19
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
24
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
25 ;;; Commentary:
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
26 ;;; -----------
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
27
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
28 ;;; Automatically recognize and delete junk email before it is
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
29 ;;; displayed in rmail/rmail-summary. Spam emails are defined by
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
30 ;;; specifying one or more of the sender, subject and contents.
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
31 ;;; URL: http://www.weizmann.ac.il/~eli/Downloads/rmail-spam-filter/
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
32
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
33 ;;; Usage:
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
34 ;;; ------
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
35
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
36 ;;; put in your .emacs:
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
37
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
38 ;;; (load "rmail-spam-filter.el")
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
39
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
40 ;;; and use customize (in rmail-spam-filter group) to:
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
41
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
42 ;;; (*) turn on the variable rmail-use-spam-filter,
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
43
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
44 ;;; (*) specify in variable rsf-definitions-alist what sender,
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
45 ;;; subject and contents make an email be considered spam.
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
46
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
47 ;;; in addition, you may:
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
48
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
49 ;;; (*) Block future mail with the subject or sender of a message
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
50 ;;; while reading it in RMAIL: just click on the "Spam" item on the
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
51 ;;; menubar, and add the subject or sender to the list of spam
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
52 ;;; definitions using the mouse and the appropriate menu item. You
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
53 ;;; need to later also save the list of spam definitions using the
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
54 ;;; same menu item, or alternatively, see variable
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
55 ;;; `rsf-autosave-newly-added-definitions'.
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
56
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
57 ;;; (*) specify if blind-cc'ed mail (no "To:" header field) is to be
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
58 ;;; treated as spam (variable rsf-no-blind-cc; Thanks to Ethan
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
59 ;;; Brown <ethan@gso.saic.com> for this).
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
60
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
61 ;;; (*) specify if rmail-spam-filter should ignore case of spam
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
62 ;;; definitions (variable rsf-ignore-case; Thanks to
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
63 ;;; Ethan Brown <ethan@gso.saic.com> for the suggestion).
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
64
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
65 ;;; (*) Specify a "white-list" of trusted senders. If any
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
66 ;;; rsf-white-list string matches a substring of the "From"
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
67 ;;; header, the message is flagged as a valid, non-spam message (Ethan
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
68 ;;; Brown <ethan@gso.saic.com>).
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
69
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
70 ;;; (*) rmail-spam-filter is best used with a general purpose spam
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
71 ;;; filter such as the procmail-based http://www.spambouncer.org/.
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
72 ;;; Spambouncer is set to only mark messages as spam/blocked/bulk/OK
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
73 ;;; via special headers, and these headers may then be defined in
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
74 ;;; rmail-spam-filter such that the spam is rejected by
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
75 ;;; rmail-spam-filter itself.
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
76
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
77 ;;; (*) rmail spam filter also works with bbdb to prevent spam senders
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
78 ;;; from entering into the .bbdb file. See variable
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
79 ;;; "rsf-auto-delete-spam-bbdb-entries". This is done
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
80 ;;; in two ways: (a) bbdb is made not to auto-create entries for
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
81 ;;; messages that are deleted by the rmail-spam-filter, (b) when a
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
82 ;;; message is deleted in rmail, the user is offered to delete the
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
83 ;;; sender's bbdb entry as well _if_ it was created at the same day.
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
84
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
85 (require 'rmail)
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
86 (if (> emacs-major-version 20)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
87 (require 'rmailsum)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
88 (if (not (fboundp 'rmail-make-summary-line)) (load-library "rmailsum")))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
89
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
90 ;; For find-if and other cool common lisp functions we may want to use.
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
91 (eval-when-compile
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
92 (require 'cl))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
93
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
94 (defgroup rmail-spam-filter nil
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
95 "Spam filter for RMAIL, the mail reader for Emacs."
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
96 :group 'rmail)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
97
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
98 (defcustom rmail-use-spam-filter nil
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
99 "*Non-nil to activate the rmail spam filter.
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
100 Specify `rsf-definitions-alist' to define what you consider spam
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
101 emails."
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
102 :type 'boolean
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
103 :group 'rmail-spam-filter )
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
104
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
105 (defcustom rsf-file "~/XRMAIL-SPAM"
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
106 "*Name of rmail file for optionally saving some of the spam.
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
107 Spam may be either just deleted, or saved in a separate spam file to
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
108 be looked at at a later time. Whether the spam is just deleted or
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
109 also saved in a separete spam file is specified for each definition of
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
110 spam, as one of the fields of `rsf-definitions-alist'"
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
111 :type 'string
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
112 :group 'rmail-spam-filter )
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
113
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
114 (defcustom rsf-no-blind-cc nil
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
115 "*Non-nil to treat blind CC (no To: header) as spam."
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
116 :type 'boolean
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
117 :group 'rmail-spam-filter )
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
118
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
119 (defcustom rsf-ignore-case nil
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
120 "*Non-nil to ignore case in `rsf-definitions-alist'."
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
121 :type 'boolean
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
122 :group 'rmail-spam-filter )
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
123
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
124 (defcustom rsf-beep nil
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
125 "*Non-nil to beep if spam is found."
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
126 :type 'boolean
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
127 :group 'rmail-spam-filter )
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
128
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
129 (defcustom rsf-sleep-after-message 2.0
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
130 "*Seconds to wait after display of message that spam was found."
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
131 :type 'number
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
132 :group 'rmail-spam-filter )
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
133
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
134 (defcustom rsf-min-region-to-spam-list 7
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
135 "*User may highlight a region in an incomming message and use
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
136 the menubar to add this region to the spam definitions. This
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
137 variable specifies the minimum size of region that may be added
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
138 to spam list, to avoid accidentally adding a too short region
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
139 which would result in false positive identification of spam
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
140 messages."
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
141 :type 'integer
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
142 :group 'rmail-spam-filter )
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
143
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
144 (defcustom rsf-auto-delete-spam-bbdb-entries nil
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
145 "*Non-nil to make sure no entries are made in bbdb for spam emails.
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
146 This is done in two ways: (1) bbdb is made not to auto-create entries
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
147 for messages that are deleted by the `rmail-spam-filter', (2) when a
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
148 message is deleted in rmail, the user is offered to delete the
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
149 sender's bbdb entry as well if it was created at the same day. Note
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
150 that Emacs needs to be restarted after setting this option for it to
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
151 take an effect."
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
152 :type 'boolean
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
153 :group 'rmail-spam-filter )
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
154
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
155 (defcustom rsf-autosave-newly-added-definitions nil
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
156 "*Non-nil to auto save new spam entries.
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
157 New entries entered via the spam menu bar item are then saved to
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
158 customization file immediately after being added via the menu bar, and
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
159 do not require explicitly saving the file after adding the new
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
160 entries."
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
161 :type 'boolean
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
162 :group 'rmail-spam-filter )
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
163
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
164 (defcustom rsf-white-list nil
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
165 "*List of strings to identify valid senders.
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
166 If any rsf-white-list string matches a substring of the 'From'
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
167 header, the message is flagged as a valid, non-spam message. Example:
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
168 If your domain is emacs.com then including 'emacs.com' in your
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
169 rsf-white-list would flag all mail from your colleagues as
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
170 valid."
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
171 :type '(repeat string)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
172 :group 'rmail-spam-filter )
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
173
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
174 (defcustom rsf-definitions-alist nil
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
175 "*Alist matching strings defining what messages are considered spam.
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
176 Each definition may contain specifications of one or more of the
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
177 elements {subject, sender, recipients or contents}, as well as a
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
178 definition of what to do with the spam (action item). A spam e-mail
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
179 is defined as one that fits all of the specified elements of any one
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
180 of the spam definitions. The strings that specify spam subject,
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
181 sender, etc, may be regexp. For example, to specify that the subject
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
182 may be either 'this is spam' or 'another spam', use the regexp: 'this
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
183 is spam\\|another spam' (without the single quotes). To specify that
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
184 if the contents contain both this and that the message is spam,
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
185 specify 'this\\&that' in the appropriate spam definition field."
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
186 :type '(repeat
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
187 (list :format "%v"
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
188 (cons :format "%v" :value (from . "")
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
189 (const :format "" from)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
190 (string :tag "From" ""))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
191 (cons :format "%v" :value (to . "")
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
192 (const :format "" to)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
193 (string :tag "To" ""))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
194 (cons :format "%v" :value (subject . "")
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
195 (const :format "" subject)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
196 (string :tag "Subject" ""))
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
197 (cons :format "%v" :value (content-type . "")
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
198 (const :format "" content-type)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
199 (string :tag "Content-Type" ""))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
200 (cons :format "%v" :value (contents . "")
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
201 (const :format "" contents)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
202 (string :tag "Contents" ""))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
203 (cons :format "%v" :value (action . output-and-delete)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
204 (const :format "" action)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
205 (choice :tag "Action selection"
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
206 (const :tag "output to spam folder and delete" output-and-delete)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
207 (const :tag "delete spam" delete-spam)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
208 ))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
209 ))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
210 :group 'rmail-spam-filter)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
211
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
212 (defvar rsf-scanning-messages-now nil
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
213 "Non nil when rmail-spam-filter scans messages,
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
214 for interaction with `rsf-bbdb-auto-delete-spam-entries'")
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
215
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
216 ;; the advantage over the automatic filter definitions is the AND conjunction
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
217 ;; of in-one-definition-elements
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
218 (defun check-field (field-symbol message-data definition result)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
219 "Check if field-symbol is in `rsf-definitions-alist'.
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
220 Capture maybe-spam and this-is-a-spam-email in a cons in result,
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
221 where maybe-spam is in first and this-is-a-spam-email is in rest.
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
222 The values are returned by destructively changing result.
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
223 If FIELD-SYMBOL field does not exist AND is not specified,
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
224 this may still be spam due to another element...
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
225 if (first result) is nil, we already have a contradiction in another
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
226 field"
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
227 (let ((definition-field (cdr (assoc field-symbol definition))))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
228 (if (and (first result) (> (length definition-field) 0))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
229 ;; only in this case can maybe-spam change from t to nil
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
230 ;; ... else, if FIELD-SYMBOL field does appear in the message,
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
231 ;; and it also appears in spam definition list, this
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
232 ;; is potentially a spam:
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
233 (if (and message-data
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
234 (string-match definition-field message-data))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
235 ;; if we do not get a contradiction from another field, this is
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
236 ;; spam
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
237 (setf (rest result) t)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
238 ;; the message data contradicts the specification, this is no spam
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
239 (setf (first result) nil)))))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
240
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
241 (defun rmail-spam-filter (msg)
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
242 "Return nil if msg is spam based on rsf-definitions-alist.
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
243 If spam, optionally output msg to a file `rsf-file' and delete
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
244 it from rmail file. Called for each new message retrieved by
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
245 `rmail-get-new-mail'."
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
246
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
247 (let ((old-message)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
248 (return-value)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
249 (this-is-a-spam-email)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
250 (maybe-spam)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
251 (message-sender)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
252 (message-recipients)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
253 (message-subject)
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
254 (message-content-type)
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
255 (num-spam-definition-elements)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
256 (num-element 0)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
257 (exit-while-loop nil)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
258 (saved-case-fold-search case-fold-search)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
259 (save-current-msg)
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
260 (rsf-saved-bbdb/mail_auto_create_p nil)
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
261 )
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
262
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
263 ;; make sure bbdb does not create entries for messages while spam
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
264 ;; filter is scanning the rmail file:
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
265 (setq rsf-saved-bbdb/mail_auto_create_p 'bbdb/mail_auto_create_p)
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
266 (setq bbdb/mail_auto_create_p nil)
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
267 ;; let `rsf-bbdb-auto-delete-spam-entries' know that rmail spam
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
268 ;; filter is running, so that deletion of rmail messages should be
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
269 ;; ignored for now:
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
270 (setq rsf-scanning-messages-now t)
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
271 (save-excursion
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
272 (save-restriction
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
273 (setq this-is-a-spam-email nil)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
274 ;; Narrow buffer to header of message and get Sender and
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
275 ;; Subject fields to be used below:
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
276 (save-restriction
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
277 (goto-char (rmail-msgbeg msg))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
278 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
279 (setq message-sender (mail-fetch-field "From"))
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
280 (setq message-recipients
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
281 (concat (mail-fetch-field "To")
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
282 (if (mail-fetch-field "Cc")
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
283 (concat ", " (mail-fetch-field "Cc")))))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
284 (setq message-subject (mail-fetch-field "Subject"))
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
285 (setq message-content-type (mail-fetch-field "Content-Type"))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
286 )
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
287 ;; Find number of spam-definition elements in the list
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
288 ;; rsf-definitions-alist specified by user:
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
289 (setq num-spam-definition-elements (safe-length
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
290 rsf-definitions-alist))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
291
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
292 ;;; do we want to ignore case in spam definitions:
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
293 (setq case-fold-search rsf-ignore-case)
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
294
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
295 ;; Check for blind CC condition. Set vars such that while
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
296 ;; loop will be bypassed and spam condition will trigger
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
297 (if (and rsf-no-blind-cc
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
298 (null message-recipients))
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
299 (setq exit-while-loop t
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
300 maybe-spam t
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
301 this-is-a-spam-email t))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
302
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
303 ;; Check white list, and likewise cause while loop
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
304 ;; bypass.
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
305 (if (let ((white-list rsf-white-list)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
306 (found nil))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
307 (while (and (not found) white-list)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
308 (if (string-match (car white-list) message-sender)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
309 (setq found t)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
310 (setq white-list (cdr white-list))))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
311 found)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
312 (setq exit-while-loop t
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
313 maybe-spam nil
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
314 this-is-a-spam-email nil))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
315
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
316 ;; maybe-spam is in first, this-is-a-spam-email in rest, this
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
317 ;; simplifies the call to check-field
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
318 (setq maybe-spam (cons maybe-spam this-is-a-spam-email))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
319
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
320 ;; scan all elements of the list rsf-definitions-alist
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
321 (while (and
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
322 (< num-element num-spam-definition-elements)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
323 (not exit-while-loop))
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
324 (let ((definition (nth num-element rsf-definitions-alist)))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
325 ;; Initialize maybe-spam which is set to t in one of two
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
326 ;; cases: (1) unspecified definition-elements are found in
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
327 ;; rsf-definitions-alist, (2) empty field is found
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
328 ;; in the message being scanned (e.g. empty subject,
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
329 ;; sender, recipients, etc). The variable is set to nil
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
330 ;; if a non empty field of the scanned message does not
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
331 ;; match a specified field in
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
332 ;; rsf-definitions-alist.
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
333
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
334 ;; initialize this-is-a-spam-email to nil. This variable
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
335 ;; is set to t if one of the spam definitions matches a
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
336 ;; field in the scanned message.
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
337 (setq maybe-spam (cons t nil))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
338
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
339 ;; start scanning incoming message:
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
340 ;;---------------------------------
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
341
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
342 ;; Maybe the different fields should also be done in a
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
343 ;; loop to make the whole thing more flexible
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
344 ;; if sender field is not specified in message being
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
345 ;; scanned, AND if "from" field does not appear in spam
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
346 ;; definitions for this element, this may still be spam
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
347 ;; due to another element...
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
348 (check-field 'from message-sender definition maybe-spam)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
349 ;; next, if spam was not ruled out already, check recipients:
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
350 (check-field 'to message-recipients definition maybe-spam)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
351 ;; next, if spam was not ruled out already, check subject:
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
352 (check-field 'subject message-subject definition maybe-spam)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
353 ;; next, if spam was not ruled out already, check content-type:
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
354 (check-field 'content-type message-content-type
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
355 definition maybe-spam)
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
356 ;; next, if spam was not ruled out already, check
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
357 ;; contents: if contents field is not specified, this may
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
358 ;; still be spam due to another element...
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
359 (check-field 'contents
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
360 (buffer-substring
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
361 (rmail-msgbeg msg) (rmail-msgend msg))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
362 definition maybe-spam)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
363
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
364 ;; if the search in rsf-definitions-alist found
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
365 ;; that this email is spam, output the email to the spam
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
366 ;; rmail file, mark the email for deletion, leave the
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
367 ;; while loop and return nil so that an rmail summary line
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
368 ;; wont be displayed for this message:
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
369 (if (and (first maybe-spam) (rest maybe-spam))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
370 ;; found that this is spam, no need to look at the
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
371 ;; rest of the rsf-definitions-alist, exit
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
372 ;; loop:
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
373 (setq exit-while-loop t)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
374 ;; else, spam was not yet found, increment number of
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
375 ;; element in rsf-definitions-alist and proceed
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
376 ;; to next element:
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
377 (setq num-element (+ num-element 1)))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
378 )
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
379 )
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
380
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
381 ;; (BK) re-set originally used variables
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
382 (setq this-is-a-spam-email (rest maybe-spam)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
383 maybe-spam (first maybe-spam))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
384
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
385 (if (and this-is-a-spam-email maybe-spam)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
386 (progn
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
387 ;;(message "Found spam!")
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
388 ;;(ding 1) (sleep-for 2)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
389
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
390 ;; temprarily set rmail-current-message in order to
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
391 ;; output and delete the spam msg if needed:
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
392 (setq save-current-msg rmail-current-message)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
393 (setq rmail-current-message msg)
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
394 ;; check action item and rsf-definitions-alist
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
395 ;; and do it:
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
396 (cond
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
397 ((equal (cdr (assoc 'action
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
398 (nth num-element rsf-definitions-alist)))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
399 'output-and-delete)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
400 (progn
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
401 (rmail-output-to-rmail-file rsf-file 1 t)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
402 ;; Don't delete if automatic deletion after output
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
403 ;; is turned on
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
404 (unless rmail-delete-after-output (rmail-delete-message))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
405 ))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
406 ((equal (cdr (assoc 'action
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
407 (nth num-element rsf-definitions-alist)))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
408 'delete-spam)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
409 (progn
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
410 (rmail-delete-message)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
411 ))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
412 )
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
413 (setq rmail-current-message save-current-msg)
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
414 (setq bbdb/mail_auto_create_p
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
415 'rsf-saved-bbdb/mail_auto_create_p)
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
416 ;; set return value. These lines must be last in the
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
417 ;; function, so that they will determine the value
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
418 ;; returned by rmail-spam-filter:
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
419 (setq return-value nil))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
420 (setq return-value t))))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
421 (setq case-fold-search saved-case-fold-search)
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
422 (setq rsf-scanning-messages-now nil)
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
423 return-value))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
424
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
425
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
426 ;; define functions for interactively adding sender/subject of a
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
427 ;; specific message to the spam definitions while reading it, using
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
428 ;; the menubar:
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
429 (defun rsf-add-subject-to-spam-list ()
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
430 (interactive)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
431 (set-buffer rmail-buffer)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
432 (let ((message-subject))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
433 (setq message-subject (mail-fetch-field "Subject"))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
434 ;; note the use of a backquote and comma on the subject line here,
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
435 ;; to make sure message-subject is actually evaluated and its value
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
436 ;; substituted:
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
437 (add-to-list 'rsf-definitions-alist
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
438 (list '(from . "")
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
439 '(to . "")
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
440 `(subject . ,message-subject)
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
441 '(content-type . "")
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
442 '(contents . "")
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
443 '(action . output-and-delete))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
444 t)
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
445 (customize-mark-to-save 'rsf-definitions-alist)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
446 (if rsf-autosave-newly-added-definitions
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
447 (progn
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
448 (custom-save-all)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
449 (message (concat "added subject \n <<< \n" message-subject
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
450 " \n >>> \n to list of spam definitions. \n"
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
451 "and saved the spam definitions to file.")))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
452 (message (concat "added subject \n <<< \n" message-subject
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
453 " \n >>> \n to list of spam definitions. \n"
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
454 "Don't forget to save the spam definitions to file using the spam
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
455 menu"))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
456 )))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
457
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
458 (defun rsf-add-sender-to-spam-list ()
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
459 (interactive)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
460 (set-buffer rmail-buffer)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
461 (let ((message-sender))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
462 (setq message-sender (mail-fetch-field "From"))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
463 ;; note the use of a backquote and comma on the "from" line here,
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
464 ;; to make sure message-sender is actually evaluated and its value
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
465 ;; substituted:
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
466 (add-to-list 'rsf-definitions-alist
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
467 (list `(from . ,message-sender)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
468 '(to . "")
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
469 '(subject . "")
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
470 '(content-type . "")
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
471 '(contents . "")
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
472 '(action . output-and-delete))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
473 t)
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
474 (customize-mark-to-save 'rsf-definitions-alist)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
475 (if rsf-autosave-newly-added-definitions
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
476 (progn
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
477 (custom-save-all)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
478 (message (concat "added sender \n <<< \n" message-sender
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
479 " \n >>> \n to list of spam definitions. \n"
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
480 "and saved the spam definitions to file.")))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
481 (message (concat "added sender \n <<< \n " message-sender
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
482 " \n >>> \n to list of spam definitions."
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
483 "Don't forget to save the spam definitions to file using the spam
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
484 menu"))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
485 )))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
486
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
487
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
488 (defun rsf-add-region-to-spam-list ()
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
489 "Add the region makred by user in the rmail buffer to spam list.
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
490 Added to spam definitions as a contents field."
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
491 (interactive)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
492 (set-buffer rmail-buffer)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
493 (let ((region-to-spam-list))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
494 ;; check if region is inactive or has zero size:
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
495 (if (not (and mark-active (not (= (region-beginning) (region-end)))))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
496 ;; if inactive, print error message:
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
497 (message "you need to first highlight some text in the rmail buffer")
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
498 (if (< (- (region-end) (region-beginning)) rsf-min-region-to-spam-list)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
499 (message
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
500 (concat "highlighted region is too small; min length set by variable \n"
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
501 "rsf-min-region-to-spam-list"
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
502 " is " (number-to-string rsf-min-region-to-spam-list)))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
503 ;; if region active and long enough, add to list of spam definisions:
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
504 (progn
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
505 (setq region-to-spam-list (buffer-substring (region-beginning) (region-end)))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
506 ;; note the use of a backquote and comma on the "from" line here,
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
507 ;; to make sure message-sender is actually evaluated and its value
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
508 ;; substituted:
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
509 (add-to-list 'rsf-definitions-alist
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
510 (list '(from . "")
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
511 '(to . "")
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
512 '(subject . "")
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
513 '(content-type . "")
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
514 `(contents . ,region-to-spam-list)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
515 '(action . output-and-delete))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
516 t)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
517 (customize-mark-to-save 'rsf-definitions-alist)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
518 (if rsf-autosave-newly-added-definitions
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
519 (progn
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
520 (custom-save-all)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
521 (message (concat "added highlighted text \n <<< \n" region-to-spam-list
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
522 " \n >>> \n to list of spam definitions. \n"
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
523 "and saved the spam definitions to file.")))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
524 (message (concat "added highlighted text \n <<< \n " region-to-spam-list
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
525 " \n >>> \n to list of spam definitions."
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
526 "Don't forget to save the spam definitions to file using the
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
527 spam menu"))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
528 ))))))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
529
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
530
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
531 (defun rsf-customize-spam-definitions ()
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
532 (interactive)
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
533 (customize-variable (quote rsf-definitions-alist)))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
534
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
535 (defun rsf-customize-group ()
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
536 (interactive)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
537 (customize-group (quote rmail-spam-filter)))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
538
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
539 (defun rsf-custom-save-all ()
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
540 (interactive)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
541 (custom-save-all))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
542
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
543 ;; add the actual menu items and keyboard shortcuts to both rmail and
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
544 ;; rmail-summary menu-bars::
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
545 (define-key rmail-summary-mode-map [menu-bar spam]
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
546 (cons "Spam" (make-sparse-keymap "Spam")))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
547 (define-key rmail-mode-map [menu-bar spam]
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
548 (cons "Spam" (make-sparse-keymap "Spam")))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
549
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
550 (define-key rmail-summary-mode-map [menu-bar spam customize-group]
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
551 '("Browse customizations of rmail spam filter" . rsf-customize-group))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
552 (define-key rmail-mode-map [menu-bar spam customize-group]
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
553 '("Browse customizations of rmail spam filter" . rsf-customize-group))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
554 (define-key rmail-summary-mode-map "\C-cSg" 'rsf-customize-group)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
555 (define-key rmail-mode-map "\C-cSg" 'rsf-customize-group)
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
556
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
557 (define-key rmail-summary-mode-map [menu-bar spam customize-spam-list]
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
558 '("Customize list of spam definitions" . rsf-customize-spam-definitions))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
559 (define-key rmail-mode-map [menu-bar spam customize-spam-list]
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
560 '("Customize list of spam definitions" . rsf-customize-spam-definitions))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
561 (define-key rmail-summary-mode-map "\C-cSd" 'rsf-customize-spam-definitions)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
562 (define-key rmail-mode-map "\C-cSd" 'rsf-customize-spam-definitions)
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
563
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
564 (define-key rmail-summary-mode-map [menu-bar spam lambda] '("----"))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
565 (define-key rmail-mode-map [menu-bar spam lambda] '("----"))
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
566
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
567 (define-key rmail-summary-mode-map [menu-bar spam my-custom-save-all]
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
568 '("save newly added spam definitions to customization file" . rsf-custom-save-all))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
569 (define-key rmail-mode-map [menu-bar spam my-custom-save-all]
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
570 '("save newly added spam definitions to customization file" . rsf-custom-save-all))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
571 (define-key rmail-summary-mode-map "\C-cSa" 'rsf-custom-save-all)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
572 (define-key rmail-mode-map "\C-cSa" 'rsf-custom-save-all)
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
573
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
574 (define-key rmail-summary-mode-map [menu-bar spam add-region-to-spam-list]
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
575 '("add region to spam list" . rsf-add-region-to-spam-list))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
576 (define-key rmail-mode-map [menu-bar spam add-region-to-spam-list]
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
577 '("add region to spam list" . rsf-add-region-to-spam-list))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
578 (define-key rmail-summary-mode-map "\C-cSn" 'rsf-add-region-to-spam-list)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
579 (define-key rmail-mode-map "\C-cSn" 'rsf-add-region-to-spam-list)
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
580
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
581 (define-key rmail-summary-mode-map [menu-bar spam add-sender-to-spam-list]
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
582 '("add sender to spam list" . rsf-add-sender-to-spam-list))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
583 (define-key rmail-mode-map [menu-bar spam add-sender-to-spam-list]
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
584 '("add sender to spam list" . rsf-add-sender-to-spam-list))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
585 (define-key rmail-summary-mode-map "\C-cSr" 'rsf-add-sender-to-spam-list)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
586 (define-key rmail-mode-map "\C-cSr" 'rsf-add-sender-to-spam-list)
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
587
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
588 (define-key rmail-summary-mode-map [menu-bar spam add-subject-to-spam-list]
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
589 '("add subject to spam list" . rsf-add-subject-to-spam-list))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
590 (define-key rmail-mode-map [menu-bar spam add-subject-to-spam-list]
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
591 '("add subject to spam list" . rsf-add-subject-to-spam-list))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
592 (define-key rmail-summary-mode-map "\C-cSt" 'rsf-add-subject-to-spam-list)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
593 (define-key rmail-mode-map "\C-cSt" 'rsf-add-subject-to-spam-list)
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
594
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
595 (defun rsf-add-content-type-field ()
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
596 "Maintain backward compatibility with previous versions of rmail-spam-filter.
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
597 The most recent version of rmai-spam-filter checks the contents
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
598 field of the incoming mail to see if it spam. The format of
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
599 `rsf-definitions-alist' has therefore changed. This function
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
600 checks to see if old format is used, and if it is, it converts
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
601 `rsf-definitions-alist' to the new format. Invoked
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
602 automatically, no user input is required."
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
603 (interactive)
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
604 (if (and rsf-definitions-alist
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
605 (not (assoc 'content-type (car rsf-definitions-alist))))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
606 (let ((result nil)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
607 (current nil)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
608 (definitions rsf-definitions-alist))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
609 (while definitions
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
610 (setq current (car definitions))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
611 (setq definitions (cdr definitions))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
612 (setq result
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
613 (append result
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
614 (list
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
615 (list (assoc 'from current)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
616 (assoc 'to current)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
617 (assoc 'subject current)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
618 (cons 'content-type "")
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
619 (assoc 'contents current)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
620 (assoc 'action current))))))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
621 (setq rsf-definitions-alist result)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
622 (customize-mark-to-save 'rsf-definitions-alist)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
623 (if rsf-autosave-newly-added-definitions
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
624 (progn
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
625 (custom-save-all)
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
626 (message (concat "converted spam definitions to new format\n"
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
627 "and saved the spam definitions to file.")))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
628 (message (concat "converted spam definitions to new format\n"
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
629 "Don't forget to save the spam definitions to file using the
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
630 spam menu"))
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
631 ))))
49862
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
632
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
633 (provide 'rmail-spam-filter)
22e7cf92fa43 Initial commit to the trunk.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
634
89909
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
635 ;;; arch-tag: 03e1d45d-b72f-4dd7-8f04-e7fd78249746
68c22ea6027c Sync to HEAD
Kenichi Handa <handa@m17n.org>
parents: 88123
diff changeset
636 ;;; rmail-spam-fitler ends here