[net.sources] mlisp programs for rading mail/msgs/new-articles

zorat@sbcs.UUCP (Alessandro Zorat) (01/30/85)

The following is a shar archive with mlisp files to read mail, system
messages or new articles through EMACS. It also allows one to keep
various "folders" and transfer messages among them, so that one can
group messages according to contents (e.g. VLSI, Graphics, etc.)

(With apologies for the very skimpy documentation)
_________________________________________________________________
#!/bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	READ_ME
#	msgs.ml
#	rmail-lib.ml
#	rmail.ml
#	rnews.ml
#	smail.ml
# This archive created: Wed Jan 30 09:35:52 1985
export PATH; PATH=/bin:$PATH
if test -f 'READ_ME'
then
	echo shar: over-writing existing file "'READ_ME'"
fi
cat << \SHAR_EOF > 'READ_ME'
This is a collection of mlisp programs to read mail/messages/news-articles in a
coherent way.
When invoking rmail, you will be presented with a menu of possible folders,
for example, like the following:

  Mail
  Msgs
  News

  Faculty
  Mail83
  Mail84
  Misc
  VLSI

fa.human-nets
net.announce
net.emacs
   .
   .
   . etc

Move the cursor to the appopriate message and type "r" if you want to read
mail/messages/news that you have not read before,
or "v" to just visit that folder, without reading
outstanding new mail/messages/news, if any.

From there on, things are similar to what is described in the manual.
There are a few additions: one can TRANSFER a mail/message/news-article to a
different folder (e.g. Faculty.) Transfer is bound to "t".
Also, there are two ways of getting back to the menu: The standard "^C", that
goes through messages marked for deletion(D) and deletes them, and the
quick-exit, bound to "q", that simply exits - and leaves the messages to be
deleted marked with D's (and does not delete them). 
This is a lot faster when your folder is big - Once in a while I
exit with "^C" to clear thing up.

If you select the folder "News", you get to read the newsgroups that as
listed in the options in your .newsrc file.

Note that the files in the Msgs and news stuff (fa.***, net.***, etc.)
remain in the system spool area, you do NOT get a copy for each user that
uses the system.  If you want to save a news article, transfer it to one of
your own folders (e.g.  Misc).  Oh yes, I seem to remember that the name of
your own folders should start with a capital letter.  

USER Installation procedures:
Fist, make a new directory in your HOME area:
mkdir ~/Msg-dirs
then, if you have a ~/Messages directory, move it to 
mv ~/Messages ~/Msg-dirs/Mail
Then you can invoke emacs and rmail (^Xr); you will get the a menu with just
Mail 
Msgs

