aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2009-02-19 03:31:31 +0000
committerGlenn Morris2009-02-19 03:31:31 +0000
commit3e3480fb8ac59907b1fd15116d07da7e554303bb (patch)
treeb6e557f783e41fbcda56c975e65231ad64419261
parent25833b8cd8ccbdf98b9501f79f879709af5eb984 (diff)
downloademacs-3e3480fb8ac59907b1fd15116d07da7e554303bb.tar.gz
emacs-3e3480fb8ac59907b1fd15116d07da7e554303bb.zip
(rmail-get-new-mail-filter-spam): Be more careful about error-handling.
Restore the feature of temporarily setting all old messages undeleted before expunging (removed 2009-02-18).
-rw-r--r--lisp/mail/rmail-spam-filter.el54
1 files changed, 41 insertions, 13 deletions
diff --git a/lisp/mail/rmail-spam-filter.el b/lisp/mail/rmail-spam-filter.el
index bd2dfaa12f8..5e88e4fb9cd 100644
--- a/lisp/mail/rmail-spam-filter.el
+++ b/lisp/mail/rmail-spam-filter.el
@@ -337,7 +337,7 @@ it from rmail file. Called for each new message retrieved by
337 ;; Else the prompt to write a new file leaves the raw 337 ;; Else the prompt to write a new file leaves the raw
338 ;; mbox buffer visible. 338 ;; mbox buffer visible.
339 (and newfile 339 (and newfile
340 (rmail-show-message (rmail-first-unseen-message) 1)) 340 (rmail-show-message (rmail-first-unseen-message) t))
341 (rmail-output rsf-file) 341 (rmail-output rsf-file)
342 ;; Swap back, else rmail-get-new-mail-1 gets confused. 342 ;; Swap back, else rmail-get-new-mail-1 gets confused.
343 (when newfile 343 (when newfile
@@ -352,23 +352,51 @@ it from rmail file. Called for each new message retrieved by
352 return-value)) 352 return-value))
353 353
354(defun rmail-get-new-mail-filter-spam (nnew) 354(defun rmail-get-new-mail-filter-spam (nnew)
355 "Check the most NNEW recent messages for spam." 355 "Check the most NNEW recent messages for spam.
356This is called at the end of `rmail-get-new-mail-1' if there is new mail."
356 (let* ((nold (- rmail-total-messages nnew)) 357 (let* ((nold (- rmail-total-messages nnew))
357 (nspam 0) 358 (nspam 0)
358 (nscan (1+ nold))) 359 (nscan (1+ nold))
359 (while (<= nscan rmail-total-messages) 360 ;; Save the original deleted state of all the messages.
360 (or (rmail-spam-filter nscan) 361 (rdv-old rmail-deleted-vector)
361 (setq nspam (1+ nspam))) 362 errflag)
363 ;; Set all messages undeleted so that the expunge only affects spam.
364 (setq rmail-deleted-vector (make-string (1+ rmail-total-messages) ?\s))
365 (while (and (not errflag) (<= nscan rmail-total-messages))
366 (condition-case nil
367 (or (rmail-spam-filter nscan)
368 (setq nspam (1+ nspam)))
369 (error (setq errflag nscan)))
362 (setq nscan (1+ nscan))) 370 (setq nscan (1+ nscan)))
363 (when (> nspam 0) 371 (unwind-protect
364 ;; Otherwise the expunge prompt leaves the raw mbox buffer showing. 372 (if errflag
365 (rmail-show-message (rmail-first-unseen-message) 1) 373 (progn
366 (if (rmail-expunge-confirmed) (rmail-only-expunge t)) 374 (setq rmail-use-spam-filter nil)
367 ;; Swap back, else get-new-mail-1 gets confused. 375 (if rsf-beep (ding t))
368 (rmail-swap-buffers-maybe) 376 (message "Spam filter error for new message %d, disabled" errflag)
369 (widen)) 377 (sleep-for rsf-sleep-after-message))
378 (when (> nspam 0)
379 ;; Otherwise sleep or expunge prompt leaves raw mbox buffer showing.
380 (rmail-show-message (or (rmail-first-unseen-message) 1) t)
381 (unwind-protect
382 (progn
383 (if rsf-beep (ding t))
384 (message "Rmail spam-filter detected and deleted %d spam \
385message%s"
386 nspam (if (= 1 nspam) "" "s"))
387 (sleep-for rsf-sleep-after-message)
388 (if (rmail-expunge-confirmed) (rmail-only-expunge t)))
389 ;; Swap back, else get-new-mail-1 gets confused.
390 (rmail-swap-buffers-maybe)
391 (widen))))
392 ;; Restore the original deleted state. Character N refers to message N.
393 (setq rmail-deleted-vector
394 (concat (substring rdv-old 0 (1+ nold))
395 ;; This still works if we deleted all the new mail.
396 (substring rmail-deleted-vector (1+ nold)))))
370 ;; Return a message based on the number of spam messages found. 397 ;; Return a message based on the number of spam messages found.
371 (cond 398 (cond
399 (errflag ", error in spam filter")
372 ((zerop nspam) "") 400 ((zerop nspam) "")
373 ((= 1 nnew) ", and it appears to be spam") 401 ((= 1 nnew) ", and it appears to be spam")
374 ((= nspam nnew) ", and all appear to be spam") 402 ((= nspam nnew) ", and all appear to be spam")