lrs@esl.esl.COM (Lynn Slater) (10/21/88)
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 ===============================================================
ljz@fxgrp.UUCP (Lloyd Zusman) (10/21/88)
In your recent mail to me ... >Date: Fri, 21 Oct 88 07:19:43 PDT >From: ames!esl.ESL.COM!lrs (Lynn Slater) >To: info-gnu-emacs@prep.ai.mit.edu >Subject: Filters in RMAIL ... you write: > ... > >It may be easier to write a function that scans the messages already >in the RMAIL file and removes/forwards certain ones of them. ... > >Try something like the following: Thanks for your thoughts and your code suggestions. I'll try your approach ... it seems like it would work just fine. Also thanks for your speedy reply. Sincerely, -- Lloyd Zusman Internet: ljz@fx.com Master Byte Software or ljz%fx.com@ames.arc.nasa.gov Los Gatos, California or fxgrp!ljz@ames.arc.nasa.gov "We take things well in hand." uucp: ...!ames!fxgrp!ljz [ our Internet connection is down: use uucp or mail to the entry above it ]