[net.emacs] Berkeley-style mailer

gallaher@topaz.ARPA (Mike Gallaher) (02/07/85)

Here is an MLisp mail reader that looks sort of like the berkeley mailer,
in that many of the keys do the same things.  It was originally written by
Chris Torek at Maryland.  I've added some stuff to make it less system
dependent and added some documentation.  I defined some variables that are
set in the site profile to indicate which system it is running on:

	sys_4.2bsd		; Berkeley 4.2bsd
	sys_4.1bsd		; Berkeley 4.1bsd 
	sys_sysv		; Unisoft System V

You can either define them yourself, or just dike out the parts for the
systems you don't want (they're all at the beginning).

Mike Gallaher
Unipress Software
...!seismo!topaz!unipress!mg
...!allegra!sunrise!unipress!mg

------cut here----------------------------------------------------------
# This is a shar archive.  Extract with sh.
echo Extracting berkmail.ml
cat > berkmail.ml << "__Egregious Trees!!!__"
;---------------------------------------------------------------------------
;NAME	berkmail.ml	A totally EMACS MLisp mailer, to look like
;			/usr/ucb/mail [somewhat]
;
;SYNOPSIS
; Unfortunately, the berkmail library is not yet well documented.  It is
; not difficult to figure out, though, if you are used to using the
; Berkeley mailer and don't mind experimenting a bit.  If you are fluent
; in MLisp, of course, you can figure it out from this source.
;
;KEYBINDINGS
;
;  q  ^C	exit-emacs
;  ^L		redraw-display
;  n ^J ^M ^N	mail-forward
;  p  ^P	mail-backward
;  d  DEL	mail-delete-current
;  h		mail-hold-current
;  u		mail-undelete-current
;  f  space	mail-next-page
;  b  ^h	mail-prev-page
;  ?		mail-help
;  !		line-to-top-of-window
;  :		execute-extended-command
;  s o	 	mail-append-to-file
;  r		mail-reply-1
;  R		mail-reply-2
;  m		send-mail
;  g		mail-goto-message
;  <		mail-first-message
;  >		mail-last-message
;  +		mail-directory-+
;  -		mail-directory--
;  e		mail-edit-message
;  x		mail-oops-I-didnt-mean-it
;
;DESCRIPTION
;
; The "mail" command checks your mailbox for new mail.  If there is
; none, it prints "No mail."  in the minibuffer and returns to what you
; were doing.  If you do have new mail, it enters a mail reading mode
; in which there are two windows on the screen.  The top window
; displays the headers of the messages in your mailbox.  One of these
; messages (initially the first one) is designated the current message,
; and is displayed in the bottom window.  In mail reading mode, keys
; are bound to commands to scroll the current message forward and
; backward, to read the next message or the previous message, and to
; delete the current message.  
;
; The "send-mail" command pops up a window with a special buffer for
; constructing a message.  It starts you out with a to:  header, which
; you can then fill in.  When you terminate that header with a carriage
; return, it inserts a subject:  header on the next line.  After you
; end the subject line with a carriage return, it inserts a blank line
; and lets you type the message body.  To send the message, type ^C to
; exit the recursive edit.  
;
;SEE ALSO
; Mail(1)		Berkeley Unix Documentation
; Mail User's guide	Berkeley Unix Documentation
;
;SYSTEMS
;	4.1bsd, 4.2bsd, Unisoft System V
;FILES
; 	user's mail spool file	(normally /usr/spool/mail)
;	message temp directory	(normally /usr/tmp/m-<userid>)
; 	~/.mailrc	user's mail customization file
;BUGS
;	Extracting the messages from the spool file into separate files, and
;	collecting them back, can be excruciatingly slow.
;
;LATER
;	For speed, use database functions to store/retrieve messages instead
;	of exploding the mail file into separate files for each message.
;
;HISTORY
; {4}	 5-Dec-84  Mike Gallaher at unipress
; 	Added code for Berkeley 4.1bsd and System V.  Added the
;	&mail-force-slowmail variable to keep System V happy.
;
; {3}	28-Nov-84  Mike Gallaher at unipress
;	replaced absolute path names by variables &mail-mailer-prog,
;	&mail-spool-dir, &mail-temp-prefix.  On some systems the mail
;	spool directory is protected so that users can't remove their
; 	mail files, so instead of unlinking the spool file when we've
;	read it, make it empty.  Also, to see if new mail has arrived,
;	(in mail-exit) check to see if spool file is empty as well as
;	checking to see	if it exists.
;
; {2}	28-Nov-84  Andrew Scott Beals at bedford
;	added mail-append-to-file
;
; {1}	The epoch  Chris Torek at maryland
;	Created.
;----------------------------------------------------------------------


