annotate lisp/mail/rmail-spam-filter.el @ 50419:27e134f43171

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