Mercurial > emacs
comparison lisp/mh-e/mh-junk.el @ 73924:63fc0820b362
mh-junk.el (mh-spamassassin-blacklist, mh-spamassassin-whitelist):
use mh-junk-background consistently in call-process calls.
(mh-bogofilter-blacklist, mh-bogofilter-whitelist,
mh-spamprobe-blacklist, mh-spamprobe-whitelist): use
with-current-buffer so the right thing happens if
mh-junk-background is t. (closes SF #1594802).
mh-e.el (mh-junk-background): document that On value is 0;
t may be used for debugging.
author | Stephen Gildea <gildea@stop.mail-abuse.org> |
---|---|
date | Sat, 11 Nov 2006 20:20:28 +0000 |
parents | 1e5bc57805bc |
children | d67b3c1597d8 |
comparison
equal
deleted
inserted
replaced
73923:9ebe2e5d0079 | 73924:63fc0820b362 |
---|---|
193 (unless mh-spamassassin-executable | 193 (unless mh-spamassassin-executable |
194 (error "Unable to find the spamassassin executable")) | 194 (error "Unable to find the spamassassin executable")) |
195 (let ((current-folder mh-current-folder) | 195 (let ((current-folder mh-current-folder) |
196 (msg-file (mh-msg-filename msg mh-current-folder)) | 196 (msg-file (mh-msg-filename msg mh-current-folder)) |
197 (sender)) | 197 (sender)) |
198 (save-excursion | 198 (message "Reporting message %d..." msg) |
199 (message "Reporting message %d..." msg) | 199 (mh-truncate-log-buffer) |
200 (mh-truncate-log-buffer) | 200 ;; Put call-process output in log buffer if we are saving it |
201 (call-process mh-spamassassin-executable msg-file mh-log-buffer nil | 201 ;; (this happens if mh-junk-background is t). |
202 (with-current-buffer mh-log-buffer | |
203 (call-process mh-spamassassin-executable msg-file mh-junk-background nil | |
202 ;;"--report" "--remove-from-whitelist" | 204 ;;"--report" "--remove-from-whitelist" |
203 "-r" "-R") ; spamassassin V2.20 | 205 "-r" "-R") ; spamassassin V2.20 |
204 (when mh-sa-learn-executable | 206 (when mh-sa-learn-executable |
205 (message "Recategorizing this message as spam...") | 207 (message "Recategorizing message %d as spam..." msg) |
206 (call-process mh-sa-learn-executable msg-file mh-log-buffer nil | 208 (mh-truncate-log-buffer) |
207 "--single" "--spam" "--local" "--no-rebuild")) | 209 (call-process mh-sa-learn-executable msg-file mh-junk-background nil |
208 (message "Blacklisting message %d..." msg) | 210 "--single" "--spam" "--local" "--no-rebuild"))) |
209 (set-buffer (get-buffer-create mh-temp-buffer)) | 211 (message "Blacklisting sender of message %d..." msg) |
212 (with-current-buffer (get-buffer-create mh-temp-buffer) | |
210 (erase-buffer) | 213 (erase-buffer) |
211 (call-process (expand-file-name mh-scan-prog mh-progs) | 214 (call-process (expand-file-name mh-scan-prog mh-progs) |
212 nil mh-junk-background nil | 215 nil t nil |
213 (format "%s" msg) current-folder | 216 (format "%d" msg) current-folder |
214 "-format" "%<(mymbox{from})%|%(addr{from})%>") | 217 "-format" "%<(mymbox{from})%|%(addr{from})%>") |
215 (goto-char (point-min)) | 218 (goto-char (point-min)) |
216 (if (search-forward-regexp "^\\(.+\\)$" nil t) | 219 (if (search-forward-regexp "^\\(.+\\)$" nil t) |
217 (progn | 220 (progn |
218 (setq sender (match-string 0)) | 221 (setq sender (match-string 0)) |
219 (mh-spamassassin-add-rule "blacklist_from" sender) | 222 (mh-spamassassin-add-rule "blacklist_from" sender) |
220 (message "Blacklisting message %d...done" msg)) | 223 (message "Blacklisting sender of message %d...done" msg)) |
221 (message "Blacklisting message %d...not done (from my address)" msg))))) | 224 (message "Blacklisting sender of message %d...not done (from my address)" msg))))) |
222 | 225 |
223 ;;;###mh-autoload | 226 ;;;###mh-autoload |
224 (defun mh-spamassassin-whitelist (msg) | 227 (defun mh-spamassassin-whitelist (msg) |
225 "Whitelist MSG with SpamAssassin. | 228 "Whitelist MSG with SpamAssassin. |
226 | 229 |
232 (unless mh-spamassassin-executable | 235 (unless mh-spamassassin-executable |
233 (error "Unable to find the spamassassin executable")) | 236 (error "Unable to find the spamassassin executable")) |
234 (let ((msg-file (mh-msg-filename msg mh-current-folder)) | 237 (let ((msg-file (mh-msg-filename msg mh-current-folder)) |
235 (show-buffer (get-buffer mh-show-buffer)) | 238 (show-buffer (get-buffer mh-show-buffer)) |
236 from) | 239 from) |
237 (save-excursion | 240 (with-current-buffer (get-buffer-create mh-temp-buffer) |
238 (set-buffer (get-buffer-create mh-temp-buffer)) | |
239 (erase-buffer) | 241 (erase-buffer) |
240 (message "Removing spamassassin markup from message...") | 242 (message "Removing spamassassin markup from message %d..." msg) |
241 (call-process mh-spamassassin-executable msg-file mh-temp-buffer nil | 243 (call-process mh-spamassassin-executable msg-file t nil |
242 ;; "--remove-markup" | 244 ;; "--remove-markup" |
243 "-d") ; spamassassin V2.20 | 245 "-d") ; spamassassin V2.20 |
244 (if show-buffer | 246 (if show-buffer |
245 (kill-buffer show-buffer)) | 247 (kill-buffer show-buffer)) |
246 (write-file msg-file) | 248 (write-file msg-file) |
247 (when mh-sa-learn-executable | 249 (when mh-sa-learn-executable |
248 (message "Recategorizing this message as ham...") | 250 (message "Recategorizing message %d as ham..." msg) |
249 (call-process mh-sa-learn-executable msg-file mh-temp-buffer nil | 251 (mh-truncate-log-buffer) |
250 "--single" "--ham" "--local" "--no-rebuild")) | 252 ;; Put call-process output in log buffer if we are saving it |
251 (message "Whitelisting message %d..." msg) | 253 ;; (this happens if mh-junk-background is t). |
254 (with-current-buffer mh-log-buffer | |
255 (call-process mh-sa-learn-executable msg-file mh-junk-background nil | |
256 "--single" "--ham" "--local" "--no-rebuild"))) | |
257 (message "Whitelisting sender of message %d..." msg) | |
252 (setq from | 258 (setq from |
253 (car (mh-funcall-if-exists | 259 (car (mh-funcall-if-exists |
254 ietf-drums-parse-address (mh-get-header-field "From:")))) | 260 ietf-drums-parse-address (mh-get-header-field "From:")))) |
255 (kill-buffer nil) | 261 (kill-buffer nil) |
256 (unless (or (null from) (equal from "")) | 262 (unless (or (null from) (equal from "")) |
257 (mh-spamassassin-add-rule "whitelist_from" from)) | 263 (mh-spamassassin-add-rule "whitelist_from" from)) |
258 (message "Whitelisting message %d...done" msg)))) | 264 (message "Whitelisting sender of message %d...done" msg)))) |
259 | 265 |
260 (defun mh-spamassassin-add-rule (rule body) | 266 (defun mh-spamassassin-add-rule (rule body) |
261 "Add a new rule to \"~/.spamassassin/user_prefs\". | 267 "Add a new rule to \"~/.spamassassin/user_prefs\". |
262 The name of the rule is RULE and its body is BODY." | 268 The name of the rule is RULE and its body is BODY." |
263 (save-window-excursion | 269 (save-window-excursion |
373 | 379 |
374 The \"Bogofilter tuning HOWTO\" describes how you can fine-tune Bogofilter." | 380 The \"Bogofilter tuning HOWTO\" describes how you can fine-tune Bogofilter." |
375 (unless mh-bogofilter-executable | 381 (unless mh-bogofilter-executable |
376 (error "Unable to find the bogofilter executable")) | 382 (error "Unable to find the bogofilter executable")) |
377 (let ((msg-file (mh-msg-filename msg mh-current-folder))) | 383 (let ((msg-file (mh-msg-filename msg mh-current-folder))) |
378 (call-process mh-bogofilter-executable msg-file mh-junk-background | 384 (mh-truncate-log-buffer) |
379 nil "-s"))) | 385 ;; Put call-process output in log buffer if we are saving it |
386 ;; (this happens if mh-junk-background is t). | |
387 (with-current-buffer mh-log-buffer | |
388 (call-process mh-bogofilter-executable msg-file mh-junk-background | |
389 nil "-s")))) | |
380 | 390 |
381 ;;;###mh-autoload | 391 ;;;###mh-autoload |
382 (defun mh-bogofilter-whitelist (msg) | 392 (defun mh-bogofilter-whitelist (msg) |
383 "Whitelist MSG with bogofilter. | 393 "Whitelist MSG with bogofilter. |
384 | 394 |
385 See `mh-bogofilter-blacklist' for more information." | 395 See `mh-bogofilter-blacklist' for more information." |
386 (unless mh-bogofilter-executable | 396 (unless mh-bogofilter-executable |
387 (error "Unable to find the bogofilter executable")) | 397 (error "Unable to find the bogofilter executable")) |
388 (let ((msg-file (mh-msg-filename msg mh-current-folder))) | 398 (let ((msg-file (mh-msg-filename msg mh-current-folder))) |
389 (call-process mh-bogofilter-executable msg-file mh-junk-background | 399 (mh-truncate-log-buffer) |
390 nil "-n"))) | 400 ;; Put call-process output in log buffer if we are saving it |
401 ;; (this happens if mh-junk-background is t). | |
402 (with-current-buffer mh-log-buffer | |
403 (call-process mh-bogofilter-executable msg-file mh-junk-background | |
404 nil "-n")))) | |
391 | 405 |
392 | 406 |
393 | 407 |
394 ;; Spamprobe Interface | 408 ;; Spamprobe Interface |
395 | 409 |
421 MH-E commands \\[mh-junk-blacklist] and \\[mh-junk-whitelist] to | 435 MH-E commands \\[mh-junk-blacklist] and \\[mh-junk-whitelist] to |
422 update SpamProbe's training." | 436 update SpamProbe's training." |
423 (unless mh-spamprobe-executable | 437 (unless mh-spamprobe-executable |
424 (error "Unable to find the spamprobe executable")) | 438 (error "Unable to find the spamprobe executable")) |
425 (let ((msg-file (mh-msg-filename msg mh-current-folder))) | 439 (let ((msg-file (mh-msg-filename msg mh-current-folder))) |
426 (call-process mh-spamprobe-executable msg-file mh-junk-background | 440 (mh-truncate-log-buffer) |
427 nil "spam"))) | 441 ;; Put call-process output in log buffer if we are saving it |
442 ;; (this happens if mh-junk-background is t). | |
443 (with-current-buffer mh-log-buffer | |
444 (call-process mh-spamprobe-executable msg-file mh-junk-background | |
445 nil "spam")))) | |
428 | 446 |
429 ;;;###mh-autoload | 447 ;;;###mh-autoload |
430 (defun mh-spamprobe-whitelist (msg) | 448 (defun mh-spamprobe-whitelist (msg) |
431 "Whitelist MSG with SpamProbe. | 449 "Whitelist MSG with SpamProbe. |
432 | 450 |
433 See `mh-spamprobe-blacklist' for more information." | 451 See `mh-spamprobe-blacklist' for more information." |
434 (unless mh-spamprobe-executable | 452 (unless mh-spamprobe-executable |
435 (error "Unable to find the spamprobe executable")) | 453 (error "Unable to find the spamprobe executable")) |
436 (let ((msg-file (mh-msg-filename msg mh-current-folder))) | 454 (let ((msg-file (mh-msg-filename msg mh-current-folder))) |
437 (call-process mh-spamprobe-executable msg-file mh-junk-background | 455 (mh-truncate-log-buffer) |
438 nil "good"))) | 456 ;; Put call-process output in log buffer if we are saving it |
457 ;; (this happens if mh-junk-background is t). | |
458 (with-current-buffer mh-log-buffer | |
459 (call-process mh-spamprobe-executable msg-file mh-junk-background | |
460 nil "good")))) | |
439 | 461 |
440 (provide 'mh-junk) | 462 (provide 'mh-junk) |
441 | 463 |
442 ;; Local Variables: | 464 ;; Local Variables: |
443 ;; indent-tabs-mode: nil | 465 ;; indent-tabs-mode: nil |