;
; *SYSTEM-DEPENDENT* definitions
;
; &mail-mailer-prog	is the name of the program that will be used
;			to send the mail, along with any flags it should
;			always get for sending mail.  If the metoo .mailrc
;			flag is set, the flag "-m" will be appended to this
;			string.
;
(if sys_4.2bsd
	(progn		; Berkeley 4.2bsd definitions
	    (setq-default &mail-mailer-prog	"/usr/lib/sendmail -i -s -p ")
	    (setq-default &mail-spool-dir	"/usr/spool/mail/")
	    (setq-default &mail-temp-prefix	"/usr/tmp/m-")
	    (setq-default &mail-force-slowmail 0)
	)
    sys_4.1bsd
	(progn		; Berkeley 4.1bsd definitions 
	    (setq-default &mail-mailer-prog	"/etc/delivermail -i -s -p ")
	    (setq-default &mail-spool-dir	"/usr/spool/mail/")
	    (setq-default &mail-temp-prefix	"/usr/tmp/m-")
	    (setq-default &mail-force-slowmail 0)
	)
    sys_sysv
	(progn		; Unisoft System V definitions
	    (setq-default &mail-mailer-prog	"/bin/mail ")
	    (setq-default &mail-spool-dir	"/usr/mail/")
	    (setq-default &mail-temp-prefix	"/usr/tmp/m-")
	    (setq-default &mail-force-slowmail 1)
	)
)
; 
;  End of -SYSTEM-DEPENDENT- code
; 
(setq-default mail-unum 0)	; Unique number