If you want other folder names (e.g. net.emacs) enter the EDIT-MODE (bound
to "~" and type them in.
(Or get the entire list of newsgroups from ????/news/active by doing
ESC-x: filter-region cat ????/news/active |sort -u
and then replacing all the numbers to the right with an empty string:
Exit edit-mode with ^C.
Then move the cursor, to the selected folder and "v" or "r".

There is an on-line help (bound to "?"), plus some more undocumented stuff
(e.g. the following lines in your .emacs_pro let you screen off the mailer's
junk (you can see it all by toggling the &show-whole-headers (bound to "~"))
;
(setq-default &show-whole-headers 0); for the mailers
(setq-default garbage-headers
"^relay-version:.*\n\\|^posting-version:.*\n\\|^path:.*\n\\|^date-received:.*\n\\|^posted:.*\n\\|^sender:.*\n\\|^via:.*\n\\|^from .*\n\\|^mail-from:.*\n\\|^origin:.*\n\\|^received:.*\n\\|^message-id:.*\n\\|^remailed-.*\n\\|^in-reply-to:.*\n\\|^return-path:.*\n\\|^article-.*\n\\|^debug-trace:.*\n\\|^[ \t]*id .*\n"
)
; 

NOTE to system person:
in rnews.ml ther is a path to /usr/local/lib/inews that might need to be
changed.
Also, in smail.ml we reference /usr/lib/sendmail
and in rmail.ml we reference /usr/local/bin/readnews
All those might need to be changed according to your local setup.
SHAR_EOF
if test -f 'msgs.ml'
then
	echo shar: over-writing existing file "'msgs.ml'"
fi
cat << \SHAR_EOF > 'msgs.ml'
(autoload "rmail-dummy" "rmail-lib")
(declare-global mbx-dir)
(if (! (is-bound been-here)) (declare-global been-here))

(defun 
    (msgs-read msg-number from date subject pads
	(rmail-dummy)		; causes all rmail-routines to be
	; (auto)loaded -- if necessary
	(save-excursion 
	    (setq pads "                                        ")
	    (temp-use-buffer "Msgs")
	    (error-occurred (read-file "~/Msg-dirs/Msgs"))
	    (setq needs-checkpointing 0)
	    (temp-use-buffer "Scratch Stuff")
	    (erase-buffer)
	    (message "Reading the messages.   Please wait...")
	    (sit-for 0)
	    (set-mark)
	    (filter-region "msgs -h")
	    (beginning-of-file)
	    (while (! (error-occurred 
			  (re-search-forward "^Message[ \t][ \t]*\\([0-9][0-9]*\\)")))
		   (region-around-match 1)
		   (setq msg-number (region-to-string))
		   (re-search-forward 
		       "^From[:]*[ \t][ \t]*\\([^ ]*\\)[ \t][ \t]*\\([^0-9]*[0-9][0-9]*\\)[ \t]")
		   (region-around-match 1)
		   (setq from (concat (region-to-string) pads))
		   (region-around-match 2)
		   (setq date (concat (region-to-string) pads))
		   (set-mark)
		   (setq subject (concat "[empty]" pads))
		   (re-search-forward "-----")
		   (narrow-region)
		   (beginning-of-file)
		   (error-occurred 
		       (re-search-forward "^Subject: \\(.*\\)$")
		       (region-around-match 1)
		       (setq subject (concat (region-to-string)
					     pads)))
		   (widen-region)
		   (save-excursion 
		       (temp-use-buffer "Msgs")
		       (end-of-file)
		       (insert-string (concat " N  "
					      (substr (concat "/usr/msgs/"
							      msg-number
							     "              ")
						      1 15)
					      (substr date 1 12) " "
					      (substr from 1 15) " "
					      (substr subject 1 30)))
		       (newline)
		   )
	    )
	    (set-mark)
	    (filter-region "msgs -f > /dev/null")
	    (temp-use-buffer "Msgs")
	    (write-named-file "~/Msg-dirs/Msgs")
	)
    )
)

(defun 
    (msgs tmp
	(save-window-excursion 
	    (setq mbx-dir "Msgs")
	    (msgs-read)
	    (do-rmail-setup)
	    (setq tmp wrap-long-lines)
	    (setq wrap-long-lines 0)
	    (setq been-here 1)
	    (recursive-edit)
	    (setq been-here -1)
	    (pop-to-buffer "rmail-directory")
	    (erase-messages)
	    (if buffer-is-modified (error-occurred (write-current-file)))
	    (error-occurred (delete-buffer "rmail-directory"))
	    (error-occurred (delete-buffer "current-message"))
	    (error-occurred (delete-buffer "Scratch Stuff"))
	    (setq wrap-long-lines tmp)
	)
	(novalue)
    )
)
SHAR_EOF
if test -f 'rmail-lib.ml'
then
	echo shar: over-writing existing file "'rmail-lib.ml'"
fi
cat << \SHAR_EOF > 'rmail-lib.ml'
(declare-global rmail-default-log)
(setq rmail-default-log (concat (getenv "HOME") "/TextMessage"))
(declare-global mbx-dir expanded-mbx-dir)
(declare-global is-a-directory)
    				; is-a-directory = 1 iff the mbx-dir
				; is a directory in "~/Msg-dirs,
				; which contains the file "Directory".
				; If mbx-dir is a file in
				; "~/Msg-dirs", is-a-dir. = 0.
(declare-global entry-name)
(if (! (is-bound mail-abbrevs))
    (progn (declare-global mail-abbrevs)
	(quietly-read-abbrev-file (getenv "HOME") "/.mail.abbrevs")
    )
)
(if (! (is-bound &show-whole-headers))
    (setq-default &show-whole-headers 0))

(if (! (is-bound garbage-headers))
    (setq-default garbage-headers
"^via:.*\n\\|^from .*\n\\|^mail-from:.*\n\\|^origin:.*\n\\|^received:.*\n\\|^message-id:.*\n\\|^remailed-.*\n\\|^in-reply-to:.*\n\\|^return-path:.*\n\\|^article-.*\n\\|^debug-trace:.*\n\\|^[ \t]*id .*\n"
    )
)

(defun
    (rmail-help-short
	(message
		"^C=>return; q=>quick-return; v=>visit; n=>next; p=>prev; h=>help; r=>reply")
    )
    
    (rmail-help
	(save-window-excursion 
	    (pop-to-buffer "Rmail-Help")
	    (delete-other-windows)
	    (if (= 0 (buffer-size))
		(insert-string (concat 
"n (^N)  next message                    p (^P)  previous message\n"
"^V      next page                       ESC-v   previous page\n"
"f (blank) scroll fwd.                   b       scroll bkw.\n"
"m       mail                            r       reply\n"
"d       delete message                  u       undel. message\n"
"^S and ^R forw. and bkwd. searches      ESC-x   extended command\n"
"q       quick-return rmail (no deletes) ^C      return rmail\n"
"ESC-c   remove expired msgs             < and > first and last msg.\n"
"s[n]    skip n messages                 ^L      redraw-display\n"
"t       transfer msg.                   a       append message to file\n"
"~       toggle between long and short headers\n"
"The following three commands are used only while reading the news\n"
"F       post a follow-up message to the current newsgroup\n"
"P       post a message to a newsgroup\n"
"R       reply to the author of the current news message\n"))
	    )
	    (message "Type any character to resume mail reading")
	    (get-tty-character)
	)
    )
)

(defun     
    (do-rmail-setup mbx-path
	(if prefix-argument-provided
	    (progn 
		   (setq mbx-path "")
		   (setq mbx-dir (get-tty-string 
				      "Enter path for message directory:  "))
		   (if (!= "/" (substr mbx-dir 1 1))
		       (setq mbx-dir (concat (getenv "HOME") "/" mbx-dir)))
	    )
	    (setq mbx-path (concat (getenv "HOME") "/Msg-dirs/"))
	)
	(pop-to-buffer "rmail-directory")
	(use-local-map "rmail-commands")
	(delete-other-windows)
	(setq mode-line-format
	      (concat "Mail from Message directory:   " mbx-dir
		      "      %M   %[%p%]"))
	(setq case-fold-search 1)
	(setq mode-string "RMail")
	(setq is-a-directory 1)	; assume we have a mbx-dir of the form
	; <directory-name> containing the file "Directory"
	(setq expanded-mbx-dir (concat mbx-path mbx-dir))
	(if (! (file-exists (concat expanded-mbx-dir 
				    "/Directory")))
	    ; if mbx-dir is not a directory 
	    ; - which contains the file "Directory" 
	    (setq is-a-directory 0)
	)
	(if is-a-directory
	    (read-file (concat expanded-mbx-dir "/Directory"))
	    (read-file expanded-mbx-dir)
	)
	(beginning-of-file)
	(if (! (eolp)) (insert-character '\n'))
	(position-on-dirent)
	(pick-up-message)
	(rmail-help-short)
    )
)

(defun 
    (rmail-read
	(save-excursion 
	    (temp-use-buffer "Scratch Stuff")
	    (erase-buffer)
	    (message "Reading the mail from the spool area;  Please wait...")
	    (sit-for 0)
	    (set-mark)
	    (filter-region 
		(concat "/usr/lib/emacs/collectmail "
			(getenv "HOME") "/Msg-dirs/Mail "
			(getenv "HOME") "/BlindBox /usr/spool/mail/"
			(getenv "USER")))
	)
    )
)

(defun
    (position-on-dirent
	(temp-use-buffer "rmail-directory")
	(if (= (buffer-size) 0) 
	    (if is-a-directory
		(read-file (concat expanded-mbx-dir  "/Directory"))
		(read-file expanded-mbx-dir)
	    )
	)
	(if (! (looking-at "^>...[ \t]*\\([^ \t\n][^ \t\n]*\\)[ \t].*"))
	    (progn
		  (beginning-of-file)
		  (if (error-occurred (re-search-forward ""))
		      (progn
			    (beginning-of-file)
			    (if (error-occurred (re-search-forward "^ N"))
				(end-of-file))
			    (rmail-mark)
			    (if (! (looking-at 
				       "^>...[ \t]*\\([^ \t\n][^ \t\n]*\\)[ \t].*"))
				(error-message "No messages"))))
	    )
	)
	(region-around-match 1)
	(setq entry-name (region-to-string))
	(beginning-of-line)
    )
)

(defun
    (set-rmail-mode-line-format
	(save-excursion  temp
	    (temp-use-buffer "rmail-directory")
	    (end-of-line) (set-mark) (beginning-of-line)
	    (setq temp (region-to-string))
	    (temp-use-buffer "current-message")
	    (end-of-file)
	    (setq mode-line-format
		(if (dot-is-visible)
		    "     Current message       %[%p%]"
		    "     Current message       %[%p%]   --More--"))
	)
    )
)

(defun
    (pick-up-message
	(position-on-dirent)
	(save-excursion 
	    (pop-to-buffer "current-message")
	    (use-local-map "rmail-commands")
	    (if is-a-directory
		(setq entry-name 
		      (concat expanded-mbx-dir "/" entry-name))
	    )
	    (if (! (error-occurred (read-file entry-name)))
		(progn 
		      (if (! &show-whole-headers)
			  (progn 
				 (set-mark)
				 (setq case-fold-search 1)
				 (error-occurred
				     (save-restriction
					 (re-search-forward "^$")
					 (narrow-region)
					 (beginning-of-file)
					 (error-occurred
					     (re-replace-string
						 garbage-headers
						 ""))))
				 (setq buffer-is-modified 0)))
		       (set-rmail-mode-line-format)
		       (rmail-help-short)
		)	; else...
		(progn 
		       (erase-buffer)
		       (send-string-to-terminal "")
		       (rmail-delete-message)
		       (message "Cannot read file  " entry-name)
		)
	    )
	)
    )
)


(defun 
    (rmail-next-message
	(position-on-dirent)
	(rmail-unmark)
	(next-line)
	(if (eobp) (progn (previous-line) 
			  (message "Last message") (sit-for 1)))
	(rmail-mark)
	(pick-up-message)
	(rmail-help-short)
    )
    
    (rmail-previous-message
	(position-on-dirent)
	(rmail-unmark)
	(previous-line)
	(if (bobp) (progn (next-line) 
			  (message "First message") (sit-for 1)))
	(rmail-mark)
	(pick-up-message)
	(rmail-help-short)
    )
)

(defun
    (rmail-delete-message
	(save-excursion 
	    (position-on-dirent)
	    (forward-character)
	    (delete-next-character)
	    (insert-character 'D')
	    (beginning-of-line)
	)
	(message "Deleted")
    )
    
    (rmail-undelete-message
	(save-excursion 
	    (position-on-dirent)
	    (forward-character)
	    (delete-next-character)
	    (insert-character ' ')
	    (beginning-of-line)
	)
	(message "Undeleted")
    )
)
(declare-global dest-mbx-dir)	; used to keep name of destination msg.
(setq dest-mbx-dir "Mail")      ; directory for mail transfers

(defun 
    (rmail-transfer full-path-dest-dir
	heading message-number source-file flags temp
	; to transfer the message heading to the "Directory" of the
	; indicated mbx-dir;  the message itself is transferred to 
	; the dest-mbx-dir.
	(setq source-file entry-name)
	(save-window-excursion
	    (temp-use-buffer "Scratch Stuff")
	    (setq temp
		  (get-tty-string 
		      (concat "Transfer to Message directory: "
			      dest-mbx-dir 
			      "   [confirm]  ")))
	    (if (!= temp "")
		(progn 
		       (erase-buffer);  erase Scratch Stuff
		       (insert-string temp)
		       (use-abbrev-table "Msg-dirs")
		       (abbrev-expand)
		       (beginning-of-file) (set-mark) (end-of-file)
		       (setq dest-mbx-dir (region-to-string))
		       (if (!= "" (get-tty-string 
				      (concat
					     "Transfer to Message directory: "
					     dest-mbx-dir
					     "   [confirm again] ")))
			   (error-message "Aborted")
		       )
		)
	    )
	    (save-excursion 
		(temp-use-buffer "Mail-directories")
		(beginning-of-file)
		(if (error-occurred (re-search-forward 
					(concat "^  *" dest-mbx-dir "$")))
		    (progn
			  (end-of-file)
			  (insert-string "\n  " dest-mbx-dir)
		    )
		)
	    )
	    (setq full-path-dest-dir
		  (concat (getenv "HOME") "/Msg-dirs/"
			  dest-mbx-dir))
	    (if (! (file-exists full-path-dest-dir))
		(progn 
		       (set-mark)
		       (filter-region 
			   (concat 
				   "mkdir "
				   full-path-dest-dir))
		       (filter-region 
			   (concat 
				   "cat /dev/null > " 
				   full-path-dest-dir
				   "/Directory"))
		)
	    )
	    (if (! (file-exists 
		       (concat full-path-dest-dir
			       "/Directory")))
		(error-message "Message Directory "
		    full-path-dest-dir
		    "  does not exist!!!")
	    )
	    (temp-use-buffer "rmail-directory")
	    (beginning-of-line)
	    (re-search-forward 
		"^\\(....\\)[^0-9\n]*\\([0-9][0-9]*\\)[ \t][ \t]*\\(.*\\)$")
	    (region-around-match 1)
	    (setq flags (region-to-string))
	    (region-around-match 2)
	    (setq message-number 
		  (substr (concat mbx-dir (region-to-string)) -14 14))
	    (region-around-match 3)
	    (setq heading (region-to-string))
	    (beginning-of-line)
	    (temp-use-buffer "Scratch Stuff")
	    (set-mark)
	    (filter-region (concat "\\cp " source-file
				   " " full-path-dest-dir
				   "/"
				   message-number))
	    (erase-buffer)	; we are still in "Scratch Stuff"
	    (insert-string flags (substr (concat "              "
						 message-number) -14 14)
			   " " heading "\n")
	    (beginning-of-file)
	    (re-replace-string "^.." "  ")
	    (append-to-file (concat full-path-dest-dir "/Directory"))
	    (temp-use-buffer "rmail-directory")
	    (beginning-of-line)
	    (forward-character)
	    (delete-next-character)
	    (insert-character 'T')
	    (beginning-of-line)
	    (message "Message heading transferred to "
		full-path-dest-dir "/Directory and file copied.")
	)
	(novalue)
    )
)

(defun
    (rmail-reply subject dest excess
	(setq subject "")
	(setq dest "")
	(setq excess "")
	(save-window-excursion end
	    (pop-to-buffer "current-message")
	    (setq case-fold-search 1)
	    (beginning-of-file)
	    (if (error-occurred (re-search-forward "^$"))
		      (end-of-file))
	    (set-mark)
	    (beginning-of-file)
	    (narrow-region)
	    (error-occurred
		(re-search-forward "^Subject:[ \t]*\\(.*\\)")
		(region-around-match 1)
		(setq subject (region-to-string))
		(if (!= (substr subject 1 3) "Re:")
		    (setq subject (concat "Re: " subject))
		)
	    )
	    (beginning-of-file)
	    (error-occurred
		(if (error-occurred (re-search-forward
					"^reply-to:[ \t]*\\(.*\\)"))
		    (re-search-forward "^from:[ \t]*\\(.*\\)"))
		(region-around-match 1)
		(setq dest (region-to-string))
	    )
	    (beginning-of-file)
	    (error-occurred edest
		(save-excursion 
		    (temp-use-buffer "Scratch Stuff")
		    (setq needs-checkpointing 0)
		    (erase-buffer)
		    (insert-string dest)
		    (error-occurred 
			(re-search-forward 
			    " *\\([^ \n]*\\)  *([^)\n]*)")
			(region-around-match 1)
			(setq dest (region-to-string))
		    )
		    (error-occurred
			(re-search-forward "^.*<\\([^>,]*\\)>")
			(region-around-match 1)
			(setq dest (region-to-string)))
		    (beginning-of-file)
		    (set-mark)
		    (error-occurred 
			(re-replace-string
			    "[^(\n]*(\\([^)\n]*\\)).*" "\\1"))
;			    "(\\|)\\|  *at  *[^,\n]*\\| *@ *[^,\n]*\\| *<[^>\n]*>"
;			    ""))
		    (end-of-file)
		    (setq edest (region-to-string))
		)
		(re-search-forward "^Date:[ \t]*")
		(set-mark)
		(end-of-line)
		(setq excess (concat
				    "In-Reply-To: "
				    edest "'s message of "
				    (region-to-string)
				    "\n"))
	    )
	    (widen-region)
	    (pop-to-buffer "send-mail")
	    (setq case-fold-search 1)
	    (erase-buffer)
	    (insert-string subject)
	    (newline)
	    (insert-string dest)
	    (newline)
	    (insert-string excess)
	    (smail)
	    (delete-other-windows)
	    (temp-use-buffer "rmail-directory")
	    (beginning-of-line)
	    (forward-character)
	    (delete-next-character)
	    (insert-character 'A')
	    (beginning-of-line)
	)
    )
)

(defun
    (rmail-unmark
	(error-occurred 
	    (delete-next-character)
	    (insert-character ' ')
	    (beginning-of-line)))
    
    (rmail-mark
	(if (error-occurred
		(beginning-of-line)
		(if (eobp)
		    (re-search-reverse "^.")
		    (progn
			  (re-search-forward "^.")
			  (beginning-of-line)))
		(delete-next-character)
		(insert-character '>')
		(beginning-of-line)
	    )
	    (message "No messages"))
    )
)

(declare-global search-key)

(defun
    (rmail-search-forward tmp
	(rmail-unmark)
	(end-of-line)
	(setq tmp (get-tty-string "Search forward: "))
	(if (!= tmp "") (setq search-key tmp))
	(error-occurred (re-search-forward search-key))
	(rmail-mark)
	(pick-up-message)
	(rmail-help-short)
    )

    (rmail-search-reverse tmp
	(rmail-unmark)
	(setq tmp (get-tty-string "Search reverse: "))
	(if (!= tmp "") (setq search-key tmp))
	(error-occurred (re-search-reverse search-key))
	(rmail-mark)
	(pick-up-message)
	(rmail-help-short)
    )
)

(defun
    (rmail-goto-message n
	(position-on-dirent)
	(setq n (get-tty-string "Goto message: "))
	(rmail-unmark)
	(beginning-of-file)
	(provide-prefix-argument n (next-line))
	(rmail-mark)
	(pick-up-message)
	(rmail-help-short)
    )
)

(defun
    (rmail-first-message
	(position-on-dirent)
	(rmail-unmark)
	(beginning-of-file)
	(rmail-mark)
	(pick-up-message)
	(rmail-help-short)
    )
)

(defun
    (rmail-last-message
	(position-on-dirent)
	(rmail-unmark)
	(end-of-file)
	(rmail-mark)
	(pick-up-message)
	(rmail-help-short)
    )
)

(defun
    (rmail-skip n
	(position-on-dirent)
	(setq n (get-tty-string "Skip messages: "))
	(rmail-unmark)
	(provide-prefix-argument n (next-line))
	(rmail-mark)
	(pick-up-message)
	(rmail-help-short)
    )
)

(defun 
    (messages-next-page
	(rmail-unmark)
	(next-page)
	(sit-for 0)
	(rmail-mark)
	(pick-up-message)
	(rmail-help-short)
    )

    (messages-previous-page
	(rmail-unmark)
	(previous-page)
	(sit-for 0)
	(rmail-mark)
	(pick-up-message)
	(rmail-help-short)
    )

    (rmail-next-page
	(save-excursion
	    (pop-to-buffer "current-message")
	    (next-page)
	    (set-rmail-mode-line-format)
	)
    )

    (rmail-previous-page
	(save-excursion
	    (pop-to-buffer "current-message")
	    (previous-page)
	    (set-rmail-mode-line-format)
	)
    )
)

(defun     
    (abbrev-expand
	(insert-character ' ')
	(delete-previous-character)
    )
)

(defun 
    (rmail-append file
	(setq file (get-tty-string (concat ": append-message-to-file ["
					   rmail-default-log "]  ")))
	(if (= file "") (setq file rmail-default-log))
	(save-excursion 
	    (temp-use-buffer "current-message")
	    (append-to-file file))
	(setq rmail-default-log file)
	(message "Appended to " file)
    )
)

(defun 
   (rmail-cleanup
	(message "Removing all expired messages from " mbx-dir 
	    "   Please wait...")
	(sit-for 0)
	(save-window-excursion tmp
	    (temp-use-buffer "rmail-directory")
	    (rmail-last-message)
	    (setq tmp (dot))
	    (rmail-first-message)
	    (while (!= tmp (dot)) (rmail-next-message))
	    (rmail-unmark)
	)
	(rmail-mark)
	(message "Done!")
    )
)

(defun 
    (exit-rmail			; goes thru the deleted or transferred 
	; messages and removes them - The key 'q'
	; instead is bound to exit emacs, so that no
	; deletion of deleted or transferred
	; messages takes place
	(temp-use-buffer "rmail-directory")
	(beginning-of-file)
	(error-occurred (re-replace-string 
			    "^\\(.\\)N" "\\1 "))
	(error-occurred (re-replace-string 
			    "^.T" " D"))
	; cleanup transferred messages
	(error-occurred
	    (while 1
		   (re-search-forward 
		       "^.D..\\([^ \t\n]*\\)")
		   (region-around-match 1)
		   (setq entry-name (region-to-string))
		   ; now unlink the file only if it is in
		   ; ~/Msg-dirs/
		   (if is-a-directory
		       (progn 
			      (if (!= (substr entry-name 1 1) "/")
				  (setq entry-name 
					(concat expanded-mbx-dir
						"/" entry-name))
			      )
			      (error-occurred (unlink-file entry-name)) 
		       )
		   )
		   (beginning-of-line)
		   (set-mark)
		   (end-of-line)
		   (forward-character)
		   (erase-region)
	    )
	)
	(exit-emacs)
    )

    (toggle-headers
	   (if &show-whole-headers
	       (setq &show-whole-headers 0)
	       (setq &show-whole-headers 1))
	   (pick-up-message)
    )
)

(defun 
    (rmail-dummy		; this is used as a dummy call to cause the
				; (auto)load of all other rmail-routines
	(novalue)
    )
)

(save-excursion i
    (temp-use-buffer "current-message")
    (setq needs-checkpointing 0)
    (define-keymap "rmail-commands")
    (use-local-map "rmail-commands")
    (setq i 0)
    (while (< i 128)
	(local-bind-to-key "illegal-operation" (+ 128 i)); remove the
				; ESC-char bindings
	(local-bind-to-key "illegal-operation" i)
	(setq i (+ i 1)))
    (local-bind-to-key "redraw-display" "\^L")
    (local-bind-to-key "rmail-next-message" 'n')
    (local-bind-to-key "rmail-next-message" "\^N")
    (local-bind-to-key "rmail-previous-message" 'p')
    (local-bind-to-key "rmail-previous-message" "\^P")
    (local-bind-to-key "rmail-next-page" 'f')
    (local-bind-to-key "rmail-next-page" ' ')
    (local-bind-to-key "rmail-previous-page" 'b')
    (local-bind-to-key "rmail-delete-message" 'd')
    (local-bind-to-key "rmail-undelete-message" 'u')
    (local-bind-to-key "rmail-help-short" '?')
    (local-bind-to-key "rmail-help" 'h')
    (local-bind-to-key "rmail-reply" 'r')
    (local-bind-to-key "smail" 'm')
    (local-bind-to-key "rmail-transfer" 't')
    (local-bind-to-key "rmail-goto-message" 'g')
    (local-bind-to-key "rmail-first-message" '<')
    (local-bind-to-key "rmail-first-message" "\e<")
    (local-bind-to-key "rmail-last-message" '>')
    (local-bind-to-key "rmail-last-message" "\e>")
    (local-bind-to-key "rmail-skip" 's')
    (local-bind-to-key "rmail-append" 'a')
    (local-bind-to-key "execute-extended-command" "\ex")
    (local-bind-to-key "exit-rmail" "\^C")
    (local-bind-to-key "exit-emacs" 'q')
    (local-bind-to-key "rmail-search-forward" "\^S")
    (local-bind-to-key "rmail-search-reverse" "\^R")
    (local-bind-to-key "rmail-cleanup" "\ec")
    (local-bind-to-key "messages-next-page" "\^V")
    (local-bind-to-key "messages-previous-page" "\ev")
    (local-bind-to-key "next-window" "\^Xn")
    (local-bind-to-key "toggle-headers" '~')
    (local-bind-to-key "rnews-followup" 'F')
    (local-bind-to-key "rnews-post" 'P')
    (local-bind-to-key "rnews-reply" 'R')

    (temp-use-buffer "rmail-directory")
    (setq needs-checkpointing 0)
    (use-local-map "rmail-commands")
)
SHAR_EOF
if test -f 'rmail.ml'
then
	echo shar: over-writing existing file "'rmail.ml'"
fi
cat << \SHAR_EOF > 'rmail.ml'
(autoload "rmail-dummy" "rmail-lib")
(autoload "msgs-read" "msgs")
(autoload "rnews-post" "rnews")
(autoload "rnews-followup" "rnews")
(autoload "rnews-reply" "rnews")
(rmail-dummy)

(defun 
    (rmail-com
	(argc)
	(setq mbx-dir "Mail")
	(rmail-read)
	(do-rmail-setup)
	(recursive-edit)
	(temp-use-buffer "rmail-directory")
	(if buffer-is-modified (error-occurred (write-current-file)))
	(error-occurred (delete-buffer "rmail-directory"))
	(error-occurred (delete-buffer "current-message"))
	(error-occurred (delete-buffer "Scratch Stuff"))
	(exit-emacs)
    )
    
    (email-help
	(message "q or ^C => exit; "
	    "v => visit; "
	    "r => read; "
	    "ESC-d => delete group; "
	    "~ => edit")
    )
    
    (email-edit
	(use-local-map "default-global-keymap")
	(setq mode-line-format
	      "   Mail Directories <<<<<< EDIT-MODE >>>>>> %[%p%]  (^C to exit)")
	(message "^C to exit EDIT mode")
	(recursive-edit)
	(use-local-map "email-commands")
	(setq mode-line-format
	      "   Mail Directories       %M           %[%p%]")
	(email-help)
    )
)

(defun 
    (rmail
	(save-window-excursion 
	    (pop-to-buffer "Mail-directories")
	    (use-local-map "email-commands")
	    (setq mode-line-format
		  "   Mail Directories       %M           %[%p%]")
	    (delete-other-windows)
	    (if (! (file-exists "~/Msg-dirs"))
		(progn 
		       (set-mark)
		       (filter-region "/bin/mkdir ~/Msg-dirs")
		)
	    )
	    (if (! (file-exists "~/.msgs_emacs"))
		(progn 
		       (erase-buffer)
		       (insert-string "Mail\nMsgs\n\n")
		       (set-mark)
;		       (filter-region 
;			   "cat /usr/new/lib/news/active | sort -u")
		       (beginning-of-file)
		       (re-replace-string "^." "  &")
;		       (re-replace-string " *[0-9][0-9]*$" "")
		       (write-named-file "~/.msgs_emacs")
		)
	    )
	    (if (= 0 (buffer-size)) (read-file "~/.msgs_emacs"))
	    (email-help)
	    (recursive-edit)
	    (if buffer-is-modified (write-current-file))
	)
	(novalue)
    )
)

(defun 
    (email-visit
	(save-window-excursion
	    (setq mbx-dir (concat (pick-mbx-dir)))
	    (do-rmail-setup)
	    (recursive-edit)
	    (temp-use-buffer "rmail-directory")
	    (if buffer-is-modified (error-occurred (write-current-file)))
	    (error-occurred (delete-buffer "rmail-directory"))
	    (error-occurred (delete-buffer "current-message"))
	    (error-occurred (delete-buffer "Scratch Stuff"))
	)
    )
)
(defun 
    (email-read tmp
	(save-excursion
	    (setq tmp case-fold-search)
	    (setq case-fold-search 0)
	    (setq global-mode-string "")
	    (setq mbx-dir (concat (pick-mbx-dir)))
	    (if (= mbx-dir "Msgs") (msgs-read))
	    (if (= mbx-dir "Mail") (rmail-read))
	    (beginning-of-line)
	    (if (+ (looking-at "^[ \t]*[a-z][^ \t\n]*$")
		   (= mbx-dir "News"))
		; Note: non-news groups MUST start
		; with a Capital letter e.g. Mail,
		; Faculty, etc.
		(progn temp readnews-command
		       (if (= mbx-dir "News")
			   (setq readnews-command 
				 "/usr/local/bin/readnews -e ")
			   (setq readnews-command 
				 (concat "/usr/local/bin/readnews -e -n "
					 mbx-dir))
		       )
		       (setq temp 
			     (get-tty-string
				 (concat 
					 "About to execute "
					 readnews-command
					 "   Type in other options: ")))
		       (temp-use-buffer "Scratch Stuff")
		       (erase-buffer)
		       (setq readnews-command 
			     (concat readnews-command " " temp))
		       (message 
			   (concat "Executing  " readnews-command
				   "   Please wait .... "))
		       (sit-for 0)
		       (if (= mbx-dir "News")
			   (setq readnews-command 
				 (concat readnews-command 
					"|sed -e 's,\\.,\\/,g'"
					" -e 's,^, N  /usr/spool/news/,'"
					" >> ~/Msg-dirs/News"))
			   (setq readnews-command 
				 (concat readnews-command
					"|sed -e 's,\\.,\\/,g'"
					" -e 's,^, N  /usr/spool/news/,'"
					" >> ~/Msg-dirs/" mbx-dir))
		       )
		       (set-mark)
		       (filter-region readnews-command)
		       (if (!= 0 (buffer-size))
			   (progn 
				  (beginning-of-file)
				  (set-mark)
				  (error-occurred 
				      (re-replace-string "\n\n* *" " "))
				  (end-of-line)
				  (error-message (region-to-string))
			   )
		       )
		)
	    )
	)
	(email-visit)
	(setq case-fold-search tmp)
    )
)

(defun 
    (pick-mbx-dir
	(save-excursion 
	    (beginning-of-line)
	    (re-search-forward "^[ \t]*\\([^ \t\n]*\\)$")
	    (region-around-match 1)
	    (region-to-string)
	)
    )
)


(defun 
    (email-remove
	(setq mbx-dir (concat (pick-mbx-dir)))
	(if (!= "" (get-tty-string (concat 
					   "Removing message directory " 
					   mbx-dir 
					   "  [Confirm] ")))
	    (error-message "Aborted"); else ...
	    (if (file-exists (concat "~/Msg-dirs/" mbx-dir "/Directory"))
		(save-excursion 
		    (temp-use-buffer "Scratch Stuff")
		    (set-mark)
		    (filter-region (concat "\\rm -r ~/Msg-dirs/" mbx-dir))
		)
		; else (if is just a file)
		(error-occurred 
		    (unlink-file (concat (getenv "HOME")
					 "/Msg-dirs/"
					 mbx-dir)))
	    )
	)
	(message "Done!")
    )
)


(save-excursion n
    (temp-use-buffer "Mail-directories")
    (define-keymap "email-commands")
    (use-local-map "email-commands")
    (setq n 39)
    (while (< n 128)
        (progn 
	    (setq n (+ 1 n))
	    (local-bind-to-key "illegal-operation" n)
	)
    )
    (local-bind-to-key "illegal-operation" '\010')
    (local-bind-to-key "illegal-operation" '\012')
    (local-bind-to-key "illegal-operation" '\015')
    (local-bind-to-key "illegal-operation" '\011')
    (local-bind-to-key "email-visit" 'v')
    (local-bind-to-key "email-read" 'r')
    (local-bind-to-key "email-remove" "\ed")
    (local-bind-to-key "exit-emacs" 'q')
    (local-bind-to-key "previous-line" 'p')
    (local-bind-to-key "next-line" 'n')
    (local-bind-to-key "email-help" '?')
    (local-bind-to-key "email-edit" '~')
)
SHAR_EOF
if test -f 'rnews.ml'
then
	echo shar: over-writing existing file "'rnews.ml'"
fi
cat << \SHAR_EOF > 'rnews.ml'
; This is an emacs interface to the readnews program. It heavily depends on
; the rmail.ml package. The rmail.ml commands are understood by rnews.ml 
; (it uses the same local map.) In addition, the following bindings are made:
; F	Post a followup message to the current message (in the current
; 	newsgroup.)
; P	Post a message to a newsgroup
; R	Reply to the author of the current message

(defun
    (rnews-reply subject dest excess refs
	(setq subject "")
	(setq dest "")
	(setq excess "")
	(save-window-excursion
	    (pop-to-buffer "current-message")
	    (setq case-fold-search 1)
	    (beginning-of-file)
	    (if (error-occurred (re-search-forward "^$"))
		      (end-of-file))
	    (set-mark)
	    (beginning-of-file)
	    (narrow-region)
	    (error-occurred
		(if (error-occurred 
			(re-search-forward "^title:[ \t]*\\(.*\\)"))
		    (re-search-forward 
			"^subject:[ \t]*\\(.*\\)")
		)
		(region-around-match 1)
		(setq subject (region-to-string))
		(if (!= (substr subject 1 3) "Re:")
		    (setq subject (concat "Re: " subject))
		)
	    )
	    (beginning-of-file)
	    (error-occurred
		(if (error-occurred 
			(re-search-forward
			    "^reply-to:[ \t]*\\(.*\\)"))
		    (if (error-occurred 
			    (re-search-forward 
				"path:[ \t]*[^ \t!]*!\\(.*\\)"))
			(if (error-occurred 
				(re-search-forward
				    "^from:[ \t]*[^ \t!]*!\\(.*\\)"))
			    (re-search-forward "^from[ \t]*\\(.[^ \t]*\\)")
			)
		    )
		)
		(region-around-match 1)
		(setq dest (region-to-string))
	    )
	    (beginning-of-file)
	    (error-occurred edest
		(save-excursion 
		    (temp-use-buffer "Scratch Stuff")
		    (setq needs-checkpointing 0)
		    (erase-buffer)
		    (insert-string dest)
		    (set-mark)
		    (beginning-of-file)
		    (if (! (error-occurred
			       (re-search-forward " (\\(.*\\))")))
			(progn
			      (region-around-match 1)
			      (setq dest (region-to-string))
			      (beginning-of-file)
			      (insert-string (concat dest "  <"))
			      (re-replace-string "  *(.*" ">")
			      (end-of-line)
			      (set-mark)
			      (beginning-of-line)
			      (setq dest (region-to-string))
			)
		    )
		    (error-occurred 
			(re-replace-string
			    "  *at  *[^,\n]*\\| *@ *[^,\n]*\\| *([^)\n]*)\\| *<[^>\n]*>"
			    ""))
		    (error-occurred
			(re-replace-string ".*!" ""))
		    (setq edest (region-to-string))
		)
		(if (error-occurred
			(re-search-forward "^Posted:[ \t]*"))
		    (re-search-forward "^Received:[ \t]*.[^ \t]*[ \t]*"))
		(set-mark)
		(end-of-line)
		(setq excess (concat
				    "In-Reply-To: "
				    edest "'s message of "
				    (region-to-string)
				    "\n"))
		(beginning-of-file)
		(error-occurred
		    (re-search-forward "^Article-I.D.:[ \t]*\\(.*\\)")
		    (region-around-match 1)
		    (setq refs (concat "References: " (region-to-string)))
		)
	    )
	    (widen-region)
	    (pop-to-buffer "send-mail")
	    (setq needs-checkpointing 0)
	    (setq case-fold-search 1)
	    (erase-buffer)
	    (insert-string subject)
	    (newline)
	    (insert-string dest)
	    (newline)
	    (insert-string excess)
	    (insert-string refs)
	    (newline)
	    (load "smail")
	    (do-mail-setup)
	)
	(position-on-dirent)
	(if (looking-at "^>")
	    (progn
		  (forward-character)
		  (delete-next-character)
		  (insert-character 'A')
		  (beginning-of-line)))
    )
)

(defun
    (rnews-followup newsgroups title refs
	(setq newsgroups "")
	(setq title "")
	(setq refs "")
	(save-window-excursion
	    (pop-to-buffer "current-message")
	    (beginning-of-file)
	    (search-forward "\n\n")
	    (set-mark)
	    (beginning-of-file)
	    (narrow-region)
	    (error-occurred
		(re-search-forward "^Newsgroups:[ \t]*\\(.*\\)")
		(region-around-match 1)
		(setq newsgroups (region-to-string))
	    )
	    (save-excursion
		(temp-use-buffer "Scratch Stuff")
		(setq needs-checkpointing 0)
		(erase-buffer)
		(insert-string newsgroups)
		(beginning-of-file)
		(error-occurred
		    (replace-string "general" "followup"))
		(set-mark)
		(end-of-file)
		(setq newsgroups (region-to-string))
	    )
	    (beginning-of-file)
	    (error-occurred
		(re-search-forward "^Title:[ \t]*\\(.*\\)")
		(region-around-match 1)
		(setq title (region-to-string))
		(if (!= (substr title 1 3) "Re:")
		    (setq title (concat "Re: " title))
		)
	    )
	    (beginning-of-file)
	    (error-occurred
		(re-search-forward "^Article-I.D.:[ \t]*\\(.*\\)")
		(region-around-match 1)
		(setq refs (region-to-string))
	    )
	    (beginning-of-file)
	    (widen-region)
	    (pop-to-buffer "post-news")
	    (setq needs-checkpointing 0)
	    (setq case-fold-search 1)
	    (erase-buffer)
	    (insert-string (concat "Newsgroups: " newsgroups))
	    (newline)
	    (insert-string (concat "Title: " title))
	    (newline)
	    (insert-string (concat "References: " refs))
	    (newline)
	    (newline)
	    (rnews-do-post)
	)
	(position-on-dirent)
	(if (looking-at "^>")
	    (progn
		  (forward-character)
		  (delete-next-character)
		  (insert-character 'F')
		  (beginning-of-line)))
    )
    
    (rnews-post
	(save-window-excursion
	    (pop-to-buffer "post-news")
	    (setq case-fold-search 1)
	    (setq needs-checkpointing 0)
	    (erase-buffer)
	    (insert-string "Newsgroups: \nTitle: \n\n")
	    (beginning-of-file)
	    (end-of-line)
	    (rnews-do-post)
	)
    )
    
    (rnews-do-post rnews-do-send mail-append-blind
	(local-bind-to-key "rnews-abort-send" "\^X\^A")
	(local-bind-to-key "exit-emacs" "\^X\^S")
	(local-bind-to-key "exit-emacs" "\^X\^F")
	(local-bind-to-key "exit-emacs" "\^X\^C")
	(local-bind-to-key "justify-paragraph" "\ej")
	(setq rnews-do-send 1)
	(setq right-margin 72)
	(recursive-edit)
	(if (= rnews-do-send 1)
	    (rnews-call-inews))
    )
    
    (rnews-call-inews newsgroups title refs
	(save-excursion
	    (setq newsgroups "")
	    (setq title "")
	    (setq refs "")
	    (beginning-of-file)
	    (search-forward "\n\n")
	    (set-mark)
	    (beginning-of-file)
	    (narrow-region)
	    (error-occurred
		(re-search-forward "^Newsgroups:[ \t]*\\(.*\\)")
		(region-around-match 1)
		(setq newsgroups (region-to-string))
	    )
	    (if (= (length newsgroups) 0)
		(setq newsgroups (get-tty-string "Newsgroups [general]: ")))
	    (if (= (length newsgroups) 0)
		(setq newsgroups "general"))
	    (beginning-of-file)
	    (error-occurred
		(re-search-forward "^Title:[ \t]*\\(.*\\)")
		(region-around-match 1)
		(setq title (region-to-string))
	    )
	    (if (= (length title) 0)
		(setq title (get-tty-string "Title: ")))
	    (beginning-of-file)
	    (error-occurred
		(re-search-forward "^References:[ \t]*\\(.*\\)")
		(region-around-match 1)
		(setq refs (concat " -F " (region-to-string)))
	    )
	    (widen-region)
	    (beginning-of-file)
	    (search-forward "\n\n")
	    (set-mark)
	    (end-of-file)
	    (copy-region-to-buffer "Delivery-errors")
	)
	(message "Sending...")
	(sit-for 0)
	(save-window-excursion
	    (switch-to-buffer "Delivery-errors")
	    (beginning-of-file)
	    (set-mark)
	    (end-of-file)
	    (filter-region
		(concat "/usr/local/lib/news/inews"
			refs " -n " newsgroups " -t '" title "'"))
	    (beginning-of-file)
	    (set-mark)
	    (error-occurred (re-replace-string "\n\n* *" "; "))
	    (end-of-line)
	    (message (region-to-string))
	)
    )
    
    (rnews-abort-send
	(if (!= "y" (substr (get-tty-string
				"Do you really want to abort the message? ")
			    1 1))
	    (error-message "Turkey!"))
	(setq rnews-do-send 0)
	(exit-emacs)
    )
)
SHAR_EOF
if test -f 'smail.ml'
then
	echo shar: over-writing existing file "'smail.ml'"
fi
cat << \SHAR_EOF > 'smail.ml'
;Unix Emacs SMail facility.   Implements smail (send mail).

; "smail" is used for sending mail.  It places you in a buffer for
; constructing the message and locally defines a few commands:
;  ^X^S	send the mail -- if all went well the window will disappear,
;	otherwise a message indicating which addresses failed will appear
;	at the bottom of the screen.  Unfortunatly, the way the mailers on
;	Unix work, the message will have been sent to those addresses which
;	succeded and not to the others, so you have to delete some
;	addresses and fix up the others before you resend the message.
;  ^Xt	positions you in the To: field of the message.
;  ^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/emacs/lib/RMailAbbrevs should contain
; 		abbrev definitions to expand login names to their
;		proper mail address.
;  ^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.

(autoload "&info" "info.ml")

(defun
    (smail-com
	(argc)
	(smail)
	(exit-emacs)
    )
)

; The following line should be changed when you install Emacs
	(setq-default TimeZone "-EST")

(defun
    (rmail-help
	(&info "emacs" "rmail")
    )
)

(defun    
    (smail 	        ; initiate mail sending
	(if (is-bound &send-mail-is-active)
	    (error-message
		"You're already composing one message, finish it first.")
	)
	(save-window-excursion
	    (pop-to-buffer "send-mail")
	    (use-local-map "Smail-commands")
	    (setq case-fold-search 1)
	    (setq right-margin 72)
	    (do-mail-setup)
	)
	(novalue)
    )
    
    ; set things up in a mail sending buffer.
    (do-mail-setup mail-do-send mail-append-blind time
	(pop-to-buffer "send-mail")
	(setq mode-line-format
	      "  Message composition      %M   %[%p%]   %<L--More--%>")
	(beginning-of-file)
	(setq time (current-time))
	(insert-string "Date: "
	    (if (= (substr time 9 1) " ")
		(substr time 10 1)
		(substr time 9 2))
	    " "
	    (substr time 5 3) " "
	    (substr time -4 4) " "
	    (substr time 12 5) TimeZone
	    "\nFrom: " )
	(insert-string (users-login-name) "@" (system-name) "        ")
	(set-mark)
	(insert-string "(" (users-full-name) ")")
	(save-restriction 
	    (narrow-region)
	    (beginning-of-file)
	    ; AZ	    (error-occurred (re-replace-string " " "."))
	    (end-of-file))
	;	(insert-string "      <" (users-login-name) "@" (system-name) ">")
	(insert-string "\nSubject: ")
	(if (error-occurred (end-of-line) (forward-character))
	    (newline))
	(insert-string "To: ")
	(set-mark)
	(if (error-occurred (end-of-line) (forward-character))
	    (newline))
	(insert-string "Message-Id: <"
	    (current-numeric-time) "/"
	    (users-login-name) "@" (system-name) ">\n")
; 		I do not like message IDs  -- AZ  --
	(beginning-of-file)
	(error-occurred 	; now clean up the author's name so that it
				; contains only the First name and Last name
				; in parentheses (i.e. remove the stuff about
				; office number, phone number etc.)
	    (re-replace-string 
		"^From: *\\([^( \n]*\\) *( *\\([^,\n]*\\)[^)\n]*)"
		"From: \\1        (\\2)"))
	(end-of-file)
	(newline)
	(backward-character)
	(if (! (bolp)) (newline))
	(setq mode-string "SMail")
	(setq mail-do-send 1)
	(setq mail-append-blind 1)
	(if (! (is-bound mail-abbrevs))
	    (progn (declare-global mail-abbrevs)
		   (quietly-read-abbrev-file
		       (concat (getenv "HOME")
			       "/.mail.abbrevs"))
	    )
	)
	(use-abbrev-table "RMail")
	(widen-region)
	(beginning-of-file)
	(if (error-occurred (re-search-forward ":  *$"))
	    (end-of-file))
	(setq abbrev-mode (= (current-column) 5))
	(setq right-margin 72)
	(setq left-margin (if (eobp) 0 10))
	(message "Type  to send the message;  to abort.")
	(error-occurred (smail-hook))
	(while mail-do-send
	       (save-excursion &send-mail-is-active
		   (recursive-edit)
		   (if mail-do-send
		       (progn
			     (message "Sending...")
			     (sit-for 0))))
	       (if mail-do-send (send-mail)))
    )
)

(defun
    (mail-abort-send
	(if (!= "y" (substr (get-tty-string
				"Do you really want to abort the message? ")
			1 1))
	    (error-message "Message aborted.  Make up your mind.."))
	(setq mail-do-send 0)
	(delete-buffer "send-mail")
	(exit-emacs))
    
    (mail-to 		        ; move to the "To:" field
	(abbrev-expand)
	(setq abbrev-mode 1)
	(beginning-of-file)
	(re-search-forward "^to:.*")
	(setq left-margin 10)
    )
    
    (mail-subject 	        ; move to the "Subject:" field
	(abbrev-expand)
	(setq abbrev-mode 0)
	(beginning-of-file)
	(re-search-forward "^subject:.*")
	(setq left-margin 10)
    )
    
    (mail-append 	        ; move to the body
	(abbrev-expand)
	(setq abbrev-mode 0)
	(end-of-file)
	(setq left-margin 1)
    )
    
    (mail-cc 		        ; move to the "cc:" field.
	(abbrev-expand)
	(setq abbrev-mode 1)
	(beginning-of-file)
	(if (error-occurred (re-search-forward "^cc:.*"))
	    (progn (re-search-forward "\n\n\\|^to:.*\n.")
		(backward-character)
		(backward-character)
		(insert-string "\nCc: ")
	    )
	)
    )

    (mail-insert
	(mail-append)
	(save-excursion
	    (insert-string "\n_________________________________\n")
	    (yank-buffer "current-message"))
	(set-mark)
	(provide-prefix-argument 10 (next-line))
	(narrow-region)
	(beginning-of-file)
	(re-replace-string "^From \\|^From:" ">&")
	(error-occurred (re-replace-string "^Date \\|^Date:" ">&"))
	(error-occurred (re-replace-string "^To \\|^To:" ">&"))
	(error-occurred (re-replace-string "^Subject \\|^Subject:" ">&"))
	(error-occurred (re-replace-string "^CC \\|^CC:" ">&"))
	(error-occurred (re-replace-string "^Mail-" ">&"))
	(error-occurred (re-replace-string "^In-Reply-To" ">&"))
	(widen-region)
	(error-occurred (re-replace-string "^." "        &"))
    )

    (mail-noblind-exit
	(setq mail-append-blind 0)
	(exit-emacs)
    )

    (send-mail addresses end		; finally send the mail
	(abbrev-expand)
;	(beginning-of-file)
;	(setq end (if (error-occurred (re-search-forward "^$"))
;		      (buffer-size)
;		      (dot)))
;	(beginning-of-file)
;	(setq addresses "")
;	(re-search-forward "^to:[ \t]*")
;	(if (< (dot) end)
;	    (progn
;		(set-mark)
;		(end-of-line)
;		(narrow-region)
;		(exchange-dot-and-mark)
;		(error-occurred (re-replace-string " *([^(]*)" ""))
;		(error-occurred (re-replace-string "[^,]*<\\([^>,]*\\)>" 
;					"\\1"))
;		(error-occurred (re-replace-string "\t" " "))
;		(error-occurred (re-replace-string "  *at  *" "@"))
;;;;;;;;;	(error-occurred (re-replace-string "  *" "."))
;		(error-occurred (re-replace-string "\\.*,\\.*" " "))
;		(error-occurred (re-replace-string "^  *\\|  *$" ""))
;                (error-occurred (re-replace-string (concat "%" (system-name)) 
;				   			""))
;		(beginning-of-line)
;		(set-mark)
;		(end-of-line)
;		(setq addresses (region-to-string))
;		(widen-region)
;	    )
;	)
;	(beginning-of-file)
;	(error-occurred
;	    (re-search-forward "^cc:[ \t]*")
;	    (if (< (dot) end)
;	      (progn
;		(set-mark)
;		(end-of-line)
;		(narrow-region)
;		(exchange-dot-and-mark)
;		(error-occurred (re-replace-string " *([^(]*)" ""))
;		(error-occurred (re-replace-string "[^,]*<\\([^>,]*\\)>" 
;					"\\1"))
;		(error-occurred (re-replace-string "\t" " "))
;		(error-occurred (re-replace-string "  *at  *\\|  *@  *" "@"))
;;;;;;;;;	(error-occurred (re-replace-string "  *" "."))
;		(error-occurred (re-replace-string "\\.*,\\.*" " "))
;		(error-occurred (re-replace-string "^  *\\|  *$" ""))
;		(beginning-of-line)
;		(set-mark)
;		(end-of-line)
;		(setq addresses (concat addresses " " (region-to-string)))
;		(widen-region)
;	      )
;	    )
;	)
;	(save-excursion 
;	    (temp-use-buffer "Scratch Stuff")
;	    (setq needs-checkpointing 0)
;	    (erase-buffer)
;	    (insert-string addresses)
;	    (beginning-of-file)
;	    (error-occurred (re-replace-string "!" "\\\\!"))
;	    (set-mark)
;	    (end-of-file)
;	    (setq addresses (region-to-string))
;	)
	(message "Sending...")
	(sit-for 0)
	(end-of-file)
	(if (! (bolp)) (newline))
	(beginning-of-file)
	(if mail-append-blind
	    (progn
		(insert-string "\3\n")
		(append-to-file "~/BlindBox")
		(delete-previous-word)))
	(set-mark)
	(end-of-file)
	(fast-filter-region "/usr/lib/sendmail -t -odi")
				; -odi = interactive delivery mode
				; necessary to allow spawned processes to
				; finish their run
        (beginning-of-file)
 	(if (= (buffer-size) 0)
	    (progn
		(setq mail-do-send 0)
		(delete-buffer "send-mail")
		(message "Sent.")
	    )			; else
	    (progn T
		   (beginning-of-file)
		   (set-mark)
		   (end-of-file)
		   (copy-region-to-buffer "Delivery-errors")
		   (beginning-of-file)
		   (error-occurred (re-replace-string "\n\n* *" "; "))
		   (end-of-line)
		   (setq T (region-to-string))
		   (erase-buffer)
		   (yank-from-killbuffer)
		   (beginning-of-file)
		   (error-occurred 
		       (re-search-forward "^to:[^>\n]*"))
		   (message T))
	)
    )
)

(defun
    (abbrev-expand
	(insert-character ' ')
	(delete-previous-character)
    )
)

(defun 
    (smail-dummy 		; used to premit all other functions to be
	(novalue)		; autoloaded
    )
)

(save-window-excursion 
    (if (! (is-bound mail-abbrevs))
	(progn (declare-global mail-abbrevs)
	    (quietly-read-abbrev-file (concat 
			(getenv "HOME") "/.mail.abbrevs"))
	)
    )
    (temp-use-buffer "send-mail")
    (define-keymap "Smail-commands")
    (use-local-map "Smail-commands")
    (local-bind-to-key "rmail-help" "\^X?")
    (local-bind-to-key "mail-to" "\^Xt")
    (local-bind-to-key "mail-append" "\^Xa")
    (local-bind-to-key "mail-cc" "\^Xc")
    (local-bind-to-key "mail-subject" "\^Xs")
    (local-bind-to-key "mail-insert" "\^Xi")
    (local-bind-to-key "mail-noblind-exit" "\^X\^C")
    (local-bind-to-key "exit-emacs" "\^X\^S")
    (local-bind-to-key "exit-emacs" "\^X\^F")
    (local-bind-to-key "mail-abort-send" "\^X\^A")
    (local-bind-to-key "justify-paragraph" "\ej")
)
SHAR_EOF
#	End of shell archive
exit 0