comparison lisp/mh-e/mh-junk.el @ 67758:6b063593fdad

Follow Emacs coding conventions. Use default setting of emacs-lisp-docstring-fill-column which is 65.
author Bill Wohler <wohler@newt.com>
date Fri, 23 Dec 2005 07:40:40 +0000
parents 3a8785724cca
children 9c3504ae6060
comparison
equal deleted inserted replaced
67757:488b4dbc7482 67758:6b063593fdad
39 ;; Interactive functions callable from the folder buffer 39 ;; Interactive functions callable from the folder buffer
40 ;;;###mh-autoload 40 ;;;###mh-autoload
41 (defun mh-junk-blacklist (range) 41 (defun mh-junk-blacklist (range)
42 "Blacklist RANGE as spam. 42 "Blacklist RANGE as spam.
43 43
44 This command trains the spam program in use (see the option `mh-junk-program') 44 This command trains the spam program in use (see the option
45 with the content of RANGE and then handles the message(s) as specified by the 45 `mh-junk-program') with the content of RANGE and then handles the
46 option `mh-junk-disposition'. 46 message(s) as specified by the option `mh-junk-disposition'.
47 47
48 Check the documentation of `mh-interactive-range' to see how RANGE is read in 48 Check the documentation of `mh-interactive-range' to see how RANGE is
49 interactive use. 49 read in interactive use.
50 50
51 For more information about using your particular spam fighting program, see: 51 For more information about using your particular spam fighting
52 program, see:
52 53
53 - `mh-spamassassin-blacklist' 54 - `mh-spamassassin-blacklist'
54 - `mh-bogofilter-blacklist' 55 - `mh-bogofilter-blacklist'
55 - `mh-spamprobe-blacklist'" 56 - `mh-spamprobe-blacklist'"
56 (interactive (list (mh-interactive-range "Blacklist"))) 57 (interactive (list (mh-interactive-range "Blacklist")))
78 79
79 ;;;###mh-autoload 80 ;;;###mh-autoload
80 (defun mh-junk-whitelist (range) 81 (defun mh-junk-whitelist (range)
81 "Whitelist RANGE as ham. 82 "Whitelist RANGE as ham.
82 83
83 This command reclassifies the RANGE as ham if it were incorrectly classified 84 This command reclassifies the RANGE as ham if it were incorrectly
84 as spam (see the option `mh-junk-program'). It then refiles the message into 85 classified as spam (see the option `mh-junk-program'). It then
85 the \"+inbox\" folder. 86 refiles the message into the \"+inbox\" folder.
86 87
87 Check the documentation of `mh-interactive-range' to see how RANGE is read in 88 Check the documentation of `mh-interactive-range' to see how
88 interactive use." 89 RANGE is read in interactive use."
89 (interactive (list (mh-interactive-range "Whitelist"))) 90 (interactive (list (mh-interactive-range "Whitelist")))
90 (let ((whitelist-func (nth 2 (assoc mh-junk-choice mh-junk-function-alist)))) 91 (let ((whitelist-func (nth 2 (assoc mh-junk-choice mh-junk-function-alist))))
91 (unless whitelist-func 92 (unless whitelist-func
92 (error "Customize `mh-junk-program' appropriately")) 93 (error "Customize `mh-junk-program' appropriately"))
93 (mh-iterate-on-range msg range 94 (mh-iterate-on-range msg range
105 (defvar mh-sa-learn-executable (executable-find "sa-learn")) 106 (defvar mh-sa-learn-executable (executable-find "sa-learn"))
106 107
107 (defun mh-spamassassin-blacklist (msg) 108 (defun mh-spamassassin-blacklist (msg)
108 "Blacklist MSG with SpamAssassin. 109 "Blacklist MSG with SpamAssassin.
109 110
110 SpamAssassin is one of the more popular spam filtering programs. Get it from 111 SpamAssassin is one of the more popular spam filtering programs. Get
111 your local distribution or from http://spamassassin.org/. 112 it from your local distribution or from http://spamassassin.org/.
112 113
113 To use SpamAssassin, add the following recipes to `.procmailrc': 114 To use SpamAssassin, add the following recipes to `.procmailrc':
114 115
115 MAILDIR=$HOME/`mhparam Path` 116 MAILDIR=$HOME/`mhparam Path`
116 117
127 * ^X-Spam-Status: Yes 128 * ^X-Spam-Status: Yes
128 spam/. 129 spam/.
129 130
130 If you don't use `spamc', use `spamassassin -P -a'. 131 If you don't use `spamc', use `spamassassin -P -a'.
131 132
132 Note that one of the recipes above throws away messages with a score greater 133 Note that one of the recipes above throws away messages with a score
133 than or equal to 10. Here's how you can determine a value that works best for 134 greater than or equal to 10. Here's how you can determine a value that
134 you. 135 works best for you.
135 136
136 First, run `spamassassin -t' on every mail message in your archive and use 137 First, run `spamassassin -t' on every mail message in your archive and
137 Gnumeric to verify that the average plus the standard deviation of good mail 138 use Gnumeric to verify that the average plus the standard deviation of
138 is under 5, the SpamAssassin default for \"spam\". 139 good mail is under 5, the SpamAssassin default for \"spam\".
139 140
140 Using Gnumeric, sort the messages by score and view the messages with the 141 Using Gnumeric, sort the messages by score and view the messages with
141 highest score. Determine the score which encompasses all of your interesting 142 the highest score. Determine the score which encompasses all of your
142 messages and add a couple of points to be conservative. Add that many dots to 143 interesting messages and add a couple of points to be conservative.
143 the `X-Spam-Level:' header field above to send messages with that score down 144 Add that many dots to the `X-Spam-Level:' header field above to send
144 the drain. 145 messages with that score down the drain.
145 146
146 In the example above, messages with a score of 5-9 are set aside in the 147 In the example above, messages with a score of 5-9 are set aside in
147 `+spam' folder for later review. The major weakness of rules-based filters is 148 the `+spam' folder for later review. The major weakness of rules-based
148 a plethora of false positives so it is worthwhile to check. 149 filters is a plethora of false positives so it is worthwhile to check.
149 150
150 If SpamAssassin classifies a message incorrectly, or is unsure, you can use 151 If SpamAssassin classifies a message incorrectly, or is unsure, you
151 the MH-E commands \\[mh-junk-blacklist] and \\[mh-junk-whitelist]. 152 can use the MH-E commands \\[mh-junk-blacklist] and
153 \\[mh-junk-whitelist].
152 154
153 The \\[mh-junk-blacklist] command adds a `blacklist_from' entry to 155 The \\[mh-junk-blacklist] command adds a `blacklist_from' entry to
154 `~/spamassassin/user_prefs', deletes the message, and sends the message to the 156 `~/spamassassin/user_prefs', deletes the message, and sends the
155 Razor, so that others might not see this spam. If the `sa-learn' command is 157 message to the Razor, so that others might not see this spam. If the
156 available, the message is also recategorized as spam. 158 `sa-learn' command is available, the message is also recategorized as
159 spam.
157 160
158 The \\[mh-junk-whitelist] command adds a `whitelist_from' rule to the 161 The \\[mh-junk-whitelist] command adds a `whitelist_from' rule to the
159 `~/.spamassassin/user_prefs' file. If the `sa-learn' command is available, the 162 `~/.spamassassin/user_prefs' file. If the `sa-learn' command is
160 message is also recategorized as ham. 163 available, the message is also recategorized as ham.
161 164
162 Over time, you'll observe that the same host or domain occurs repeatedly in 165 Over time, you'll observe that the same host or domain occurs
163 the `blacklist_from' entries, so you might think that you could avoid future 166 repeatedly in the `blacklist_from' entries, so you might think that
164 spam by blacklisting all mail from a particular domain. The utility function 167 you could avoid future spam by blacklisting all mail from a particular
165 `mh-spamassassin-identify-spammers' helps you do precisely that. This function 168 domain. The utility function `mh-spamassassin-identify-spammers' helps
166 displays a frequency count of the hosts and domains in the `blacklist_from' 169 you do precisely that. This function displays a frequency count of the
167 entries from the last blank line in `~/.spamassassin/user_prefs' to the end of 170 hosts and domains in the `blacklist_from' entries from the last blank
168 the file. This information can be used so that you can replace multiple 171 line in `~/.spamassassin/user_prefs' to the end of the file. This
172 information can be used so that you can replace multiple
169 `blacklist_from' entries with a single wildcard entry such as: 173 `blacklist_from' entries with a single wildcard entry such as:
170 174
171 blacklist_from *@*amazingoffersdirect2u.com 175 blacklist_from *@*amazingoffersdirect2u.com
172 176
173 In versions of SpamAssassin (2.50 and on) that support a Bayesian classifier, 177 In versions of SpamAssassin (2.50 and on) that support a Bayesian
174 \\[mh-junk-blacklist] uses the `sa-learn' program to recategorize the message 178 classifier, \\[mh-junk-blacklist] uses the `sa-learn' program to
175 as spam. Neither MH-E, nor SpamAssassin, rebuilds the database after adding 179 recategorize the message as spam. Neither MH-E, nor SpamAssassin,
176 words, so you will need to run `sa-learn --rebuild' periodically. This can be 180 rebuilds the database after adding words, so you will need to run
177 done by adding the following to your crontab: 181 `sa-learn --rebuild' periodically. This can be done by adding the
182 following to your crontab:
178 183
179 0 * * * * sa-learn --rebuild > /dev/null 2>&1" 184 0 * * * * sa-learn --rebuild > /dev/null 2>&1"
180 (unless mh-spamassassin-executable 185 (unless mh-spamassassin-executable
181 (error "Unable to find the spamassassin executable")) 186 (error "Unable to find the spamassassin executable"))
182 (let ((current-folder mh-current-folder) 187 (let ((current-folder mh-current-folder)
208 (message "Blacklisting message %d...not done (from my address)" msg))))) 213 (message "Blacklisting message %d...not done (from my address)" msg)))))
209 214
210 (defun mh-spamassassin-whitelist (msg) 215 (defun mh-spamassassin-whitelist (msg)
211 "Whitelist MSG with SpamAssassin. 216 "Whitelist MSG with SpamAssassin.
212 217
213 The \\[mh-junk-whitelist] command adds a `whitelist_from' rule to the 218 The \\[mh-junk-whitelist] command adds a `whitelist_from' rule to
214 `~/.spamassassin/user_prefs' file. If the `sa-learn' command is available, the 219 the `~/.spamassassin/user_prefs' file. If the `sa-learn' command
215 message is also recategorized as ham. 220 is available, the message is also recategorized as ham.
216 221
217 See `mh-spamassassin-blacklist' for more information." 222 See `mh-spamassassin-blacklist' for more information."
218 (unless mh-spamassassin-executable 223 (unless mh-spamassassin-executable
219 (error "Unable to find the spamassassin executable")) 224 (error "Unable to find the spamassassin executable"))
220 (let ((msg-file (mh-msg-filename msg mh-current-folder)) 225 (let ((msg-file (mh-msg-filename msg mh-current-folder))
261 (kill-buffer nil))))) 266 (kill-buffer nil)))))
262 267
263 (defun mh-spamassassin-identify-spammers () 268 (defun mh-spamassassin-identify-spammers ()
264 "Identify spammers who are repeat offenders. 269 "Identify spammers who are repeat offenders.
265 270
266 This function displays a frequency count of the hosts and domains in the 271 This function displays a frequency count of the hosts and domains
267 `blacklist_from' entries from the last blank line in 272 in the `blacklist_from' entries from the last blank line in
268 `~/.spamassassin/user_prefs' to the end of the file. This information can be 273 `~/.spamassassin/user_prefs' to the end of the file. This
269 used so that you can replace multiple `blacklist_from' entries with a single 274 information can be used so that you can replace multiple
270 wildcard entry such as: 275 `blacklist_from' entries with a single wildcard entry such as:
271 276
272 blacklist_from *@*amazingoffersdirect2u.com" 277 blacklist_from *@*amazingoffersdirect2u.com"
273 (interactive) 278 (interactive)
274 (let* ((file (expand-file-name "~/.spamassassin/user_prefs")) 279 (let* ((file (expand-file-name "~/.spamassassin/user_prefs"))
275 (domains (make-hash-table :test 'equal))) 280 (domains (make-hash-table :test 'equal)))
310 (defvar mh-bogofilter-executable (executable-find "bogofilter")) 315 (defvar mh-bogofilter-executable (executable-find "bogofilter"))
311 316
312 (defun mh-bogofilter-blacklist (msg) 317 (defun mh-bogofilter-blacklist (msg)
313 "Blacklist MSG with bogofilter. 318 "Blacklist MSG with bogofilter.
314 319
315 Bogofilter is a Bayesian spam filtering program. Get it from your local 320 Bogofilter is a Bayesian spam filtering program. Get it from your
316 distribution or from http://bogofilter.sourceforge.net/. 321 local distribution or from http://bogofilter.sourceforge.net/.
317 322
318 Bogofilter is taught by running: 323 Bogofilter is taught by running:
319 324
320 bogofilter -n < good-message 325 bogofilter -n < good-message
321 326
322 on every good message, and 327 on every good message, and
323 328
324 bogofilter -s < spam-message 329 bogofilter -s < spam-message
325 330
326 on every spam message. This is called a full training; three other 331 on every spam message. This is called a full training; three other
327 training methods are described in the FAQ that is distributed with bogofilter. 332 training methods are described in the FAQ that is distributed with
328 Note that most Bayesian filters need 1000 to 5000 of each type of message to 333 bogofilter. Note that most Bayesian filters need 1000 to 5000 of each
329 start doing a good job. 334 type of message to start doing a good job.
330 335
331 To use bogofilter, add the following recipes to `.procmailrc': 336 To use bogofilter, add the following recipes to `.procmailrc':
332 337
333 MAILDIR=$HOME/`mhparam Path` 338 MAILDIR=$HOME/`mhparam Path`
334 339
342 347
343 :0: 348 :0:
344 * ^X-Bogosity: Unsure, tests=bogofilter 349 * ^X-Bogosity: Unsure, tests=bogofilter
345 spam/unsure/. 350 spam/unsure/.
346 351
347 If bogofilter classifies a message incorrectly, or is unsure, you can use the 352 If bogofilter classifies a message incorrectly, or is unsure, you can
348 MH-E commands \\[mh-junk-blacklist] and \\[mh-junk-whitelist] to update 353 use the MH-E commands \\[mh-junk-blacklist] and \\[mh-junk-whitelist]
349 bogofilter's training. 354 to update bogofilter's training.
350 355
351 The \"Bogofilter FAQ\" suggests that you run the following 356 The \"Bogofilter FAQ\" suggests that you run the following
352 occasionally to shrink the database: 357 occasionally to shrink the database:
353 358
354 bogoutil -d wordlist.db | bogoutil -l wordlist.db.new 359 bogoutil -d wordlist.db | bogoutil -l wordlist.db.new
397 402
398 :0: 403 :0:
399 *^X-SpamProbe: SPAM 404 *^X-SpamProbe: SPAM
400 spam/. 405 spam/.
401 406
402 If SpamProbe classifies a message incorrectly, you can use the MH-E commands 407 If SpamProbe classifies a message incorrectly, you can use the
403 \\[mh-junk-blacklist] and \\[mh-junk-whitelist] to update SpamProbe's 408 MH-E commands \\[mh-junk-blacklist] and \\[mh-junk-whitelist] to
404 training." 409 update SpamProbe's training."
405 (unless mh-spamprobe-executable 410 (unless mh-spamprobe-executable
406 (error "Unable to find the spamprobe executable")) 411 (error "Unable to find the spamprobe executable"))
407 (let ((msg-file (mh-msg-filename msg mh-current-folder))) 412 (let ((msg-file (mh-msg-filename msg mh-current-folder)))
408 (call-process mh-spamprobe-executable msg-file mh-junk-background 413 (call-process mh-spamprobe-executable msg-file mh-junk-background
409 nil "spam"))) 414 nil "spam")))