Mercurial > emacs
annotate lisp/mail/rmail-spam-filter.el @ 88310:3a8dcdafba19
(rmail-convert-mbox-format): Handle mails without subject.
author | Alex Schroeder <alex@gnu.org> |
---|---|
date | Wed, 01 Feb 2006 19:26:18 +0000 |
parents | de90332b77e9 |
children |
rev | line source |
---|---|
88137 | 1 ;;; rmail-spam-filter.el --- spam filter for rmail, the emacs mail reader. |
2 | |
3 ;; Copyright (C) 2002 | |
4 ;; Free Software Foundation, Inc. | |
5 ;; Keywords: email, spam, filter, rmail | |
6 ;; Author: Eli Tziperman <eli@beach.weizmann.ac.il> | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs 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. | |
14 | |
15 ;; GNU Emacs 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. | |
19 | |
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. | |
24 | |
25 ;;; Commentary: | |
26 ;;; ----------- | |
27 | |
28 ;;; Automatically recognize and delete junk email before it is | |
29 ;;; displayed in rmail/rmail-summary. Spam emails are defined by | |
30 ;;; specifying one or more of the sender, subject and contents. | |
31 ;;; URL: http://www.weizmann.ac.il/~eli/Downloads/rmail-spam-filter/ | |
32 | |
33 ;;; Usage: | |
34 ;;; ------ | |
35 | |
36 ;;; put in your .emacs: | |
37 | |
38 ;;; (load "rmail-spam-filter.el") | |
39 | |
40 ;;; and use customize (in rmail-spam-filter group) to: | |
41 | |
42 ;;; (*) turn on the variable rmail-use-spam-filter, | |
43 | |
44 ;;; (*) specify in variable rmail-spam-definitions-alist what sender, | |
45 ;;; subject and contents make an email be considered spam. | |
46 | |
47 ;;; in addition, you may: | |
48 | |
49 ;;; (*) Block future mail with the subject or sender of a message | |
50 ;;; while reading it in RMAIL: just click on the "Spam" item on the | |
51 ;;; menubar, and add the subject or sender to the list of spam | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
52 ;;; definitions using the mouse and the appropriate menu item. You |
88137 | 53 ;;; need to later also save the list of spam definitions using the |
54 ;;; same menu item, or alternatively, see variable | |
55 ;;; `rmail-spam-filter-autosave-newly-added-spam-definitions'. | |
56 | |
57 ;;; (*) specify if blind-cc'ed mail (no "To:" header field) is to be | |
58 ;;; treated as spam (variable rmail-spam-no-blind-cc; Thanks to Ethan | |
59 ;;; Brown <ethan@gso.saic.com> for this). | |
60 | |
61 ;;; (*) specify if rmail-spam-filter should ignore case of spam | |
62 ;;; definitions (variable rmail-spam-filter-ignore-case; Thanks to | |
63 ;;; Ethan Brown <ethan@gso.saic.com> for the suggestion). | |
64 | |
65 ;;; (*) Specify a "white-list" of trusted senders. If any | |
66 ;;; rmail-spam-white-list string matches a substring of the "From" | |
67 ;;; header, the message is flagged as a valid, non-spam message (Ethan | |
68 ;;; Brown <ethan@gso.saic.com>). | |
69 | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
70 ;;; (*) rmail-spam-filter is best used with a general purpose spam |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
71 ;;; filter such as the procmail-based http://www.spambouncer.org/. |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
72 ;;; Spambouncer is set to only mark messages as spam/blocked/bulk/OK |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
73 ;;; via special headers, and these headers may then be defined in |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
74 ;;; rmail-spam-filter such that the spam is rejected by |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
75 ;;; rmail-spam-filter itself. |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
76 |
88137 | 77 ;;; (*) rmail spam filter also works with bbdb to prevent spam senders |
78 ;;; from entering into the .bbdb file. See variable | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
79 ;;; "spam-filter-auto-delete-spam-bbdb-entries". This is done |
88137 | 80 ;;; in two ways: (a) bbdb is made not to auto-create entries for |
81 ;;; messages that are deleted by the rmail-spam-filter, (b) when a | |
82 ;;; message is deleted in rmail, the user is offered to delete the | |
83 ;;; sender's bbdb entry as well _if_ it was created at the same day. | |
84 | |
85 (require 'rmail) | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
86 (if (> emacs-major-version 20) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
87 (require 'rmailsum) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
88 (if (not (fboundp 'rmail-make-summary-line)) (load-library "rmailsum"))) |
88137 | 89 |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
90 (eval-when-compile |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
91 (require 'cl)) |
88137 | 92 |
93 (defgroup rmail-spam-filter nil | |
94 "Spam filter for RMAIL, the mail reader for Emacs." | |
95 :group 'rmail) | |
96 | |
97 (defcustom rmail-use-spam-filter nil | |
98 "*Non-nil to activate the rmail spam filter. | |
99 Specify `rmail-spam-definitions-alist' to define what you consider spam | |
100 emails." | |
101 :type 'boolean | |
102 :group 'rmail-spam-filter ) | |
103 | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
104 (defcustom vm-use-spam-filter nil |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
105 "*Non-nil to activate the rmail spam filter. |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
106 Specify `rmail-spam-definitions-alist' to define what you consider spam |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
107 emails." |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
108 :type 'boolean |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
109 :group 'rmail-spam-filter ) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
110 |
88137 | 111 (defcustom rmail-spam-file "~/XRMAIL-SPAM" |
112 "*Name of rmail file for optionally saving some of the spam. | |
113 Spam may be either just deleted, or saved in a separate spam file to | |
114 be looked at at a later time. Whether the spam is just deleted or | |
115 also saved in a separete spam file is specified for each definition of | |
116 spam, as one of the fields of `rmail-spam-definitions-alist'" | |
117 :type 'string | |
118 :group 'rmail-spam-filter ) | |
119 | |
120 (defcustom rmail-spam-no-blind-cc nil | |
121 "*Non-nil to treat blind CC (no To: header) as spam." | |
122 :type 'boolean | |
123 :group 'rmail-spam-filter ) | |
124 | |
125 (defcustom rmail-spam-filter-ignore-case nil | |
126 "*Non-nil to ignore case in `rmail-spam-definitions-alist'." | |
127 :type 'boolean | |
128 :group 'rmail-spam-filter ) | |
129 | |
130 (defcustom rmail-spam-filter-beep nil | |
131 "*Non-nil to beep if spam is found." | |
132 :type 'boolean | |
133 :group 'rmail-spam-filter ) | |
134 | |
135 (defcustom rmail-spam-sleep-after-message 2.0 | |
136 "*Seconds to wait after display of message that spam was found." | |
137 :type 'number | |
138 :group 'rmail-spam-filter ) | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
139 |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
140 (defcustom rmail-spam-filter-min-region-length-added-to-spam-list 7 |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
141 "*Minimum size of region highllighted in a message that can be added to spam list" |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
142 :type 'integer |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
143 :group 'rmail-spam-filter ) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
144 |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
145 (defcustom spam-filter-auto-delete-spam-bbdb-entries nil |
88137 | 146 "*Non-nil to make sure no entries are made in bbdb for spam emails. |
147 This is done in two ways: (1) bbdb is made not to auto-create entries | |
148 for messages that are deleted by the `rmail-spam-filter', (2) when a | |
149 message is deleted in rmail, the user is offered to delete the | |
150 sender's bbdb entry as well if it was created at the same day. Note | |
151 that Emacs needs to be restarted after setting this option for it to | |
152 take an effect." | |
153 :type 'boolean | |
154 :group 'rmail-spam-filter ) | |
155 | |
156 (defcustom rmail-spam-filter-autosave-newly-added-spam-definitions nil | |
157 "*Non-nil to auto save new spam entries. | |
158 New entries entered via the spam menu bar item are then saved to | |
159 customization file immediately after being added via the menu bar, and | |
160 do not require explicitly saving the file after adding the new | |
161 entries." | |
162 :type 'boolean | |
163 :group 'rmail-spam-filter ) | |
164 | |
165 (defcustom rmail-spam-white-list nil | |
166 "*List of strings to identify valid senders. | |
167 If any rmail-spam-white-list string matches a substring of the 'From' | |
168 header, the message is flagged as a valid, non-spam message. Example: | |
169 If your domain is emacs.com then including 'emacs.com' in your | |
170 rmail-spam-white-list would flag all mail from your colleagues as | |
171 valid." | |
172 :type '(repeat string) | |
173 :group 'rmail-spam-filter ) | |
174 | |
175 (defcustom rmail-spam-definitions-alist nil | |
176 "*Alist matching strings defining what messages are considered spam. | |
177 Each definition may contain specifications of one or more of the | |
178 elements {subject, sender, recipients or contents}, as well as a | |
179 definition of what to do with the spam (action item). A spam e-mail | |
180 is defined as one that fits all of the specified elements of any one | |
181 of the spam definitions. The strings that specify spam subject, | |
182 sender, etc, may be regexp. For example, to specify that the subject | |
183 may be either 'this is spam' or 'another spam', use the regexp: 'this | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
184 is spam\\|another spam' (without the single quotes). To specify that |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
185 if the contents contain both this and that the message is spam, |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
186 specify 'this\\&that' in the appropriate spam definition field." |
88137 | 187 :type '(repeat |
188 (list :format "%v" | |
189 (cons :format "%v" :value (from . "") | |
190 (const :format "" from) | |
191 (string :tag "From" "")) | |
192 (cons :format "%v" :value (to . "") | |
193 (const :format "" to) | |
194 (string :tag "To" "")) | |
195 (cons :format "%v" :value (subject . "") | |
196 (const :format "" subject) | |
197 (string :tag "Subject" "")) | |
198 (cons :format "%v" :value (contents . "") | |
199 (const :format "" contents) | |
200 (string :tag "Contents" "")) | |
201 (cons :format "%v" :value (action . output-and-delete) | |
202 (const :format "" action) | |
203 (choice :tag "Action selection" | |
204 (const :tag "output to spam folder and delete" output-and-delete) | |
205 (const :tag "delete spam" delete-spam) | |
206 )) | |
207 )) | |
208 :group 'rmail-spam-filter) | |
209 | |
210 (defvar rmail-spam-filter-scanning-messages-now nil | |
211 "Non nil when rmail-spam-filter scans messages, | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
212 for interaction with `spam-filter-bbdb-auto-delete-spam-entries'") |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
213 |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
214 (defvar spam-filter-working-with-vm nil |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
215 "Non nil when vm is active. |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
216 for interaction with `spam-filter-auto-delete-spam-bbdb-entries'") |
88137 | 217 |
218 (defun rmail-spam-filter (msg) | |
219 "Return nil if msg is spam based on rmail-spam-definitions-alist. | |
220 If spam, optionally output msg to a file `rmail-spam-file' and delete | |
221 it from rmail file. Called for each new message retrieved by | |
222 `rmail-get-new-mail'." | |
223 | |
224 (let ((old-message) | |
225 (return-value) | |
226 (this-is-a-spam-email) | |
227 (maybe-spam) | |
228 (message-sender) | |
229 (message-recipients) | |
230 (message-subject) | |
231 (num-spam-definition-elements) | |
232 (num-element 0) | |
233 (exit-while-loop nil) | |
234 (saved-case-fold-search case-fold-search) | |
235 (save-current-msg) | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
236 (rmail-spam-filter-saved-bbdb/mail_auto_create_p nil)) |
88137 | 237 |
238 ;; make sure bbdb does not create entries for messages while spam | |
239 ;; filter is scanning the rmail file: | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
240 (setq rmail-spam-filter-saved-bbdb/mail_auto_create_p |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
241 'bbdb/mail_auto_create_p |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
242 bbdb/mail_auto_create_p nil) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
243 ;; let `spam-filter-bbdb-auto-delete-spam-entries' know that rmail spam |
88137 | 244 ;; filter is running, so that deletion of rmail messages should be |
245 ;; ignored for now: | |
246 (setq rmail-spam-filter-scanning-messages-now t) | |
247 (save-excursion | |
248 (save-restriction | |
249 (setq this-is-a-spam-email nil) | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
250 |
88137 | 251 ;; Narrow buffer to header of message and get Sender and |
252 ;; Subject fields to be used below: | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
253 (narrow-to-region |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
254 (rmail-desc-get-start current-message) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
255 (rmail-desc-get-end current-message)) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
256 (goto-char (point-min)) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
257 (setq message-sender (mail-fetch-field "From") |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
258 message-recipients |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
259 (concat (mail-fetch-field "To") |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
260 (if (mail-fetch-field "Cc") |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
261 (concat ", " (mail-fetch-field "Cc")))) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
262 message-subject (mail-fetch-field "Subject"))) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
263 |
88137 | 264 ;; Find number of spam-definition elements in the list |
265 ;; rmail-spam-definitions-alist specified by user: | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
266 (setq num-spam-definition-elements |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
267 (safe-length rmail-spam-definitions-alist)) |
88137 | 268 |
269 ;;; do we want to ignore case in spam definitions: | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
270 (setq case-fold-search rmail-spam-filter-ignore-case) |
88137 | 271 |
272 ;; Check for blind CC condition. Set vars such that while | |
273 ;; loop will be bypassed and spam condition will trigger (EDB) | |
274 (if (and rmail-spam-no-blind-cc | |
275 (null message-recipients)) | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
276 (setq exit-while-loop t |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
277 maybe-spam t |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
278 this-is-a-spam-email t)) |
88137 | 279 |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
280 ;; Check white list, and likewise cause while loop |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
281 ;; bypass. (EDB) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
282 (if (let ((white-list rmail-spam-white-list) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
283 (found nil)) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
284 (while (and (not found) white-list) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
285 (if (string-match (car white-list) message-sender) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
286 (setq found t) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
287 (setq white-list (cdr white-list)))) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
288 found) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
289 (setq exit-while-loop t |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
290 maybe-spam nil |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
291 this-is-a-spam-email nil)) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
292 |
88137 | 293 ;; scan all elements of the list rmail-spam-definitions-alist |
294 (while (and | |
295 (< num-element num-spam-definition-elements) | |
296 (not exit-while-loop)) | |
297 (progn | |
298 ;; Initialize maybe-spam which is set to t in one of two | |
299 ;; cases: (1) unspecified definition-elements are found in | |
300 ;; rmail-spam-definitions-alist, (2) empty field is found | |
301 ;; in the message being scanned (e.g. empty subject, | |
302 ;; sender, recipients, etc). The variable is set to nil | |
303 ;; if a non empty field of the scanned message does not | |
304 ;; match a specified field in | |
305 ;; rmail-spam-definitions-alist. | |
306 (setq maybe-spam t) | |
307 ;; initialize this-is-a-spam-email to nil. This variable | |
308 ;; is set to t if one of the spam definitions matches a | |
309 ;; field in the scanned message. | |
310 (setq this-is-a-spam-email nil) | |
311 | |
312 ;; start scanning incoming message: | |
313 ;;--------------------------------- | |
314 | |
315 ;; if sender field is not specified in message being | |
316 ;; scanned, AND if "from" field does not appear in spam | |
317 ;; definitions for this element, this may still be spam | |
318 ;; due to another element... | |
319 (if (and (not message-sender) | |
320 (string-match | |
321 (cdr (assoc 'from (nth num-element | |
322 rmail-spam-definitions-alist))) "")) | |
323 (setq maybe-spam t) | |
324 ;; ... else, if message-sender does appear in the | |
325 ;; message, and it also appears in the spam definition | |
326 ;; list, it is potentially spam: | |
327 (if (and message-sender | |
328 (string-match | |
329 (cdr (assoc 'from (nth num-element | |
330 rmail-spam-definitions-alist))) | |
331 message-sender) | |
332 ) | |
333 (setq this-is-a-spam-email t) | |
334 (setq maybe-spam nil) | |
335 ) | |
336 ) | |
337 ;; next, if spam was not ruled out already, check recipients: | |
338 (if maybe-spam | |
339 ;; if To field does not exist AND is not specified, | |
340 ;; this may still be spam due to another element... | |
341 (if (and (not message-recipients) | |
342 (string-match | |
343 (cdr (assoc 'to | |
344 (nth num-element | |
345 rmail-spam-definitions-alist))) "")) | |
346 (setq maybe-spam t) | |
347 ;; ... else, if To field does appear in the message, | |
348 ;; and it also appears in spam definition list, this | |
349 ;; is potentially a spam: | |
350 (if (and message-recipients | |
351 (string-match | |
352 (cdr (assoc 'to (nth num-element | |
353 rmail-spam-definitions-alist))) | |
354 message-recipients) | |
355 ) | |
356 (setq this-is-a-spam-email t) | |
357 (setq maybe-spam nil) | |
358 ) | |
359 ) | |
360 ) | |
361 ;; next, if spam was not ruled out already, check subject: | |
362 (if maybe-spam | |
363 ;; if subject field does not exist AND is not | |
364 ;; specified, this may still be spam due to another | |
365 ;; element... | |
366 (if (and (not message-subject) | |
367 (string-match | |
368 (cdr (assoc 'subject | |
369 (nth num-element | |
370 rmail-spam-definitions-alist))) | |
371 "")) | |
372 (setq maybe-spam t) | |
373 ;; ... else, if subject field does appear in the | |
374 ;; message, and it also appears in the spam | |
375 ;; definition list, this is potentially a spam: | |
376 (if (and message-subject | |
377 (string-match | |
378 (cdr (assoc 'subject (nth num-element | |
379 rmail-spam-definitions-alist))) | |
380 message-subject) | |
381 ) | |
382 (setq this-is-a-spam-email t) | |
383 (setq maybe-spam nil) | |
384 ) | |
385 ) | |
386 ) | |
387 ;; next, if spam was not ruled out already, check | |
388 ;; contents: if contents field is not specified, this may | |
389 ;; still be spam due to another element... | |
390 (if maybe-spam | |
391 (if (string-match | |
392 (cdr (assoc 'contents | |
393 (nth num-element | |
394 rmail-spam-definitions-alist))) "") | |
395 (setq maybe-spam t) | |
396 ;; ... else, check to see if it appears in spam | |
397 ;; definition: | |
398 (if (string-match | |
399 (cdr (assoc 'contents | |
400 (nth num-element | |
401 rmail-spam-definitions-alist))) | |
402 (buffer-substring | |
403 (rmail-msgbeg msg) (rmail-msgend msg))) | |
404 (setq this-is-a-spam-email t) | |
405 (setq maybe-spam nil))) | |
406 ) | |
407 ;; if the search in rmail-spam-definitions-alist found | |
408 ;; that this email is spam, output the email to the spam | |
409 ;; rmail file, mark the email for deletion, leave the | |
410 ;; while loop and return nil so that an rmail summary line | |
411 ;; wont be displayed for this message: | |
412 (if (and this-is-a-spam-email maybe-spam) | |
413 ;; found that this is spam, no need to look at the | |
414 ;; rest of the rmail-spam-definitions-alist, exit | |
415 ;; loop: | |
416 (setq exit-while-loop t) | |
417 ;; else, spam was not yet found, increment number of | |
418 ;; element in rmail-spam-definitions-alist and proceed | |
419 ;; to next element: | |
420 (setq num-element (+ num-element 1))) | |
421 ) | |
422 ) | |
423 (if (and this-is-a-spam-email maybe-spam) | |
424 (progn | |
425 ;;(message "Found spam!") | |
426 ;;(ding 1) (sleep-for 2) | |
427 | |
428 ;; temprarily set rmail-current-message in order to | |
429 ;; output and delete the spam msg if needed: | |
430 (setq save-current-msg rmail-current-message) | |
431 (setq rmail-current-message msg) | |
432 ;; check action item and rmail-spam-definitions-alist | |
433 ;; and do it: | |
434 (cond | |
435 ((equal (cdr (assoc 'action | |
436 (nth num-element rmail-spam-definitions-alist))) | |
437 'output-and-delete) | |
438 (progn | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
439 (rmail-output rmail-spam-file) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
440 ;; Don't delete if automatic deletion after output |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
441 ;; is turned on |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
442 (unless rmail-delete-after-output (rmail-delete-message)) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
443 (rmail-delete-message))) |
88137 | 444 ((equal (cdr (assoc 'action |
445 (nth num-element rmail-spam-definitions-alist))) | |
446 'delete-spam) | |
447 (progn | |
448 (rmail-delete-message) | |
449 )) | |
450 ) | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
451 (setq rmail-current-message save-current-msg) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
452 (setq bbdb/mail_auto_create_p |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
453 'rmail-spam-filter-saved-bbdb/mail_auto_create_p) |
88137 | 454 ;; set return value. These lines must be last in the |
455 ;; function, so that they will determine the value | |
456 ;; returned by rmail-spam-filter: | |
457 (setq return-value nil)) | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
458 (setq return-value t))) |
88137 | 459 (setq case-fold-search saved-case-fold-search) |
460 (setq rmail-spam-filter-scanning-messages-now nil) | |
461 return-value)) | |
462 | |
463 | |
464 ;; define functions for interactively adding sender/subject of a | |
465 ;; specific message to the spam definitions while reading it, using | |
466 ;; the menubar: | |
467 (defun rmail-spam-filter-add-subject-to-spam-list () | |
468 (interactive) | |
469 (set-buffer rmail-buffer) | |
470 (let ((message-subject)) | |
471 (setq message-subject (mail-fetch-field "Subject")) | |
472 ;; note the use of a backquote and comma on the subject line here, | |
473 ;; to make sure message-subject is actually evaluated and its value | |
474 ;; substituted: | |
475 (add-to-list 'rmail-spam-definitions-alist | |
476 (list '(from . "") | |
477 '(to . "") | |
478 `(subject . ,message-subject) | |
479 '(contents . "") | |
480 '(action . output-and-delete)) | |
481 t) | |
482 (customize-mark-to-save 'rmail-spam-definitions-alist) | |
483 (if rmail-spam-filter-autosave-newly-added-spam-definitions | |
484 (progn | |
485 (custom-save-all) | |
486 (message (concat "added subject \n <<< \n" message-subject | |
487 " \n >>> \n to list of spam definitions. \n" | |
488 "and saved the spam definitions to file."))) | |
489 (message (concat "added subject \n <<< \n" message-subject | |
490 " \n >>> \n to list of spam definitions. \n" | |
491 "Don't forget to save the spam definitions to file using the spam menu")) | |
492 ))) | |
493 | |
494 (defun rmail-spam-filter-add-sender-to-spam-list () | |
495 (interactive) | |
496 (set-buffer rmail-buffer) | |
497 (let ((message-sender)) | |
498 (setq message-sender (mail-fetch-field "From")) | |
499 ;; note the use of a backquote and comma on the "from" line here, | |
500 ;; to make sure message-sender is actually evaluated and its value | |
501 ;; substituted: | |
502 (add-to-list 'rmail-spam-definitions-alist | |
503 (list `(from . ,message-sender) | |
504 '(to . "") | |
505 '(subject . "") | |
506 '(contents . "") | |
507 '(action . output-and-delete)) | |
508 t) | |
509 (customize-mark-to-save 'rmail-spam-definitions-alist) | |
510 (if rmail-spam-filter-autosave-newly-added-spam-definitions | |
511 (progn | |
512 (custom-save-all) | |
513 (message (concat "added sender \n <<< \n" message-sender | |
514 " \n >>> \n to list of spam definitions. \n" | |
515 "and saved the spam definitions to file."))) | |
516 (message (concat "added sender \n <<< \n " message-sender | |
517 " \n >>> \n to list of spam definitions." | |
518 "Don't forget to save the spam definitions to file using the spam menu")) | |
519 ))) | |
520 | |
521 | |
522 (defun rmail-spam-filter-add-region-to-spam-list () | |
523 "Add the region makred by user in the rmail buffer to the list of | |
524 spam definitions as a contents field." | |
525 (interactive) | |
526 (set-buffer rmail-buffer) | |
527 (let ((region-to-spam-list)) | |
528 ;; check if region is inactive or has zero size: | |
529 (if (not (and mark-active (not (= (region-beginning) (region-end))))) | |
530 ;; if inactive, print error message: | |
531 (message "you need to first highlight some text in the rmail buffer") | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
532 (if (< (- (region-end) (region-beginning)) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
533 rmail-spam-filter-min-region-length-added-to-spam-list) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
534 (message |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
535 (concat "highlighted region is too small; min length set by variable \n" |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
536 "rmail-spam-filter-min-region-length-added-to-spam-list" |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
537 " is " (number-to-string |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
538 rmail-spam-filter-min-region-length-added-to-spam-list))) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
539 ;; if region active and long enough, add to list of spam definisions: |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
540 (progn |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
541 (setq region-to-spam-list (buffer-substring (region-beginning) (region-end))) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
542 ;; note the use of a backquote and comma on the "from" line here, |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
543 ;; to make sure message-sender is actually evaluated and its value |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
544 ;; substituted: |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
545 (add-to-list 'rmail-spam-definitions-alist |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
546 (list '(from . "") |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
547 '(to . "") |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
548 '(subject . "") |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
549 `(contents . ,region-to-spam-list) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
550 '(action . output-and-delete)) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
551 t) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
552 (customize-mark-to-save 'rmail-spam-definitions-alist) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
553 (if rmail-spam-filter-autosave-newly-added-spam-definitions |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
554 (progn |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
555 (custom-save-all) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
556 (message (concat "added highlighted text \n <<< \n" region-to-spam-list |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
557 " \n >>> \n to list of spam definitions. \n" |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
558 "and saved the spam definitions to file."))) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
559 (message (concat "added highlighted text \n <<< \n " region-to-spam-list |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
560 " \n >>> \n to list of spam definitions." |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
561 "Don't forget to save the spam definitions to file using the spam menu")) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
562 )))))) |
88137 | 563 |
564 | |
565 (defun rmail-spam-filter-customize-spam-definitions () | |
566 (interactive) | |
567 (customize-variable (quote rmail-spam-definitions-alist))) | |
568 | |
569 (defun rmail-spam-filter-customize-group () | |
570 (interactive) | |
571 (customize-group (quote rmail-spam-filter))) | |
572 | |
573 (defun rmail-spam-custom-save-all () | |
574 (interactive) | |
575 (custom-save-all)) | |
576 | |
577 ;; add the actual menu items and keyboard shortcuts to both rmail and | |
578 ;; rmail-summary menu-bars:: | |
579 (define-key rmail-summary-mode-map [menu-bar spam] | |
580 (cons "Spam" (make-sparse-keymap "Spam"))) | |
581 (define-key rmail-mode-map [menu-bar spam] | |
582 (cons "Spam" (make-sparse-keymap "Spam"))) | |
583 | |
584 (define-key rmail-summary-mode-map [menu-bar spam customize-group] | |
585 '("Browse customizations of rmail spam filter" . rmail-spam-filter-customize-group)) | |
586 (define-key rmail-mode-map [menu-bar spam customize-group] | |
587 '("Browse customizations of rmail spam filter" . rmail-spam-filter-customize-group)) | |
588 (define-key rmail-summary-mode-map "\C-cSg" 'rmail-spam-filter-customize-group) | |
589 (define-key rmail-mode-map "\C-cSg" 'rmail-spam-filter-customize-group) | |
590 | |
591 (define-key rmail-summary-mode-map [menu-bar spam customize-spam-list] | |
592 '("Customize list of spam definitions" . rmail-spam-filter-customize-spam-definitions)) | |
593 (define-key rmail-mode-map [menu-bar spam customize-spam-list] | |
594 '("Customize list of spam definitions" . rmail-spam-filter-customize-spam-definitions)) | |
595 (define-key rmail-summary-mode-map "\C-cSd" 'rmail-spam-filter-customize-spam-definitions) | |
596 (define-key rmail-mode-map "\C-cSd" 'rmail-spam-filter-customize-spam-definitions) | |
597 | |
598 (define-key rmail-summary-mode-map [menu-bar spam lambda] '("----")) | |
599 (define-key rmail-mode-map [menu-bar spam lambda] '("----")) | |
600 | |
601 (define-key rmail-summary-mode-map [menu-bar spam my-custom-save-all] | |
602 '("save newly added spam definitions to customization file" . rmail-spam-custom-save-all)) | |
603 (define-key rmail-mode-map [menu-bar spam my-custom-save-all] | |
604 '("save newly added spam definitions to customization file" . rmail-spam-custom-save-all)) | |
605 (define-key rmail-summary-mode-map "\C-cSa" 'rmail-spam-custom-save-all) | |
606 (define-key rmail-mode-map "\C-cSa" 'rmail-spam-custom-save-all) | |
607 | |
608 (define-key rmail-summary-mode-map [menu-bar spam add-region-to-spam-list] | |
609 '("add region to spam list" . rmail-spam-filter-add-region-to-spam-list)) | |
610 (define-key rmail-mode-map [menu-bar spam add-region-to-spam-list] | |
611 '("add region to spam list" . rmail-spam-filter-add-region-to-spam-list)) | |
612 (define-key rmail-summary-mode-map "\C-cSn" 'rmail-spam-filter-add-region-to-spam-list) | |
613 (define-key rmail-mode-map "\C-cSn" 'rmail-spam-filter-add-region-to-spam-list) | |
614 | |
615 (define-key rmail-summary-mode-map [menu-bar spam add-sender-to-spam-list] | |
616 '("add sender to spam list" . rmail-spam-filter-add-sender-to-spam-list)) | |
617 (define-key rmail-mode-map [menu-bar spam add-sender-to-spam-list] | |
618 '("add sender to spam list" . rmail-spam-filter-add-sender-to-spam-list)) | |
619 (define-key rmail-summary-mode-map "\C-cSr" 'rmail-spam-filter-add-sender-to-spam-list) | |
620 (define-key rmail-mode-map "\C-cSr" 'rmail-spam-filter-add-sender-to-spam-list) | |
621 | |
622 (define-key rmail-summary-mode-map [menu-bar spam add-subject-to-spam-list] | |
623 '("add subject to spam list" . rmail-spam-filter-add-subject-to-spam-list)) | |
624 (define-key rmail-mode-map [menu-bar spam add-subject-to-spam-list] | |
625 '("add subject to spam list" . rmail-spam-filter-add-subject-to-spam-list)) | |
626 (define-key rmail-summary-mode-map "\C-cSt" 'rmail-spam-filter-add-subject-to-spam-list) | |
627 (define-key rmail-mode-map "\C-cSt" 'rmail-spam-filter-add-subject-to-spam-list) | |
628 | |
629 | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
630 (defun spam-filter-bbdb-auto-delete-spam-entries () |
88137 | 631 "When deleting a message in RMAIL, check to see if the bbdb entry |
632 was created today, and if it was, prompt to delete it too. This function | |
633 needs to be called via the `rmail-delete-message-hook' like this: | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
634 \(add-hook 'rmail-delete-message-hook 'spam-filter-bbdb-auto-delete-spam-entries)" |
88137 | 635 (interactive) |
636 (require 'bbdb-hooks) | |
637 (if (not rmail-spam-filter-scanning-messages-now) | |
638 (if (get-buffer "*BBDB*") | |
639 (save-excursion | |
640 (set-buffer (get-buffer "*BBDB*")) | |
641 (if (bbdb-current-record) | |
642 (if (equal | |
643 (format-time-string bbdb-time-internal-format (current-time)) | |
644 (bbdb-record-getprop (bbdb-current-record) 'creation-date)) | |
645 (bbdb-delete-current-record (bbdb-current-record)))))))) | |
646 | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
647 (defun spam-filter-bbdb-dont-create-entries-for-deleted-messages () |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
648 "Make sure senderes of messages marked as deleted are not added to bbdb. |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
649 Works with vm and rmail. Returns nil for deleted messages or for messages in spam-folder. |
88137 | 650 Need to add this as a hook like this: |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
651 \(setq bbdb/mail-auto-create-p 'spam-filter-bbdb-dont-create-entries-for-deleted-messages) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
652 and this is also used in conjunction with spam-filter-bbdb-auto-delete-spam-entries. |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
653 More doc: spam-filter-bbdb-auto-delete-spam-entries will delete newly created bbdb |
88137 | 654 entries of mail that is deleted. However, if one scrolls back to the deleted |
655 messages, then the sender is again added to the bbdb. This function | |
656 prevents this. Also, don't create entries for messages in the `rmail-spam-file'." | |
657 (interactive) | |
658 ;; don't create a bbdb entry if one of the following conditions is satisfied: | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
659 (let ((dont-create nil)) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
660 ;; use this only if appropriate variable is set and if |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
661 ;; rmail-buffer is set meaning that rmail is active: |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
662 (if (and rmail-use-spam-filter rmail-buffer) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
663 (setq dont-create |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
664 (or |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
665 ;; 1) looking at a deleted message: |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
666 (rmail-message-deleted-p rmail-current-message) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
667 ;; 2) looking at messages in rmail-spam-file: |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
668 (string-match |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
669 (expand-file-name rmail-spam-file) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
670 (expand-file-name (buffer-file-name rmail-buffer))) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
671 ))) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
672 (if (and vm-use-spam-filter spam-filter-working-with-vm) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
673 (setq dont-create |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
674 (vm-deleted-flag (car vm-message-pointer)))) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
675 (not dont-create))) |
88137 | 676 |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
677 ;; add a veriable that is set to t when vm is active: |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
678 (if vm-use-spam-filter |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
679 (progn |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
680 (add-hook 'vm-mode-hook 'spam-filter-working-with-vm-func) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
681 (add-hook 'vm-quit-hook 'spam-filter-not-working-with-vm-func))) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
682 (defun spam-filter-working-with-vm-func () |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
683 (interactive) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
684 (setq spam-filter-working-with-vm t)) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
685 (defun spam-filter-not-working-with-vm-func () |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
686 (interactive) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
687 (setq spam-filter-working-with-vm nil)) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
688 |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
689 ;; activate bbdb-anti-spam measures for rmail or vm: |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
690 (if spam-filter-auto-delete-spam-bbdb-entries |
88137 | 691 (progn |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
692 ;; for rmail: |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
693 (if rmail-use-spam-filter |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
694 (progn |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
695 (add-hook 'rmail-delete-message-hook 'spam-filter-bbdb-auto-delete-spam-entries) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
696 (setq bbdb/mail-auto-create-p 'spam-filter-bbdb-dont-create-entries-for-deleted-messages))) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
697 ;; for vm: |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
698 (if vm-use-spam-filter |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
699 (progn |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
700 (defadvice vm-delete-message |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
701 (before advice-spam-filter-bbdb-auto-delete-spam-entries activate) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
702 (spam-filter-bbdb-auto-delete-spam-entries)) |
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
703 (setq bbdb/mail-auto-create-p 'spam-filter-bbdb-dont-create-entries-for-deleted-messages))) |
88137 | 704 )) |
705 | |
706 (provide 'rmail-spam-filter) | |
707 | |
88139
de90332b77e9
Add patches from Eli Tziperman <eli@beach.weizmann.ac.il>, and John Paul
Paul Reilly <pmr@pajato.com>
parents:
88137
diff
changeset
|
708 ;;; rmail-spam-fitler ends here |