annotate lisp/mail/rmail-spam-filter.el @ 88146:a64fe1ff909a

(rmail-make-summary-line): Function deleted. (rmail-new-summary): Make it work once again as in old version. (rmail-summary-get-summary): Call rmail-summary-line-decoder.
author Richard M. Stallman <rms@gnu.org>
date Mon, 27 Sep 2004 07:41:10 +0000
parents de90332b77e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
88137
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
1 ;;; rmail-spam-filter.el --- spam filter for rmail, the emacs mail reader.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
2
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
3 ;; Copyright (C) 2002
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
4 ;; Free Software Foundation, Inc.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
5 ;; Keywords: email, spam, filter, rmail
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
6 ;; Author: Eli Tziperman <eli@beach.weizmann.ac.il>
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
7
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
9
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
13 ;; any later version.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
14
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
18 ;; GNU General Public License for more details.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
19
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
24
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
25 ;;; Commentary:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
26 ;;; -----------
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
27
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
28 ;;; Automatically recognize and delete junk email before it is
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
29 ;;; displayed in rmail/rmail-summary. Spam emails are defined by
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
30 ;;; specifying one or more of the sender, subject and contents.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
31 ;;; URL: http://www.weizmann.ac.il/~eli/Downloads/rmail-spam-filter/
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
32
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
33 ;;; Usage:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
34 ;;; ------
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
35
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
36 ;;; put in your .emacs:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
37
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
38 ;;; (load "rmail-spam-filter.el")
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
39
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
40 ;;; and use customize (in rmail-spam-filter group) to:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
41
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
42 ;;; (*) turn on the variable rmail-use-spam-filter,
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
43
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
44 ;;; (*) specify in variable rmail-spam-definitions-alist what sender,
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
45 ;;; subject and contents make an email be considered spam.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
46
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
47 ;;; in addition, you may:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
48
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
49 ;;; (*) Block future mail with the subject or sender of a message
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
50 ;;; while reading it in RMAIL: just click on the "Spam" item on the
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
53 ;;; need to later also save the list of spam definitions using the
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
54 ;;; same menu item, or alternatively, see variable
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
55 ;;; `rmail-spam-filter-autosave-newly-added-spam-definitions'.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
56
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
57 ;;; (*) specify if blind-cc'ed mail (no "To:" header field) is to be
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
58 ;;; treated as spam (variable rmail-spam-no-blind-cc; Thanks to Ethan
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
59 ;;; Brown <ethan@gso.saic.com> for this).
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
60
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
61 ;;; (*) specify if rmail-spam-filter should ignore case of spam
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
62 ;;; definitions (variable rmail-spam-filter-ignore-case; Thanks to
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
63 ;;; Ethan Brown <ethan@gso.saic.com> for the suggestion).
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
64
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
65 ;;; (*) Specify a "white-list" of trusted senders. If any
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
66 ;;; rmail-spam-white-list string matches a substring of the "From"
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
67 ;;; header, the message is flagged as a valid, non-spam message (Ethan
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
68 ;;; Brown <ethan@gso.saic.com>).
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
77 ;;; (*) rmail spam filter also works with bbdb to prevent spam senders
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
80 ;;; in two ways: (a) bbdb is made not to auto-create entries for
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
81 ;;; messages that are deleted by the rmail-spam-filter, (b) when a
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
82 ;;; message is deleted in rmail, the user is offered to delete the
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
83 ;;; sender's bbdb entry as well _if_ it was created at the same day.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
84
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
92
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
93 (defgroup rmail-spam-filter nil
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
94 "Spam filter for RMAIL, the mail reader for Emacs."
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
95 :group 'rmail)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
96
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
97 (defcustom rmail-use-spam-filter nil
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
98 "*Non-nil to activate the rmail spam filter.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
99 Specify `rmail-spam-definitions-alist' to define what you consider spam
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
100 emails."
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
101 :type 'boolean
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
102 :group 'rmail-spam-filter )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
111 (defcustom rmail-spam-file "~/XRMAIL-SPAM"
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
112 "*Name of rmail file for optionally saving some of the spam.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
113 Spam may be either just deleted, or saved in a separate spam file to
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
114 be looked at at a later time. Whether the spam is just deleted or
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
115 also saved in a separete spam file is specified for each definition of
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
116 spam, as one of the fields of `rmail-spam-definitions-alist'"
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
117 :type 'string
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
118 :group 'rmail-spam-filter )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
119
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
120 (defcustom rmail-spam-no-blind-cc nil
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
121 "*Non-nil to treat blind CC (no To: header) as spam."
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
122 :type 'boolean
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
123 :group 'rmail-spam-filter )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
124
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
125 (defcustom rmail-spam-filter-ignore-case nil
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
126 "*Non-nil to ignore case in `rmail-spam-definitions-alist'."
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
127 :type 'boolean
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
128 :group 'rmail-spam-filter )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
129
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
130 (defcustom rmail-spam-filter-beep nil
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
131 "*Non-nil to beep if spam is found."
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
132 :type 'boolean
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
133 :group 'rmail-spam-filter )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
134
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
135 (defcustom rmail-spam-sleep-after-message 2.0
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
136 "*Seconds to wait after display of message that spam was found."
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
137 :type 'number
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
146 "*Non-nil to make sure no entries are made in bbdb for spam emails.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
147 This is done in two ways: (1) bbdb is made not to auto-create entries
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
148 for messages that are deleted by the `rmail-spam-filter', (2) when a
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
149 message is deleted in rmail, the user is offered to delete the
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
150 sender's bbdb entry as well if it was created at the same day. Note
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
151 that Emacs needs to be restarted after setting this option for it to
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
152 take an effect."
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
153 :type 'boolean
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
154 :group 'rmail-spam-filter )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
155
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
156 (defcustom rmail-spam-filter-autosave-newly-added-spam-definitions nil
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
157 "*Non-nil to auto save new spam entries.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
158 New entries entered via the spam menu bar item are then saved to
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
159 customization file immediately after being added via the menu bar, and
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
160 do not require explicitly saving the file after adding the new
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
161 entries."
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
162 :type 'boolean
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
163 :group 'rmail-spam-filter )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
164
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
165 (defcustom rmail-spam-white-list nil
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
166 "*List of strings to identify valid senders.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
167 If any rmail-spam-white-list string matches a substring of the 'From'
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
168 header, the message is flagged as a valid, non-spam message. Example:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
169 If your domain is emacs.com then including 'emacs.com' in your
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
170 rmail-spam-white-list would flag all mail from your colleagues as
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
171 valid."
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
172 :type '(repeat string)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
173 :group 'rmail-spam-filter )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
174
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
175 (defcustom rmail-spam-definitions-alist nil
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
176 "*Alist matching strings defining what messages are considered spam.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
177 Each definition may contain specifications of one or more of the
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
178 elements {subject, sender, recipients or contents}, as well as a
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
179 definition of what to do with the spam (action item). A spam e-mail
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
180 is defined as one that fits all of the specified elements of any one
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
181 of the spam definitions. The strings that specify spam subject,
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
182 sender, etc, may be regexp. For example, to specify that the subject
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
187 :type '(repeat
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
188 (list :format "%v"
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
189 (cons :format "%v" :value (from . "")
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
190 (const :format "" from)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
191 (string :tag "From" ""))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
192 (cons :format "%v" :value (to . "")
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
193 (const :format "" to)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
194 (string :tag "To" ""))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
195 (cons :format "%v" :value (subject . "")
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
196 (const :format "" subject)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
197 (string :tag "Subject" ""))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
198 (cons :format "%v" :value (contents . "")
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
199 (const :format "" contents)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
200 (string :tag "Contents" ""))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
201 (cons :format "%v" :value (action . output-and-delete)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
202 (const :format "" action)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
203 (choice :tag "Action selection"
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
204 (const :tag "output to spam folder and delete" output-and-delete)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
205 (const :tag "delete spam" delete-spam)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
206 ))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
207 ))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
208 :group 'rmail-spam-filter)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
209
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
210 (defvar rmail-spam-filter-scanning-messages-now nil
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
217
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
218 (defun rmail-spam-filter (msg)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
219 "Return nil if msg is spam based on rmail-spam-definitions-alist.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
220 If spam, optionally output msg to a file `rmail-spam-file' and delete
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
221 it from rmail file. Called for each new message retrieved by
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
222 `rmail-get-new-mail'."
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
223
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
224 (let ((old-message)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
225 (return-value)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
226 (this-is-a-spam-email)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
227 (maybe-spam)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
228 (message-sender)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
229 (message-recipients)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
230 (message-subject)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
231 (num-spam-definition-elements)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
232 (num-element 0)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
233 (exit-while-loop nil)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
234 (saved-case-fold-search case-fold-search)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
237
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
238 ;; make sure bbdb does not create entries for messages while spam
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
244 ;; filter is running, so that deletion of rmail messages should be
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
245 ;; ignored for now:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
246 (setq rmail-spam-filter-scanning-messages-now t)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
247 (save-excursion
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
248 (save-restriction
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
251 ;; Narrow buffer to header of message and get Sender and
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
264 ;; Find number of spam-definition elements in the list
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
268
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
271
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
272 ;; Check for blind CC condition. Set vars such that while
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
273 ;; loop will be bypassed and spam condition will trigger (EDB)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
274 (if (and rmail-spam-no-blind-cc
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
293 ;; scan all elements of the list rmail-spam-definitions-alist
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
294 (while (and
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
295 (< num-element num-spam-definition-elements)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
296 (not exit-while-loop))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
297 (progn
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
298 ;; Initialize maybe-spam which is set to t in one of two
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
299 ;; cases: (1) unspecified definition-elements are found in
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
300 ;; rmail-spam-definitions-alist, (2) empty field is found
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
301 ;; in the message being scanned (e.g. empty subject,
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
302 ;; sender, recipients, etc). The variable is set to nil
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
303 ;; if a non empty field of the scanned message does not
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
304 ;; match a specified field in
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
305 ;; rmail-spam-definitions-alist.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
306 (setq maybe-spam t)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
307 ;; initialize this-is-a-spam-email to nil. This variable
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
308 ;; is set to t if one of the spam definitions matches a
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
309 ;; field in the scanned message.
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
310 (setq this-is-a-spam-email nil)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
311
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
312 ;; start scanning incoming message:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
313 ;;---------------------------------
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
314
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
315 ;; if sender field is not specified in message being
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
316 ;; scanned, AND if "from" field does not appear in spam
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
317 ;; definitions for this element, this may still be spam
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
318 ;; due to another element...
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
319 (if (and (not message-sender)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
320 (string-match
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
321 (cdr (assoc 'from (nth num-element
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
322 rmail-spam-definitions-alist))) ""))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
323 (setq maybe-spam t)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
324 ;; ... else, if message-sender does appear in the
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
325 ;; message, and it also appears in the spam definition
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
326 ;; list, it is potentially spam:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
327 (if (and message-sender
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
328 (string-match
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
329 (cdr (assoc 'from (nth num-element
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
330 rmail-spam-definitions-alist)))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
331 message-sender)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
332 )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
333 (setq this-is-a-spam-email t)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
334 (setq maybe-spam nil)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
335 )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
336 )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
337 ;; next, if spam was not ruled out already, check recipients:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
338 (if maybe-spam
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
339 ;; if To field does not exist AND is not specified,
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
340 ;; this may still be spam due to another element...
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
341 (if (and (not message-recipients)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
342 (string-match
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
343 (cdr (assoc 'to
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
344 (nth num-element
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
345 rmail-spam-definitions-alist))) ""))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
346 (setq maybe-spam t)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
347 ;; ... else, if To field does appear in the message,
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
348 ;; and it also appears in spam definition list, this
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
349 ;; is potentially a spam:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
350 (if (and message-recipients
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
351 (string-match
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
352 (cdr (assoc 'to (nth num-element
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
353 rmail-spam-definitions-alist)))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
354 message-recipients)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
355 )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
356 (setq this-is-a-spam-email t)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
357 (setq maybe-spam nil)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
358 )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
359 )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
360 )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
361 ;; next, if spam was not ruled out already, check subject:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
362 (if maybe-spam
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
363 ;; if subject field does not exist AND is not
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
364 ;; specified, this may still be spam due to another
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
365 ;; element...
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
366 (if (and (not message-subject)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
367 (string-match
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
368 (cdr (assoc 'subject
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
369 (nth num-element
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
370 rmail-spam-definitions-alist)))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
371 ""))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
372 (setq maybe-spam t)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
373 ;; ... else, if subject field does appear in the
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
374 ;; message, and it also appears in the spam
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
375 ;; definition list, this is potentially a spam:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
376 (if (and message-subject
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
377 (string-match
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
378 (cdr (assoc 'subject (nth num-element
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
379 rmail-spam-definitions-alist)))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
380 message-subject)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
381 )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
382 (setq this-is-a-spam-email t)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
383 (setq maybe-spam nil)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
384 )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
385 )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
386 )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
387 ;; next, if spam was not ruled out already, check
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
388 ;; contents: if contents field is not specified, this may
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
389 ;; still be spam due to another element...
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
390 (if maybe-spam
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
391 (if (string-match
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
392 (cdr (assoc 'contents
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
393 (nth num-element
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
394 rmail-spam-definitions-alist))) "")
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
395 (setq maybe-spam t)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
396 ;; ... else, check to see if it appears in spam
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
397 ;; definition:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
398 (if (string-match
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
399 (cdr (assoc 'contents
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
400 (nth num-element
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
401 rmail-spam-definitions-alist)))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
402 (buffer-substring
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
403 (rmail-msgbeg msg) (rmail-msgend msg)))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
404 (setq this-is-a-spam-email t)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
405 (setq maybe-spam nil)))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
406 )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
407 ;; if the search in rmail-spam-definitions-alist found
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
408 ;; that this email is spam, output the email to the spam
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
409 ;; rmail file, mark the email for deletion, leave the
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
410 ;; while loop and return nil so that an rmail summary line
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
411 ;; wont be displayed for this message:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
412 (if (and this-is-a-spam-email maybe-spam)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
413 ;; found that this is spam, no need to look at the
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
414 ;; rest of the rmail-spam-definitions-alist, exit
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
415 ;; loop:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
416 (setq exit-while-loop t)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
417 ;; else, spam was not yet found, increment number of
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
418 ;; element in rmail-spam-definitions-alist and proceed
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
419 ;; to next element:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
420 (setq num-element (+ num-element 1)))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
421 )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
422 )
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
423 (if (and this-is-a-spam-email maybe-spam)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
424 (progn
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
425 ;;(message "Found spam!")
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
426 ;;(ding 1) (sleep-for 2)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
427
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
428 ;; temprarily set rmail-current-message in order to
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
429 ;; output and delete the spam msg if needed:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
430 (setq save-current-msg rmail-current-message)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
431 (setq rmail-current-message msg)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
432 ;; check action item and rmail-spam-definitions-alist
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
433 ;; and do it:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
434 (cond
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
435 ((equal (cdr (assoc 'action
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
436 (nth num-element rmail-spam-definitions-alist)))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
437 'output-and-delete)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
444 ((equal (cdr (assoc 'action
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
445 (nth num-element rmail-spam-definitions-alist)))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
446 'delete-spam)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
447 (progn
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
448 (rmail-delete-message)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
449 ))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
454 ;; set return value. These lines must be last in the
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
455 ;; function, so that they will determine the value
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
456 ;; returned by rmail-spam-filter:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
459 (setq case-fold-search saved-case-fold-search)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
460 (setq rmail-spam-filter-scanning-messages-now nil)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
461 return-value))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
462
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
463
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
464 ;; define functions for interactively adding sender/subject of a
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
465 ;; specific message to the spam definitions while reading it, using
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
466 ;; the menubar:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
467 (defun rmail-spam-filter-add-subject-to-spam-list ()
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
468 (interactive)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
469 (set-buffer rmail-buffer)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
470 (let ((message-subject))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
471 (setq message-subject (mail-fetch-field "Subject"))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
472 ;; note the use of a backquote and comma on the subject line here,
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
473 ;; to make sure message-subject is actually evaluated and its value
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
474 ;; substituted:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
475 (add-to-list 'rmail-spam-definitions-alist
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
476 (list '(from . "")
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
477 '(to . "")
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
478 `(subject . ,message-subject)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
479 '(contents . "")
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
480 '(action . output-and-delete))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
481 t)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
482 (customize-mark-to-save 'rmail-spam-definitions-alist)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
483 (if rmail-spam-filter-autosave-newly-added-spam-definitions
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
484 (progn
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
485 (custom-save-all)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
486 (message (concat "added subject \n <<< \n" message-subject
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
487 " \n >>> \n to list of spam definitions. \n"
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
488 "and saved the spam definitions to file.")))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
489 (message (concat "added subject \n <<< \n" message-subject
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
490 " \n >>> \n to list of spam definitions. \n"
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
491 "Don't forget to save the spam definitions to file using the spam menu"))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
492 )))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
493
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
494 (defun rmail-spam-filter-add-sender-to-spam-list ()
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
495 (interactive)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
496 (set-buffer rmail-buffer)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
497 (let ((message-sender))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
498 (setq message-sender (mail-fetch-field "From"))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
499 ;; note the use of a backquote and comma on the "from" line here,
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
500 ;; to make sure message-sender is actually evaluated and its value
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
501 ;; substituted:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
502 (add-to-list 'rmail-spam-definitions-alist
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
503 (list `(from . ,message-sender)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
504 '(to . "")
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
505 '(subject . "")
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
506 '(contents . "")
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
507 '(action . output-and-delete))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
508 t)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
509 (customize-mark-to-save 'rmail-spam-definitions-alist)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
510 (if rmail-spam-filter-autosave-newly-added-spam-definitions
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
511 (progn
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
512 (custom-save-all)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
513 (message (concat "added sender \n <<< \n" message-sender
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
514 " \n >>> \n to list of spam definitions. \n"
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
515 "and saved the spam definitions to file.")))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
516 (message (concat "added sender \n <<< \n " message-sender
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
517 " \n >>> \n to list of spam definitions."
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
518 "Don't forget to save the spam definitions to file using the spam menu"))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
519 )))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
520
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
521
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
522 (defun rmail-spam-filter-add-region-to-spam-list ()
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
523 "Add the region makred by user in the rmail buffer to the list of
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
524 spam definitions as a contents field."
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
525 (interactive)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
526 (set-buffer rmail-buffer)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
527 (let ((region-to-spam-list))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
528 ;; check if region is inactive or has zero size:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
529 (if (not (and mark-active (not (= (region-beginning) (region-end)))))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
530 ;; if inactive, print error message:
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
563
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
564
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
565 (defun rmail-spam-filter-customize-spam-definitions ()
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
566 (interactive)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
567 (customize-variable (quote rmail-spam-definitions-alist)))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
568
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
569 (defun rmail-spam-filter-customize-group ()
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
570 (interactive)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
571 (customize-group (quote rmail-spam-filter)))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
572
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
573 (defun rmail-spam-custom-save-all ()
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
574 (interactive)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
575 (custom-save-all))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
576
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
577 ;; add the actual menu items and keyboard shortcuts to both rmail and
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
578 ;; rmail-summary menu-bars::
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
579 (define-key rmail-summary-mode-map [menu-bar spam]
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
580 (cons "Spam" (make-sparse-keymap "Spam")))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
581 (define-key rmail-mode-map [menu-bar spam]
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
582 (cons "Spam" (make-sparse-keymap "Spam")))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
583
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
584 (define-key rmail-summary-mode-map [menu-bar spam customize-group]
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
585 '("Browse customizations of rmail spam filter" . rmail-spam-filter-customize-group))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
586 (define-key rmail-mode-map [menu-bar spam customize-group]
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
587 '("Browse customizations of rmail spam filter" . rmail-spam-filter-customize-group))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
588 (define-key rmail-summary-mode-map "\C-cSg" 'rmail-spam-filter-customize-group)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
589 (define-key rmail-mode-map "\C-cSg" 'rmail-spam-filter-customize-group)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
590
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
591 (define-key rmail-summary-mode-map [menu-bar spam customize-spam-list]
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
592 '("Customize list of spam definitions" . rmail-spam-filter-customize-spam-definitions))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
593 (define-key rmail-mode-map [menu-bar spam customize-spam-list]
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
594 '("Customize list of spam definitions" . rmail-spam-filter-customize-spam-definitions))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
595 (define-key rmail-summary-mode-map "\C-cSd" 'rmail-spam-filter-customize-spam-definitions)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
596 (define-key rmail-mode-map "\C-cSd" 'rmail-spam-filter-customize-spam-definitions)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
597
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
598 (define-key rmail-summary-mode-map [menu-bar spam lambda] '("----"))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
599 (define-key rmail-mode-map [menu-bar spam lambda] '("----"))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
600
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
601 (define-key rmail-summary-mode-map [menu-bar spam my-custom-save-all]
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
602 '("save newly added spam definitions to customization file" . rmail-spam-custom-save-all))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
603 (define-key rmail-mode-map [menu-bar spam my-custom-save-all]
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
604 '("save newly added spam definitions to customization file" . rmail-spam-custom-save-all))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
605 (define-key rmail-summary-mode-map "\C-cSa" 'rmail-spam-custom-save-all)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
606 (define-key rmail-mode-map "\C-cSa" 'rmail-spam-custom-save-all)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
607
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
608 (define-key rmail-summary-mode-map [menu-bar spam add-region-to-spam-list]
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
609 '("add region to spam list" . rmail-spam-filter-add-region-to-spam-list))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
610 (define-key rmail-mode-map [menu-bar spam add-region-to-spam-list]
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
611 '("add region to spam list" . rmail-spam-filter-add-region-to-spam-list))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
612 (define-key rmail-summary-mode-map "\C-cSn" 'rmail-spam-filter-add-region-to-spam-list)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
613 (define-key rmail-mode-map "\C-cSn" 'rmail-spam-filter-add-region-to-spam-list)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
614
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
615 (define-key rmail-summary-mode-map [menu-bar spam add-sender-to-spam-list]
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
616 '("add sender to spam list" . rmail-spam-filter-add-sender-to-spam-list))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
617 (define-key rmail-mode-map [menu-bar spam add-sender-to-spam-list]
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
618 '("add sender to spam list" . rmail-spam-filter-add-sender-to-spam-list))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
619 (define-key rmail-summary-mode-map "\C-cSr" 'rmail-spam-filter-add-sender-to-spam-list)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
620 (define-key rmail-mode-map "\C-cSr" 'rmail-spam-filter-add-sender-to-spam-list)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
621
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
622 (define-key rmail-summary-mode-map [menu-bar spam add-subject-to-spam-list]
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
623 '("add subject to spam list" . rmail-spam-filter-add-subject-to-spam-list))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
624 (define-key rmail-mode-map [menu-bar spam add-subject-to-spam-list]
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
625 '("add subject to spam list" . rmail-spam-filter-add-subject-to-spam-list))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
626 (define-key rmail-summary-mode-map "\C-cSt" 'rmail-spam-filter-add-subject-to-spam-list)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
627 (define-key rmail-mode-map "\C-cSt" 'rmail-spam-filter-add-subject-to-spam-list)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
628
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
631 "When deleting a message in RMAIL, check to see if the bbdb entry
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
632 was created today, and if it was, prompt to delete it too. This function
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
635 (interactive)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
636 (require 'bbdb-hooks)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
637 (if (not rmail-spam-filter-scanning-messages-now)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
638 (if (get-buffer "*BBDB*")
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
639 (save-excursion
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
640 (set-buffer (get-buffer "*BBDB*"))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
641 (if (bbdb-current-record)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
642 (if (equal
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
643 (format-time-string bbdb-time-internal-format (current-time))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
644 (bbdb-record-getprop (bbdb-current-record) 'creation-date))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
645 (bbdb-delete-current-record (bbdb-current-record))))))))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
654 entries of mail that is deleted. However, if one scrolls back to the deleted
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
655 messages, then the sender is again added to the bbdb. This function
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
656 prevents this. Also, don't create entries for messages in the `rmail-spam-file'."
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
657 (interactive)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
704 ))
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
705
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
706 (provide 'rmail-spam-filter)
cb307edb1d27 Initial commit.
Paul Reilly <pmr@pajato.com>
parents:
diff changeset
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