(defun
  (mail tempfile msgn spoolfile metoo record recordfile holdall
        systempath oops-I-didnt-mean-it slowmail
    (save-window-excursion
      (setq tempfile (concat &mail-temp-prefix (users-login-name)))
      (if (file-exists tempfile)
         (error-message (concat tempfile " exists -- aborted"))
      )
      (if (setq holdall prefix-argument-provided)
         (setq spoolfile (get-tty-file ": mail (from file) "))
         (setq spoolfile (concat &mail-spool-dir (users-login-name)))
      )
      (setq oops-I-didnt-mean-it 0)
      (message "Reading...")
      (sit-for 0)
      (pop-to-buffer "mail")
      (setq needs-checkpointing 0)
      (setq right-margin 9999)
      (use-local-map "mail-commands")
      (pop-to-buffer "Message")
      (setq needs-checkpointing 0)
      (error-occurred (read-file spoolfile))
      (if (eobp)
         (message "No mail.")
      (progn
        (set-mark)
	(filter-region (concat "rm -rf " tempfile ";mkdir " tempfile))
  	(append-to-file (concat tempfile "/MAIL"))
	(setq msgn 1)
	(save-excursion
          (temp-use-buffer "Scratch Stuff")
          (setq needs-checkpointing 0)
          (erase-buffer)	    ; {3} make spoolfile empty
          (write-named-file spoolfile))
	  (while (! (eobp))
            (if (error-occurred (search-forward "\n\nFrom "))
	       (end-of-file)
               (provide-prefix-argument 5 (backward-character))
            )
            (narrow-region)
	    (error-occurred (mail-extract-header msgn))
	    (copy-region-to-buffer "Scratch Stuff")
	    (save-excursion
	       (temp-use-buffer "Scratch Stuff")
               (write-named-file (concat tempfile "/" msgn))
            )
	    (setq msgn (+ msgn 1))
            (widen-region)
            (set-mark)
          )
	  (mail-set-vars)
	  (delete-buffer "Scratch Stuff")
	  (pop-to-buffer "mail")
	  (beginning-of-file)
	  (mail-select-current)
	  (message "Type ^C to exit, ? for help")
	  (error-occurred (recursive-edit))
	  (if oops-I-didnt-mean-it
	     (progn
	        (read-file (concat tempfile "/MAIL"))
		(end-of-file)
		(error-occurred (insert-file spoolfile))
		(write-named-file spoolfile)
		(error-occurred (read-file spoolfile))
             )
             (progn
	       (message "...exiting...")
	       (sit-for 0)
	       (mail-exit)
             )
          )
	  (set-mark)
	  (filter-region (concat "rm -rf " tempfile))
      )
      )
      (delete-buffer "Message")
      (delete-buffer "mail")
    )
    (novalue)
  )

  (mail-extract-header date subj
    (save-excursion
      (beginning-of-file)
      (if (error-occurred (re-search-forward "^From [^ \t]* \\(.*\\)"))
         (setq date "")
         (progn
	    (region-around-match 1)
	    (setq date (region-to-string))
         )
      )
      (if (error-occurred (re-search-forward "^Subject: \\(.*\\)"))
   	 (setq subj "")
	 (progn
	    (region-around-match 1)
            (setq subj (region-to-string))
         )
      )
      (pop-to-buffer "mail")
      (end-of-file)
      (insert-string ".  ")         ; Status area
      (insert-string (arg 1))
      (to-col 8)
      (insert-string (substr (mail-originator) 1 (- 25 (current-column))))
      (to-col 26)
      (insert-string (substr date 1 (- 54 (current-column))))
      (to-col 55)
      (insert-character 34)
      (insert-string (substr subj 1 (- 78 (current-column))))
      (insert-character 34)
      (insert-character 10)
    )
  )

  (mail-originator whofrom whormt
    (save-excursion
      (pop-to-buffer "Message")
      (beginning-of-file)
      (setq whormt "")
      (setq systempath "")
      (while (! (error-occurred (re-search-forward "^>*From \\([^ \t]*\\) .* remote from \\(.*\\)")))
        (region-around-match 1)
        (setq whormt (region-to-string))
        (region-around-match 2)
	(setq systempath (concat systempath (region-to-string) "!"))
      )
      (beginning-of-file)
      (if (error-occurred (re-search-forward "^From \\([^ \t]*\\) \\(.*\\)"))
	 (setq whofrom "[unknown]")
	 (progn
	    (region-around-match 1)
            (setq whofrom (region-to-string))
         )
      )
      (concat systempath (if (= whofrom "uucp") whormt whofrom))
    )
  )

  (mail-number i j
    (setq j 0)
    (if (! (eobp))
       (save-excursion
         (beginning-of-line)
	 (provide-prefix-argument 3 (forward-character))
	 (while (& (>= (setq i (following-char)) '0') (<= i '9'))
	   (setq j (+ (* j 10) (- i '0')))
	   (forward-character)
         )
       )
    )
    j
  )

  (mail-select-current j
    (setq j (mail-number))
    (pop-to-buffer "Message")
    (if j
       (read-file (concat tempfile "/" j))
       (erase-buffer)
    )
    (mail-set-mode)
    (pop-to-buffer "mail")
    (setq mode-line-format (concat "Mail Directory: message # "
				       j " of " (- msgn 1)
				       (if (= global-mode-string "") " "
					   "  -  %M")
                           )
    )
    (if (looking-at "\\.")
       (save-excursion
         (delete-next-character)
	 (insert-character mail-default-mark)
       )
    )
  )

  (mail-set-mode
    (save-excursion
      (pop-to-buffer "Message")
      (end-of-file)
      (if (! (dot-is-visible))
    	 (while (| (= (preceding-char) ' ') 
                   (= (preceding-char) '\t')
		   (= (preceding-char) '\n')
                )
           (backward-character)
         )
      )
      (if (dot-is-visible)
	 (setq mode-line-format "%b%*  %f  %[%p%]  (%m)")
	 (setq mode-line-format "%b%*  %f  %[%p%]  (%m)  --More--")
      )
    )
  )

  (mail-help
    (message "n-ext, p-revious, d-elete, h-old, f-orward, b-ackward")
  )

  (mail-forward
    (if (eobp)
       (message "No more messages")
       (progn
         (next-line)
	 (mail-select-current)
       )
    )
  )

  (mail-backward
    (if (bobp)
       (message "At first message")
       (progn
	 (previous-line)
	 (mail-select-current)
       )
    )
  )

  (mail-edit-message
    (if (eobp)
      (message "I see no message here.")
      (progn
        (save-window-excursion
          (pop-to-buffer "Message")
          (setq mode-line-format "%b%*  %f  %[%p%]  (%m)")
          (recursive-edit)
        )
	(mail-select-current)
      )
    )
  )

  (mail-goto-message n
    (setq n (get-tty-string "Goto message: "))
    (beginning-of-file)
    (provide-prefix-argument (- n 1) (next-line))
    (mail-select-current)
  )
   
  (mail-first-message
    (beginning-of-file)
    (mail-select-current)
  )

  (mail-last-message
    (end-of-file)
    (previous-line)
    (mail-select-current)
  )

  (mail-directory-+
    (next-page)
    (sit-for 0)		; This fixes a bug.
    (mail-select-current)
  )

  (mail-directory--
    (previous-page)
    (sit-for 0)		; Same bug.
    (mail-select-current)
  )

  (mail-delete-current
    (if (! (eobp))
       (save-excursion
         (beginning-of-line)
         (insert-character 'D')
         (delete-next-character)
       )
    )
  )

  (mail-hold-current
    (if (! (eobp))
       (save-excursion
         (beginning-of-line)
         (insert-character 'H')
	 (delete-next-character)
       )
    )
  )

  (mail-undelete-current
    (if (! (eobp))
       (save-excursion
	 (beginning-of-line)
	 (insert-character ' ')
	 (delete-next-character)
       )
    )
  )

  (mail-oops-I-didnt-mean-it
    (message "Sure you want to exit? ")
    (if (= 'y' (get-tty-character))
       (progn
	 (message "Sure you want to exit? yes")
	 (sit-for 0)
	 (setq oops-I-didnt-mean-it 1)
	 (exit-emacs)
       )
    )
    (message "Continue")
  )

  (mail-exit i del holdthis held newmail
    (pop-to-buffer "mail")
    (beginning-of-file)
    (setq held 0)
    (while (! (eobp))
      (setq i (mail-number))
      (beginning-of-line)
      (setq del (looking-at "D"))
      (setq holdthis (| holdall (looking-at "H\\|\\.")))
      (setq held (| held holdthis))
      (if (! del)	; Not deleteing.  Hold or save?
         (progn
	   (pop-to-buffer "Message")
           (read-file (concat tempfile "/" i))
	   (append-to-file (if holdthis (concat tempfile "/0") "~/mbox"))
	   (pop-to-buffer "mail")
         )
      )
      (next-line)
    )
    (pop-to-buffer "Message")
    (erase-buffer)					; {3}
    (if held
       (progn
	 (setq newmail (| (error-occurred (read-file spoolfile)) (bobp)))
	 (error-occurred (insert-file (concat tempfile "/0")))
	 (write-named-file spoolfile)
	 (error-occurred (read-file spoolfile))
       )
       (setq newmail (| (error-occurred (read-file spoolfile)) (bobp)))
    )
    (if (! newmail)
       (message "New mail has arrived.")
    )
  )

  (mail-next-page
    (pop-to-buffer "Message")
    (next-page)
    (scroll-one-line-down)
    (mail-set-mode)
    (pop-to-buffer "mail")
  )

  (mail-prev-page
    (pop-to-buffer "Message")
    (previous-page)
    (if (! (save-excursion (beginning-of-file) (dot-is-visible)))
       (scroll-one-line-up)
    )
    (mail-set-mode)
    (pop-to-buffer "mail")
  )

  (mail-reply-1
    (mail-reply 1)		; normal reply
  )

  (mail-reply-2
    (mail-reply 0)		; reply to sender
  )

  (mail-reply subject dests ccs
    (setq subject "")
    (setq dests "")
    (setq ccs "")
    (if (eobp)
       (message "Reply to what???")
       (save-window-excursion
	 (pop-to-buffer "Message")
	 (beginning-of-file)
	 (error-occurred
           (re-search-forward "^Subject:[ \t]*")
	   (set-mark)
	   (end-of-line)
           (setq subject (region-to-string))
         )
	 (beginning-of-file)
	 (setq dests (mail-originator))
	 (if (arg 1)
	    (progn
	      (beginning-of-file)
	      (error-occurred
	        (re-search-forward "^To:[ \t]*")
	        (set-mark)
	        (end-of-line)
	        (setq dests (concat dests (mail-extract-whoto (region-to-string))))
              )
	      (beginning-of-file)
	      (error-occurred
	        (re-search-forward "^Cc:[ \t]*")
	        (set-mark)
	        (end-of-line)
	        (setq ccs (mail-extract-whoto (region-to-string)))
              )
            )
         )
	 (pop-to-buffer "send-mail")
	 (setq case-fold-search 1)
	 (erase-buffer)
	 (insert-string "To: ")
	 (insert-string dests)
	 (newline)
	 (insert-string "Subject: ")
	 (if (!= subject "")
            (insert-string subject)
         )
	 (newline)
	 (if (!= ccs "")
	    (progn
	      (insert-string "Cc:")
	      (insert-string ccs)
	      (newline)
            )
         )
	 (newline)
	 (if (= subject "")
            (mail-subject)
         )         
	 (if (mail-send 1)
	    (progn
	      (temp-use-buffer "mail")
	      (beginning-of-line)
	      (forward-character)
	      (delete-next-character)
	      (insert-character 'A')
            )
         )
       )
    )
  )

  (mail-extract-whoto iam list temp remains char localpath
    (setq list "")
    (setq temp "")
    (setq localpath "")
    (setq remains (concat (arg 1) " "))
    (setq iam (users-login-name))
    (while (!= remains "")
      (setq char (substr remains 1 1))
      (setq remains (substr remains 2 1000))
      (if (= char "!")
	 (progn
	   (setq localpath (concat localpath temp char))
	   (setq temp "")
         )
         (if (| (= char " ") (= char "\t"))
            (progn
	      (if (& (!= temp "") (!= temp iam))
		 (setq list (concat list " " (if (= systempath localpath) "" (concat systempath localpath)) temp))
              )
	      (setq temp "")
	      (setq localpath ""))
	      (setq temp (concat temp char))
         )
      )
    )
    list
  )

  (send-mail metoo record recordfile readmail slowmail
    (save-window-excursion
      (mail-set-vars)
      (delete-buffer "Scratch Stuff")
      (pop-to-buffer "send-mail")
      (setq case-fold-search 1)
      (erase-buffer)
      (insert-string "To: ")
      (newline)
      (newline)
      (mail-to)
      (mail-send 0)
    )
    (novalue)
  )

  (mail-send mail-do-send readmail mail-send-aborted
    (setq readmail (arg 1))
    (setq mode-string "<mail>")
    (setq right-margin 72)
    (setq mail-do-send 1)
    (setq mail-send-aborted 0)
    (local-bind-to-key "mail-to"                "\^xt")
    (local-bind-to-key "mail-to"                "\^x\^t")
    (local-bind-to-key "mail-append"            "\^xa")
    (local-bind-to-key "mail-cc"                "\^xc")
    (local-bind-to-key "mail-subject"           "\^xs" "\^x\^s")
    (local-bind-to-key "mail-insert"            "\^xi" "\^xm")
    (local-bind-to-key "exit-emacs"             "\^c"  "\^x\^f")
    (local-bind-to-key "mail-abort"             "\^xq")
    (local-bind-to-key "justify-paragraph"      "\ej")
    (local-bind-to-key "mail-run-spell-program" "\^x?")
    (message "Hit ^C to send, ^Xq to abort")
    (save-excursion
      (temp-use-buffer "MailSpell")
      (setq needs-checkpointing 0)
    )
    (while mail-do-send
      (error-occurred (recursive-edit))
      (if mail-do-send
         (mail-send-mail)
      )
    )
    (error-occurred (delete-buffer "send-mail"))
    (error-occurred (delete-buffer "MailSpell"))
    (if unlink-checkpoint-files
       (unlink-file ".Csend-mail")
    )
    (! mail-send-aborted)
  )

  (mail-to
    (mail-to-1)
    (setq left-margin 10)
    (local-bind-to-key "mail-subject" "\^M")
  )

  (mail-to-1
    (beginning-of-file)
    (if (error-occurred (re-search-forward "^To:.*"))
       (progn
         (insert-string "To: \n")
         (backward-character)
       )
    )
  )

  (mail-subject
    (beginning-of-file)
    (if (error-occurred (re-search-forward "^Subject:.*"))
       (progn
         (re-search-forward "^To:.*\n")
         (insert-string "Subject: \n")
	 (backward-character)
       )
    )
    (setq left-margin 10)
    (local-bind-to-key "mail-subject-cr" "\^m")
  )

  (mail-subject-cr
    (beginning-of-file)
    (if (! (error-occurred (re-search-forward "^Subject:")))
       (if (looking-at "[ \t]*\n")
	  (progn
	    (beginning-of-line)
	    (kill-to-end-of-line)
            (kill-to-end-of-line)
          )
       )
    )
    (mail-append)
  )

  (mail-cc-cr
    (beginning-of-file)
    (if (! (error-occurred (re-search-forward "^Cc:")))
       (if (looking-at "[ \t]*\n")
	  (progn
	    (beginning-of-line)
	    (kill-to-end-of-line)
            (kill-to-end-of-line)
          )
       )
    )
    (mail-append)
  )

  (mail-abort
    (message "Do you really want to abort?")
    (if (!= 'y' (get-tty-character))
       (message "Continue")
       (progn
         (message "Aborted.")
	 (setq mail-do-send 0)
	 (setq mail-send-aborted 1)
	 (exit-emacs)
       )
    )
  )

  (mail-append
    (end-of-file)
    (setq left-margin 1)
    (remove-local-binding "\^m")
  )

  (mail-cc
    (beginning-of-file)
    (if (error-occurred (re-search-forward "^Cc:.*"))
       (progn
         (re-search-forward "\n\n\\|^To:.*\n.")
         (backward-character)
         (backward-character)
         (if (looking-at "\nSubject:[ \t]*")
	    (progn
              (forward-character)
              (end-of-line)
            )
         )
         (insert-string "\nCc: ")
       )
    )
    (local-bind-to-key "mail-cc-cr" "\^M")
  )

  (mail-insert
    (if readmail
       (progn
	 (mail-append)
	 (save-excursion
	   (if (! (eolp))
              (newline)
           )
	   (insert-string "________________________________\n")
	   (yank-buffer "Message")
	   (delete-previous-character)
	   (insert-string "________________________________\n\n")
         )
	 (re-replace-string "^From \\|^Date:" ">&")
       )
       (message "What ARE you talking about?")
    )
  )

  (mail-run-spell-program
    (message "Running ""spell""...")
    (sit-for 0)
    (save-excursion
      (temp-use-buffer "MailSpell")
      (erase-buffer)
      (pop-to-buffer "send-mail")
      (beginning-of-file)
      (if (error-occurred (re-search-forward "^Cc:.*"))
	 (if (error-occurred (re-search-forward "^Subject:.*"))
	    (mail-to-1)
         )
      )
      (forward-character)
      (set-mark)
      (end-of-file)
      (append-region-to-buffer "MailSpell")
      (temp-use-buffer "MailSpell")
      (beginning-of-file)
      (set-mark)
      (end-of-file)
      (filter-region "/usr/bin/spell")
      (if (buffer-size)
         (pop-to-buffer "MailSpell")
	 (message "No spelling errors")
      )
    )
    (novalue)
  )

  (mail-send-mail addresses end mail-command
    (save-excursion
      (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)
	   (setq addresses (region-to-string))
         )
      )
      (beginning-of-file)
      (error-occurred
        (re-search-forward "^Cc:[ \t]*")
	(if (< (dot) end)
	   (progn
	     (set-mark)
	     (end-of-line)
	     (setq addresses (concat addresses " " (region-to-string)))
           )
        )
      )
      (temp-use-buffer "Scratch Stuff")
      (setq needs-checkpointing 0)
      (erase-buffer)
      (insert-string addresses)
      (beginning-of-file)
      (error-occurred (re-replace-string "\t\\|," " "))
      (error-occurred (re-replace-string "  *" " "))
      (error-occurred (replace-string "!" "\\!")); quote !s for csh
      (set-mark)
      (end-of-file)
      (setq addresses (region-to-string))
      (delete-buffer "Scratch Stuff"))
      (if (| (= addresses "") (= addresses " "))
	 (message "No destination!?")
	 (save-excursion
	   (message "Sending...")
	   (sit-for 0)
	   (end-of-file)
	   (if (! (bolp)) (newline))
	      (beginning-of-file)
	      (if record
		 (progn
		   (insert-string (concat "From " (users-login-name) " " (current-time)))
		   (newline)
		   (end-of-file)
		   (newline)
		   (if (error-occurred (append-to-file recordfile))
		      (progn
		  	(message "Could not append to " recordfile)
			(sit-for 0)
                      )
                   )
		   (delete-previous-character)
		   (beginning-of-file)
		   (kill-to-end-of-line)
		   (kill-to-end-of-line)
                 )
              )
	      (set-mark)
	      (end-of-file)
	      (setq mail-command (concat &mail-mailer-prog (if metoo "-m " "") addresses))
	      (if slowmail	; ick.
		 (progn
		   (filter-region mail-command)
		   (if (buffer-size)
		      (progn
		 	(beginning-of-file)
		  	(set-mark)
			(error-occurred (re-replace-string "\n\n* *" "; "))
			(end-of-line)
			(message (region-to-string))
			(erase-buffer)
			(yank-from-killbuffer)
                      )
		      (setq mail-do-send 0)
                   )
                 )
		 (progn mail-ufile
		   (setq mail-unum (+ mail-unum 1))
	           (setq mail-ufile (concat "/tmp/email"
					    (users-login-name)
					    mail-unum)
                   )
		   (write-named-file mail-ufile)
		   (start-filtered-process (concat mail-command
 						   "<"
						   mail-ufile
						   ";/bin/rm "
						   mail-ufile)
					   (concat "mail-deliver" mail-unum)
					   "mail-delivery-error"
					   "nothing"
                   )
	           (setq mail-do-send 0)
                 )
              )
         )
      )
  )

  (mail-delivery-error
    (save-excursion
       (temp-use-buffer MPX-process)
       (end-of-file)
       (insert-string (process-output))
       (beginning-of-file)
       (error-occurred (re-replace-string "Mail in .*\\.\n" ""))
       (beginning-of-file)
       (if (! (error-occurred (re-search-forward "User unknown\\|Service unavailable\\|Can't create output")))
  	  (progn
            (pop-to-buffer MPX-process)
	    (message "Mail: just got wind of an error...")
          )
       )
    )
  )

  (mail-set-vars
    (temp-use-buffer "Scratch Stuff")
    (setq needs-checkpointing 0)
    (error-occurred
      (read-file "~/.mailrc")
      (setq metoo (! (error-occurred (re-search-forward "[ \t]metoo[ \t\n]"))))
      (beginning-of-file)
      (setq slowmail (! (error-occurred
                          (re-search-forward "[ \t]slowmail[ \t\n]")
                        )
                     )
      )
      (beginning-of-file)
      (setq record (! (error-occurred
			 (re-search-forward 
                           "[ \t]record[ \t]*=[ \t]*\\([^ \t\n]*\\)")
                      )
                   )
      )
      (if record
	 (progn
           (region-around-match 1)
	   (setq recordfile (region-to-string))
         )
      )
    )
    (setq slowmail (| slowmail &mail-force-slowmail))	; {4}
  )

  (mail-append-to-file file j
    (save-window-excursion
      (setq file (get-tty-file "Append to what file? "))
      (setq needs-checkpointing 0)
      (error-occurred (visit-file file))
      (end-of-file)
      (save-excursion 
   	(pop-to-buffer "mail")
 	(setq j (mail-number))
      )
      (insert-file (concat tempfile "/" j))
      (write-current-file)
    )
  )
)

