I use RMAIL to read all my mail.  Spamassassin has marked spam, and
exim has thrown away the real junk.  In RMAIL mode I have a hook to
rmail-show-message-hook.  The hook function uses a long an moderately
complex filter to file junk in a Junky file, label messages from
certain individuals and mailing lists, make additional checks
(largely superseded by SA, but...)

For example@:

(defun rmail-file-filtering-mail-hook () 
  "Hook to file mail and label spam etc automatically"
  (if (eq (current-buffer)
               (get-file-buffer (expand-file-name "~/RMAIL")))
                                        ; Only for RMAIL file
      (let
          (pos subject to cc sender reply from content-type x-rbl x-sa
               x-sas x-mailer x-message-info x-warning return-path received)
        (save-restriction
          (narrow-to-region (setq pos (point))
                            (progn
                              (search-forward "\n\n" nil t) (point)))
          (setq subject (mail-fetch-field "Subject"))
          (setq to      (mail-fetch-field "To"))
          (setq cc      (mail-fetch-field "Cc"))
          (setq sender  (mail-fetch-field "Sender"))
          (setq reply   (mail-fetch-field "Reply-to"))
          (setq from    (mail-fetch-field "From"))
          (setq x-rbl   (mail-fetch-field "X-RBL-Warning"))
          (setq x-sa    (mail-fetch-field "X-Spam-Flag"))
          (setq x-sas   (mail-fetch-field "X-Spam-Score"))
          (setq x-mailer (mail-fetch-field "X-Mailer"))
          (setq x-message-info (mail-fetch-field "X-Message-Info"))
          (setq x-warning (mail-fetch-field "X-Warning"))
          (setq return-path (mail-fetch-field "Return-path"))
          (setq content-type (mail-fetch-field "Content-Type"))
          )
        (goto-char pos)
        (if (eq subject nil) (setq subject ""))
        (if (eq to nil)      (setq to ""))
        (if (eq cc nil)      (setq cc ""))
        (if (eq sender nil)  (setq sender ""))
        (if (eq reply nil)   (setq reply ""))
        (if (eq from nil)    (setq from ""))
        (if (eq x-rbl nil)   (setq x-rbl (mail-fetch-field "X-Warning")))
        (if (eq x-sas nil)   (setq x-sas ""))
        (if (eq x-mailer nil) (setq x-mailer ""))
        (if (eq x-warning nil) (setq x-warning ""))
        (if (eq return-path nil) (setq return-path ""))
        (if (eq received nil) (setq received ""))
        (if (eq content-type nil)    (setq content-type ""))
        (cond ((or (string-match "Warning: message delayed at" subject)
                   (string-match
                    "Returned mail: warning: cannot send message for" subject)
                   (string-match
                    "Warning: could not send message for past" subject))
               (rmail-set-attribute "deleted" t)
               (let ((del-msg rmail-current-message))
                 (if (rmail-summary-exists)
                     (rmail-select-summary (rmail-summary-mark-deleted 
del-msg))))
               (rmail-next-undeleted-message 1))
              ((string-match "text/html" content-type)
               (rmail-set-attribute "html-mail" t)
               (rmail-set-attribute "deleted" t)
               (let ((del-msg rmail-current-message))
                 (if (rmail-summary-exists)
                     (rmail-select-summary
                      (rmail-summary-mark-deleted del-msg))))
               (rmail-next-undeleted-message 1))
              ((rmail-message-labels-p rmail-current-message "white") nil)
              ((rmail-message-deleted-p rmail-current-message) nil)
              ((rmail-message-labels-p rmail-current-message "filed") nil)
;; things that have been mislabelled first
              ((or (string-match "@ras.org.uk" from)
                   (string-match "@ahrb.ac.uk" from)
                   )
               (rmail-set-label "white" t))
;; and then junk
              ((or (absolute-junk from to subject received) ;; absolute junk
                   x-message-info
                   (body-search "<html>")
                   (body-search "<!doctype html")
                   (string-match "CyberCreek Avalanche Millennium" x-mailer)
                   (string-match "mPOP Web-Mail" x-mailer))
               (let ((ss rmail-delete-after-output))
                 (setq rmail-delete-after-output nil)
                 (rmail-set-label "abs-junk" t)
                 (rmail-output-to-rmail-file
                  (expand-file-name "~/Junky"))
                 (rmail-set-attribute "deleted" t)
                 (let ((del-msg rmail-current-message))
                   (if (rmail-summary-exists)
                       (rmail-select-summary
                        (rmail-summary-mark-deleted del-msg))))
                 (setq rmail-delete-after-output ss)
                 (rmail-next-undeleted-message 1)))
              ((string-match
                "[EMAIL PROTECTED]" from)
               (rmail-set-label "spam" t))
              ((or x-sa                    ; Spam assassin flag
                   (string-match "(\\+\\+\\+\\+\\+" x-sas))
               (let ((ss rmail-delete-after-output))
                 (setq rmail-delete-after-output nil)
                 (rmail-set-label "spamassassin" t)
                 (rmail-output-to-rmail-file
                  (expand-file-name "~/Junky"))
                 (rmail-set-attribute "deleted" t)
                 (let ((del-msg rmail-current-message))
                   (if (rmail-summary-exists)
                       (rmail-select-summary
                        (rmail-summary-mark-deleted del-msg))))
                 (setq rmail-delete-after-output ss)
                 (rmail-next-undeleted-message 1)))

and so on.

is that what you mean?
==John ffitch

Reply via email to