(defun vms-pmail-save-and-exit ()
"Save current buffer and exit emacs.
If this emacs cannot be suspended, you will be prompted about modified
buffers other than the mail buffer. BEWARE --- suspending emacs without
saving your mail buffer causes mail to abort the send (potentially useful
since the mail buffer is still here)."
(interactive)
(basic-save-buffer)
(if (vms-system-info "LOGICAL" "DONT_SUSPEND_EMACS")
(progn
(save-some-buffers)
(kill-emacs 1))
(kill-buffer (current-buffer))
(suspend-emacs)))
(defun vms-pmail-abort ()
"Mark buffer as unmodified and exit emacs.
When the editor is exited without saving its buffer, VMS mail does not
send a message. If you have other modified buffers you will be
prompted for what to do with them."
(interactive)
(if (not (yes-or-no-p "Really abort mail? "))
(ding)
(not-modified)
(if (vms-system-info "LOGICAL" "DONT_SUSPEND_EMACS")
(progn
(save-some-buffers)
(kill-emacs 1))
(kill-buffer (current-buffer))
(suspend-emacs))))
(defun vms-pmail-setup ()
"Set up file assuming use by VMS MAIL utility.
The buffer is put into text-mode, auto-save is turned off and the
following bindings are established.
\\[vms-pmail-save-and-exit] vms-pmail-save-and-exit
\\[vms-pmail-abort] vms-pmail-abort
All other emacs commands are still available."
(interactive)
(auto-save-mode -1)
(text-mode)
(let ((default (vms-system-info "LOGICAL" "SYS$SCRATCH"))
(directory (file-name-directory (buffer-file-name)))
(filename (file-name-nondirectory (buffer-file-name))))
(if (string= directory "SYS$SCRATCH:")
(progn
(cd default)
(setq buffer-file-name (concat default filename))))
(use-local-map (copy-keymap (current-local-map)))
(local-set-key "\C-c\C-c" 'vms-pmail-save-and-exit)
(local-set-key "\C-c\C-g" 'vms-pmail-abort)))
(defun indicate-mail-reply-text ()
"Prepares received mail for re-sending by placing >'s on each line."
(interactive)
(goto-char (point-min))
(while (not (eobp))
(insert ">")
(beginning-of-line)
(forward-line 1))
(set-buffer-modified-p nil)
(goto-char (point-min)))
(defun insert-signature ()
"Moves to the end of the buffer and inserts a \"signature\" file.
First try the file indicated by environment variable MAIL$TRAILER.
If that fails, try the file \"~/.signature\".
If neither file exists, fails quietly."
(interactive)
(end-of-buffer)
(newline)
(if (vms-system-info "LOGICAL" "MAIL$TRAILER")
(if (file-attributes (vms-system-info "LOGICAL" "MAIL$TRAILER"))
(insert-file-contents (vms-system-info "LOGICAL" "MAIL$TRAILER"))
(if (file-attributes "~/.signature")
(insert-file-contents "~/.signature")))))
(provide 'vms-pmail)