(save-excursion i old-keymap
  (if (! (is-bound mail-default-mark))
     (setq-default mail-default-mark ' ')
  )
  (setq old-keymap (current-local-keymap))  
  (define-keymap "mail-commands")
  (use-local-map "mail-commands")
  (setq i 0)
  (while (< i 128)
    (local-bind-to-key "illegal-operation" i)
    (setq i (+ i 1))
  )
  (local-bind-to-key "exit-emacs"              "\^c")
  (local-bind-to-key "exit-emacs"              "q")
  (local-bind-to-key "redraw-display"          "\^l")
  (local-bind-to-key "mail-forward"            "n")
  (local-bind-to-key "mail-forward"            "\^j")
  (local-bind-to-key "mail-forward"            "\^m")
  (local-bind-to-key "mail-forward"            "\^n")
  (local-bind-to-key "mail-backward"           "p")
  (local-bind-to-key "mail-backward"           "\^p")
  (local-bind-to-key "mail-delete-current"     "d")
  (local-bind-to-key "mail-delete-current"     0177)
  (local-bind-to-key "mail-hold-current"       "h")
  (local-bind-to-key "mail-undelete-current"   "u")
  (local-bind-to-key "mail-next-page"           "f")
  (local-bind-to-key "mail-next-page"           " ")
  (local-bind-to-key "mail-prev-page"           "b")
  (local-bind-to-key "mail-prev-page"           "\^h")
  (local-bind-to-key "mail-help"                "?")
  (local-bind-to-key "line-to-top-of-window"    "!")
  (local-bind-to-key "execute-extended-command" ":")
  (local-bind-to-key "mail-append-to-file"      "s")
  (local-bind-to-key "mail-append-to-file"      "o")
  (local-bind-to-key "mail-reply-1"             "r")
  (local-bind-to-key "mail-reply-2"             "R")
  (local-bind-to-key "send-mail"                "m")
  (local-bind-to-key "mail-goto-message"         "g")
  (local-bind-to-key "mail-first-message"        "<")
  (local-bind-to-key "mail-last-message"         ">")
  (local-bind-to-key "mail-directory-+"          "+")
  (local-bind-to-key "mail-directory--"          "-")
  (local-bind-to-key "mail-edit-message"         "e")
  (local-bind-to-key "mail-oops-I-didnt-mean-it" "x")
  (if (= old-keymap "")
     (remove-local-map)
     (use-local-map old-keymap)
  )
  (novalue)
)

__Egregious Trees!!!__
exit