[net.emacs] reading .mailrc in smail.ml

preece@ccvaxa.UUCP (08/26/85)

I added the following code to smail.ml after several Emacs mail
users complained that it didn't understand .mailrc file aliases.
This replaces smail's use of an abbrev file with a routine to
locate alias lines in the user's .mailrc file and turn them into
abbrev definitions.  This is moderately useful (the problem is that
abbrev expansion is done only in certain places -- To: and Cc: lines --
and therefore doesn't work if you just move down the screen with
next-line instead of using the smail commands to go to the appropriate
lines.  I suppose it would be possible to trap all movement commands,
have them check the line header, and switch on abbrevs where
appropriate, but I haven't the energy.  If you want aliases to
expand, you'll just have to ^X-t to go to the To line and so forth.

The following is for Gosling/Unipress Emacs where smail.ml is used
for sending mail.  Unipress 2.xx has a new mail package that uses
the .mailrc file somewhat differently.

Don't trust line numbers...
----------------------------------------------------------------------------
*** /tmp/d04292	Sun Aug 25 22:23:05 1985
--- smail.ml	Mon Jul 22 17:43:26 1985
***************
*** 13,23
  ;  ^Xc	positions you in the Cc: field of the message, creating it if it
  ;	doesn't already exist.
  ; 		The abbrev facility is used for mail address expansion,
! ; 		the file /usr/lib/emacs/RMailAbbrevs should contain
! ; 		abbrev definitions to expand login names to their
! ;		proper mail address.  This gets used at CMU since we have
! ;		7 VAXen, 4 10's and countless 11's;  remembering where a
! ;		person usually logs in is nearly impossible.
  ;  ^Xs	positions you in the Subject: field of the message.
  ;  ^Xa	positions you to the end of the body of the message, ready to
  ; 	append more text.

--- 13,20 -----
  ;  ^Xc	positions you in the Cc: field of the message, creating it if it
  ;	doesn't already exist.
  ; 		The abbrev facility is used for mail address expansion,
! ; 		reading ~/.mailrc and scanning out alias lines to form
! ; 		abbrev definitions
  ;  ^Xs	positions you in the Subject: field of the message.
  ;  ^Xa	positions you to the end of the body of the message, ready to
  ; 	append more text.
***************
*** 39,45
  	(erase-buffer)
  	(if (! (is-bound read-mail-abbrevs))
  	    (progn (declare-global read-mail-abbrevs)
! 		(quietly-read-abbrev-file "/usr/lib/emacs/RMailAbbrevs")
  	    )
  	)
  	(use-abbrev-table "RMail")

--- 39,45 -----
  	(erase-buffer)
  	(if (! (is-bound read-mail-abbrevs))
  	    (progn (declare-global read-mail-abbrevs)
! 		(mail-setup-aliases)
  	    )
  	)
  	(use-abbrev-table "RMail")
***************
*** 214,220
  	(setq mail-append-blind 1)
  	(if (! (is-bound read-mail-abbrevs))
  	    (progn (declare-global read-mail-abbrevs)
! 		   (quietly-read-abbrev-file "/usr/lib/emacs/RMailAbbrevs")
  	    )
  	)
  	(use-abbrev-table "RMail")

--- 214,220 -----
  	(setq mail-append-blind 1)
  	(if (! (is-bound read-mail-abbrevs))
  	    (progn (declare-global read-mail-abbrevs)
! 		   (mail-setup-aliases)
  	    )
  	)
  	(use-abbrev-table "RMail")
***************
*** 394,399
      (abbrev-expand
  	(insert-character ' ')
  	(delete-previous-character)
      )
  )
  

--- 394,445 -----
      (abbrev-expand
  	(insert-character ' ')
  	(delete-previous-character)
+     )
+ )
+ 
+ (defun (mail-setup-aliases word_temp abbrev_temp
+ 	   (save-window-excursion
+ 	       (temp-use-buffer "*Mail-Abbrevs*")
+ 	       (setq needs-checkpointing 0)
+ 	       (beginning-of-file)
+ 	       (set-mark)
+ 	       (end-of-file)
+ 	       (delete-to-killbuffer)
+ 	       (use-abbrev-table "RMail")
+ 	       (setq abbrev-mode 1)
+ 	       (use-syntax-table "Mail-Abbrevs")
+ 	       (modify-syntax-entry "w    !")
+ 	       (error-occurred 
+ 		   (insert-file (concat (getenv "HOME") "/.mailrc"))
+ 	       )
+ 	       (beginning-of-file)
+ 	       (while (! (eobp))
+ 		      (if (looking-at "^alias")
+ 			  (progn 
+ 				 (forward-word)
+ 				 (delete-white-space)
+ 				 (insert-character ' ')
+ 				 (set-mark)
+ 				 (forward-word)
+ 				 (setq word_temp (region-to-string))
+ 				 (delete-white-space)
+ 				 (insert-character ' ')
+ 				 (set-mark)
+ 				 (forward-word)
+ 				 (delete-white-space)
+ 				 (while (! (eolp))
+ 					(insert-string ", ")
+ 					(forward-word)
+ 					(delete-white-space)
+ 				 )
+ 				 (setq abbrev_temp (region-to-string))
+ 				 (define-local-abbrev word_temp abbrev_temp)
+ 			  )
+ 		      )
+ 		      (next-line)
+ 		      (beginning-of-line)
+ 	       )
+ 	   )
         )
  )