[comp.emacs] smarter RMAIL output

wand@CORWIN.CCS.NORTHEASTERN.EDU (Mitchell Wand) (09/18/89)

I have added new feature to rmail to make the command
"rmail-output-to-rmail-file" (usually bound to "o") smarter about guessing
where to put the mail.  This is similar to a feature in vmail.  [Thanks to the
several people who told me about vmail].

It uses 2 variables:

rmail-output-directory	   and
rmail-output-files-alist

to provide a better default file when you try to use the "o" command.  This is
best illustrated by an example:

(setq rmail-output-directory "~/email")
(setq rmail-output-files-alist
      '(("rrrs-authors" "scheme/rrrs")
	("To:.*cpl" "cpl/mbox")
	("lfp" "lfp")
	("From.*matthias" "matthias/mbox")
	("program.*com\|pgm.*com" "lfp")
	("Re:.*book\|Re:.*ch" "plbook")
	("dfried" "dan")
	))

Each element of rmail-output-files-alist is a list of 2 items:  the first is a
regexp and the second an expression.  If the regexp is matched anywhere in the
message, then the second expression is evaluated to determine a filename.
This filename, in the rmail-output-directory, is used as an initial guess by
the "o" command.  If there is no match, then the last rmail output file is
used, as it is now.

The second element is run through "eval", so you could put fancier stuff
there (eg a form to evaluate), but I have not tested that yet.

Attached is the patch to rmailout.el which accomplishes this.


Mitchell Wand
College of Computer Science
Northeastern University
360 Huntington Avenue #161CN
Boston, MA 02115

CSNet:  wand@corwin.ccs.northeastern.edu

*** /usr/local/emacs/lisp/rmailout.el	Thu Apr 14 05:36:10 1988
--- emacs/rmailout.el	Mon Sep 11 08:59:48 1989
***************
*** 23,39 ****
  (defvar rmail-delete-after-output nil
    "*Non-nil means automatically delete a message that is copied to a file.")
  
  (defun rmail-output-to-rmail-file (file-name)
    "Append the current message to an Rmail file named FILE-NAME.
  If the file does not exist, ask if it should be created.
  If file is being visited, the message is appended to the Emacs
  buffer visiting that file."
!   (interactive (list (read-file-name
  		      (concat "Output message to Rmail file: (default "
! 			      (file-name-nondirectory rmail-last-rmail-file)
  			      ") ")
! 		      (file-name-directory rmail-last-rmail-file)
! 		      rmail-last-rmail-file)))
    (setq file-name (expand-file-name file-name))
    (setq rmail-last-rmail-file file-name)
    (rmail-maybe-set-message-counters)
--- 23,65 ----
  (defvar rmail-delete-after-output nil
    "*Non-nil means automatically delete a message that is copied to a file.")
  
+ (defvar rmail-output-directory "~"
+   "*Directory for rmail-suggest-output-file files")
+ 
+ (defvar rmail-output-files-alist nil
+   "*Alist of regexps and suggested rmail output files.")
+ 
+ (defun rmail-suggest-output-file ()
+   (interactive)
+   (rmail-suggest-output-file-loop rmail-output-files-alist))
+ 
+ (defun rmail-suggest-output-file-loop (alist)
+   (if (null alist)
+       rmail-last-rmail-file
+     (save-excursion
+       (goto-char (point-min))
+       (let ((case-fold-search t)
+ 	    (pat (car (car alist))))
+ 	(let ((found-it (re-search-forward pat (point-max) t)))
+ 	  (if found-it
+ 	      (concat rmail-output-directory "/"
+ 		      (eval (car (cdr (car alist)))))
+ 	    (rmail-suggest-output-file-loop (cdr alist))))))))
+       
+ 
  (defun rmail-output-to-rmail-file (file-name)
    "Append the current message to an Rmail file named FILE-NAME.
  If the file does not exist, ask if it should be created.
  If file is being visited, the message is appended to the Emacs
  buffer visiting that file."
!   (interactive
!    (let ((suggested-file-name (rmail-suggest-output-file)))
!      (list (read-file-name
  		      (concat "Output message to Rmail file: (default "
! 			      (file-name-nondirectory suggested-file-name)
  			      ") ")
! 		      (file-name-directory suggested-file-name)
! 		      suggested-file-name))))
    (setq file-name (expand-file-name file-name))
    (setq rmail-last-rmail-file file-name)
    (rmail-maybe-set-message-counters)