From: plummer@cs.swarthmore.edu (David Barker-Plummer)
Newsgroups: gnu.emacs.sources
Subject: Re: Mail enhancements, was Re: How to get '>' with C-c C-y in rmail-mode
Date: 14 Oct 92 23:28:12 GMT
	<NICKEL.92Oct14210043@desaster.cs.tu-berlin.de>
Organization: Swarthmore College, Swarthmore, PA

On the subject of citing mail messages.  I like to include the cited
authors initials at the beginning of each line of the citation, viz:

In article <sledge.719066501@clustrol>
sledge@clustrol.informatik.rwth-aachen.de (Thomas Bueschgens) writes:

TB> Maybe I have already posted it. The following two files (rmail.el and
TB> sendmail.el) are used at our site, I think Uli Pralle
TB> <Uli.Pralle@cs.tu-berlin.de> wrote them. They are just additions to
TB> the original rmail.el and sendmail.el. 

I used mail-yank.el by Ashwin Ram and others for this, but soon got
tired of typing the initials of the author when asked.  So I wrote
some code which automatically extracts the initials from the yanked
From: line of the message.

I found this rather hard to do, and ugly to boot, but them I am not an
expert Emacs lisp programmer (I use the other AI programming
language).  I include the code for extracting the author name below.

I would be pleased to hear from anyone who has a better version, or
would like to offer constructive criticism of my code.

-- Dave


------------------------------------------------------------

; I implemented this in order to automatically extract the initials from
; the From: field of the message being replied to.
; 
; Unfortunately, the From: field has many formats, and so we must fall
; through to asking the user in many cases.  This could probably be
; done better and more generally.


(defun get-or-ask-for-author ()
  (setq temp (get-author))
  (if temp
      temp
    (read-from-minibuffer "Short Name or Initials of Author? ")))

(defun get-author ()
  (save-excursion
    (beginning-of-buffer)
    (if (re-search-forward "^From:\\s-*" nil t)
	(extracted-author))))

; After the From: in the headers in the original message, there may be
; any one of a variety of formats.  
; - there may be a bare user name, which could be
;   + a string of characters, Eg "cfk", 
;   + a string of characters followed by an address, Eg
;     brennan@cc.swarthmore.edu 
; - Or the user name may be decorated by the users real name, as in
;   + rms@gnu.ai.mit.edu (Richard Stallman), or
;   + Andrew Merrill <merrill>

; The (if (looking-at ...) cases below handle each of these in turn.

(defun extracted-author ()
  (if (looking-at "[A-Za-z0-9]*$")
      (buffer-substring (match-beginning 0) (match-end 0))
    (if (looking-at "\\([A-Za-z0-9]*\\)@[A-Za-z0-9.%]*$")
	(buffer-substring (match-beginning 1) (match-end 1))
      (if (looking-at "[A-Za-z0-9@.]*\\s-*(\\([A-Za-z ]*\\))$")
	  (progn
	    (goto-char (match-beginning 1))
	    (extract-initial-string))
	(if (looking-at "[A-Za-z. ]*<[A-Za-z0-9@.]*>$")
	    (extract-initial-string)
	  (if (looking-at "\"[A-Za-z. ]*\"\\s-*<[A-Za-z0-9@.]*>$")
	      (progn
		(forward-char 1)
		(extract-initial-string))))))))

(defun extract-initial-string ()
  "Extract initials from a string of capitalized words"
  (setq ni (extract-next-initial))
  (if ni
      (progn 
	(forward-word 1)
	(while (looking-at "\\s-")
	  (forward-char 1))
	(concat ni (extract-initial-string)))
    ""))

(defun extract-next-initial ()
  (setq temp case-fold-search)
  (setq case-fold-search nil)
  (if (looking-at "[A-Z]")
      (progn 
       (setq case-fold-search temp)
       (buffer-substring (match-beginning 0) (match-end 0)))
    (progn 
      (setq case-fold-search temp)
      nil)))

     
Newsgroups: gnu.emacs.sources