Path: utzoo!utgpu!attcan!uunet!husc6!mit-eddie!esl.esl.COM!lrs From: lrs@esl.esl.COM (Lynn Slater) Newsgroups: comp.emacs Subject: Filters in RMAIL Message-ID: <8810211419.AA04402@esl.ESL.COM> Date: 21 Oct 88 14:19:43 GMT Sender: daemon@eddie.MIT.EDU Lines: 61 Lloyd Zusman writes: > So, I would like to filter my mail in a different manner. Since I use > rmail inside of GNU Emacs, it seems to me that it would be nice if the > 'rmail-get-new-mail' function could optionally filter the messages as > it takes them from my system mailbox and writes them into my RMAIL > mailbox. Some sort of hook could be used for this, I presume. Why must the work be done in rmail-get-new-mail? It may be easier to write a function that scans the messages already in the RMAIL file and removes/forwards certain ones of them. This would let you use the fill range or emacs functions such as range constrained string search, point/line motion, etc. The filter will probably be easier to write and test. You could then bind a key to a function that would first read the mail and would then invoke the filter. Try something like the following: Warning: this is not tested code or code that I use. I am posting this because the problem described may be common and the ideas below may help. Do not use the below without checking it carefully first. (defvar rmail-filters nil "A list of the filter function to call on each mail message") (defun filter-rmail () "Applies the rmail filters on all messages from here to end of mail" (interactive) (goto-char (point-min)) (mapcar '(lambda (filter-fcn) (save-excursion (apply filter-fcn nil))) rmail-filters) (if (< rmail-current-message rmail-total-messages) (progn (rmail-next-message 1) (filter-rmail)))) ;; now define some site specific filters. Demontrate 2 diff styles (defun rmail-filter-VADS-messages () "Does action X if the current message was a vads related message" (if (re-search-forward "\\(svug\\|vrdxhq\\|apso\\vads\\)" (save-excursion (forward-line 5) (point)) t) (message "VADS message found"))) ;; Add the filter to the filter hooks (setq rmail-filters (cons 'rmail-filter-VADS-messages rmail-filters)) (defun rmail-filter-gnu-ada-messages () "Does action X if the current message was a gnu-ada related message" (re-search-forward "Subject:.*$") (if (re-search-backward "gnu.*ada" (match-beginning 0) t) (message "Gnu Ada Message Found"))) ;; Add the filter to the filter hooks (setq rmail-filters (cons 'rmail-filter-gnu-ada-messages rmail-filters)) -- Lynn =============================================================== Lynn Slater -- lrs@esl.com ESL/TRW 495 Java Drive, Box 3510, Sunnyvale, Ca 94088-3510 Office (408) 738-2888 x 4482; Home (415) 796-4149 ===============================================================