[comp.emacs] RMAIL does something I don't understand...

eric@AI.MIT.EDU (Eric Hanchrow) (02/02/91)

I've noticed that rmail determines which mailbox to read by looking at
the LOGNAME environment variable.  It prefers LOGNAME over USER, which
means if I log in (for example) as root, and then `su' as bob, and try
to read mail, I get an error to the effect that `bob' can't read
`root's mail.  Here's the code where it figures out who you are for
the sake of reading mail:
     (list "~/mbox"
	(concat rmail-spool-directory
	(or (getenv "LOGNAME")
		(getenv "USER")
		(user-login-name))))

Were I running things, I would check in the exact opposite order.  My
question is: does anybody know the reasoning behind this code?

       ------------------------------------------------------------------------
       |Eric Hanchrow		sun.com!nosun!yamada-sun!eric		      |
       |Phase III Logic, Inc.	cse.ogi.edu!yamada-sun!eric		      |
       |1600 N.W. 167th Place		Beaverton, OR 97006-4800 USA	      |
       |Voice: (503)-645-0313		Fax: (503)-645-0207     as of 4-Oct-89|
       --------------Crackling-noises-OK--do-not-correct!----------------------

meissner@osf.org (02/06/91)

| From: manderso@mpr.ca (Mark Anderson)
| Newsgroups: gnu.emacs.help
| Date: 5 Feb 91 02:08:46 GMT
| Reply-To: manderso@mprgate.mpr.ca (Mark Anderson)
| Organization: MPR Teltech Ltd., Burnaby, B.C., Canada
| 
| In article <6356@spdcc.SPDCC.COM> bondc@spdcc.COM (Asmodeus) writes:
| >Ayup, that's it.  Doesn't work.
| 
| Aliases from the .mailrc file are stored in Emacs in the variable
| mail-aliases.  I suspect that changes to .mailrc after RMAIL reads it
| the first time are not reflected in the variable.  You can force Emacs
| to read the .mailrc by setting mail-aliases to 't.

Or you can add the following to your .emacs file, and any time you
save .mailrc, it will reset mail-aliases automatically.

(defvar mrm-recursive-rebuild-aliases nil
  "Non-nil if within mrm-rebuild-mail-aliases.")

(defun mrm-rebuild-mail-aliases-hook ()
  "Hook to rebuild the mail aliases, whenever ~/.mailrc is stored."
  (if (and (not mrm-recursive-rebuild-aliases)
	   (string-equal buffer-file-name (expand-file-name "~/.mailrc")))
      (unwind-protect
	  (progn
	    (setq mrm-recursive-rebuild-aliases t)
	    (basic-save-buffer)
	    (setq mail-aliases t)
	    (message "Mail will be rebuilt the next time mail is sent"))
	(progn
	  (setq mrm-recursive-rebuild-aliases nil)
	  t))
    nil))


(if (not (memq 'mrm-rebuild-mail-aliases-hook write-file-hooks))
    (setq write-file-hooks (cons 'mrm-rebuild-mail-aliases-hook write-file-hooks)))

--
Michael Meissner	email: meissner@osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

Considering the flames and intolerance, shouldn't USENET be spelled ABUSENET?

bjaspan@ATHENA.MIT.EDU ("Barr3y Jaspan") (02/07/91)

   Date: 5 Feb 91 02:08:46 GMT
   From: manderso@mprgate.mpr.ca  (Mark Anderson)

   You can force Emacs to read the .mailrc by setting mail-aliases to 't.

Yup.  Here is a bit of code that causes it to happen automatically; I
believe I snarfed it from this mailing list several months ago.

; Reset mail-aliases to t when ~/.mailrc is written, so that mail-aliases
; will get updated before next send."
(setq write-file-hooks (cons 'alias-check write-file-hooks))
(defun alias-check() ""
    (if (equal ".mailrc" (file-name-nondirectory buffer-file-name)) 
	(setq mail-aliases t))
    nil)

Barr3y Jaspan, bjaspan@mit.edu
Watchmaker Computing

ajw@ansa.co.uk (Andrew Watson) (02/08/91)

Mark Anderson <manderso@mprgate.mpr.ca> wrote:

> Aliases from the .mailrc file are stored in Emacs in the variable
> mail-aliases.  I suspect that changes to .mailrc after RMAIL reads it
> the first time are not reflected in the variable.

This is the case.

> 						     You can force Emacs
> to read the .mailrc by setting mail-aliases to 't.

I long ago got bored with this game and make the following small hack
to ensure that editing the .mailrc (using emacs, of course) caused the
variable to be reset automagically, and hence brought the changes made
into effect immediately.

Insert the following lines at the bottom of your .mailrc:

#
# Local Variables:
# eval: (setup-mailrc-hook)
# End:

And put the following two function definitions in your .emacs, or
where-ever:

(defun mailrc-reset ()
  (message "Reset aliases variable")
  (sit-for 1)
  (setq mail-aliases t)
  nil)     ; this is rather important!

(defun setup-mailrc-hook ()
  (make-local-variable 'write-file-hooks)  ; make it have a separate value here
  (setq write-file-hooks (cons 'mailrc-reset write-file-hooks)))

       .                           Regards,
      / \^
     / / \ \                           Andrew
    / /   \ \
   '=========`      Andrew Watson             Tel:      +44 223 323010
  /| |\ | <  |\	    APM Ltd, Poseidon House,  Fax:      +44 223 359779
 / | | \| _> | \    Castle Park,              UUCP:     mcsun!ukc!ansa!ajw
 ---------------    Cambridge CB3 0RD, UK     Internet: ajw@ansa.co.uk