]> git.eshelyaron.com Git - emacs.git/commitdiff
(rmail-get-new-mail): New local rsf-number-of-spam.
authorRichard M. Stallman <rms@gnu.org>
Fri, 16 Jan 2004 18:23:37 +0000 (18:23 +0000)
committerRichard M. Stallman <rms@gnu.org>
Fri, 16 Jan 2004 18:23:37 +0000 (18:23 +0000)
Call rmail-spam-filter.  Delete and expunge spam.
Print number of spam messages deleted.
Save and restore the deletion status of old messages when reading
new mail with spam filter, so that expunging spam does not expunge
msgs deleted by the user.

(rmail-only-expunge): added an optional argument dont-show to
prevent showing message after expunge.

lisp/mail/rmail.el

index cc2d595d8a62c6605c3687091bf503ff5e2f32fb..f8abc2a910d5e4e47391c5f55d1b331c3125ce13 100644 (file)
@@ -1364,6 +1364,7 @@ It returns t if it got any new messages."
          (while all-files
            (let ((opoint (point))
                  (new-messages 0)
+                 (rsf-number-of-spam 0)
                  (delete-files ())
                  ;; If buffer has not changed yet, and has not been saved yet,
                  ;; don't replace the old backup file now.
@@ -1446,11 +1447,59 @@ It returns t if it got any new messages."
                  (progn (goto-char opoint)
                         (if (or file-name rmail-inbox-list)
                             (message "(No new mail has arrived)")))
-               (if (rmail-summary-exists)
+               ;; check new messages to see if any of them is spam:
+               (if rmail-use-spam-filter
+                   (let*
+                       ((old-messages (- rmail-total-messages new-messages))
+                         (rsf-scanned-message-number (1+ old-messages))
+                         ;; save deletion flags of old messages: vector starts
+                         ;; at zero (is one longer that no of messages),
+                         ;; therefore take 1+ old-messages
+                         (save-deleted
+                          (substring rmail-deleted-vector 0 (1+
+                          old-messages))))
+                      ;; set all messages to undeleted
+                      (setq rmail-deleted-vector
+                            (make-string (1+ rmail-total-messages) ?\ ))
+                     (while (<= rsf-scanned-message-number
+                     rmail-total-messages)
+                       (progn
+                         (if (not (rmail-spam-filter rsf-scanned-message-number))
+                             (progn (setq rsf-number-of-spam (1+ rsf-number-of-spam)))
+                           )
+                         (setq rsf-scanned-message-number (1+ rsf-scanned-message-number))
+                         ))
+                     (if (> rsf-number-of-spam 0)
+                         (progn
+                           (when (rmail-expunge-confirmed)
+                              (rmail-only-expunge t))
+                            ))
+                      (setq rmail-deleted-vector
+                            (concat
+                             save-deleted
+                             (make-string (- rmail-total-messages old-messages)
+                                          ?\ )))
+                     ))
+               (if (rmail-summary-exists)
                    (rmail-select-summary
                     (rmail-update-summary)))
-               (message "%d new message%s read"
-                        new-messages (if (= 1 new-messages) "" "s"))
+               (message "%d new message%s read%s"
+                        new-messages (if (= 1 new-messages) "" "s")
+                        ;; print out a message on number of spam messages found:
+                        (if (and rmail-use-spam-filter (> rsf-number-of-spam 0))
+                            (if (= 1 new-messages)
+                                (format ", and found to be a spam message"
+                                        rsf-number-of-spam)
+                              (if (> rsf-number-of-spam 1)
+                                  (format ", %d of which found to be spam messages"
+                                          rsf-number-of-spam)
+                                (format ", one of which found to be a spam message"
+                                        rsf-number-of-spam)))
+                          ""))
+               (if (and rmail-use-spam-filter (> rsf-number-of-spam 0))
+                   (progn (if rmail-spam-filter-beep (beep t))
+                          (sleep-for rmail-spam-sleep-after-message)))
+
                ;; Move to the first new message
                ;; unless we have other unseen messages before it.
                (rmail-show-message (rmail-first-unseen-message))
@@ -2999,7 +3048,7 @@ See also user-option `rmail-confirm-expunge'."
       (funcall rmail-confirm-expunge
               "Erase deleted messages from Rmail file? ")))
 
-(defun rmail-only-expunge ()
+(defun rmail-only-expunge (&optional dont-show)
   "Actually erase all deleted messages in the file."
   (interactive)
   (set-buffer rmail-buffer)
@@ -3078,11 +3127,12 @@ See also user-option `rmail-confirm-expunge'."
       (message "Expunging deleted messages...done")
       (if (not win)
          (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)))
-      (rmail-show-message
-       (if (zerop rmail-current-message) 1 nil))
-      (if rmail-enable-mime
-         (goto-char (+ (point-min) opoint))
-       (goto-char (+ (point) opoint))))))
+      (if (not dont-show)
+         (rmail-show-message
+          (if (zerop rmail-current-message) 1 nil)
+       (if rmail-enable-mime
+           (goto-char (+ (point-min) opoint))
+         (goto-char (+ (point) opoint))))))))
 
 (defun rmail-expunge ()
   "Erase deleted messages from Rmail file and summary buffer."