]> code.delx.au - gnu-emacs/blobdiff - lisp/mh-e/mh-comp.el
(url-http-mark-connection-as-free, url-http-find-free-connection):
[gnu-emacs] / lisp / mh-e / mh-comp.el
index d6b4f9754b6a63a60246329faaaba4a1df515bfa..a967a2c8d9e33a1885628666811aa638235139c0 100644 (file)
@@ -1,6 +1,7 @@
-;;; mh-comp.el --- MH-E functions for composing messages
+;;; mh-comp.el --- MH-E functions for composing and sending messages
 
-;; Copyright (C) 1993,1995,1997,2000,2001,2002 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1995, 1997,
+;;  2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
 ;; Author: Bill Wohler <wohler@newt.com>
 ;; Maintainer: Bill Wohler <wohler@newt.com>
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
-;; Internal support for MH-E package.
+;; This file includes the functions in the MH-Folder maps that get us
+;; into MH-Letter mode, as well the functions in the MH-Letter mode
+;; that are used to send the mail. Other that those, functions that
+;; are needed in mh-letter.el should be found there.
 
 ;;; Change Log:
 
-;; $Id: mh-comp.el,v 1.2 2003/02/03 20:55:30 wohler Exp $
-
 ;;; Code:
 
 (require 'mh-e)
-(require 'gnus-util)
-(require 'easymenu)
-(require 'cl)
-
-;; Shush the byte-compiler
-(defvar adaptive-fill-first-line-regexp)
-(defvar font-lock-defaults)
-(defvar mark-active)
-(defvar sendmail-coding-system)
-(defvar mh-identity-list)
-(defvar mh-identity-default)
-(defvar mh-identity-menu)
-
-;;; Autoloads
-(autoload 'Info-goto-node "info")
-(autoload 'mail-mode-fill-paragraph "sendmail")
-(autoload 'mm-handle-displayed-p "mm-decode")
-
-(autoload 'sc-cite-original "sc"
-  "Workhorse citing function which performs the initial citation.
-This is callable from the various mail and news readers' reply
-function according to the agreed upon standard.  See `\\[sc-describe]'
-for more details.  `sc-cite-original' does not do any yanking of the
-original message but it does require a few things:
-
-     1) The reply buffer is the current buffer.
-
-     2) The original message has been yanked and inserted into the
-        reply buffer.
-
-     3) Verbose mail headers from the original message have been
-        inserted into the reply buffer directly before the text of the
-        original message.
+(require 'mh-gnus)                      ;needed because mh-gnus.el not compiled
+(require 'mh-scan)
 
-     4) Point is at the beginning of the verbose headers.
+(require 'sendmail)
 
-     5) Mark is at the end of the body of text to be cited.
+(autoload 'easy-menu-add "easymenu")
+(autoload 'mml-insert-tag "mml")
 
-For Emacs 19's, the region need not be active (and typically isn't
-when this function is called.  Also, the hook `sc-pre-hook' is run
-before, and `sc-post-hook' is run after the guts of this function.")
+\f
 
-;;; Site customization (see also mh-utils.el):
+;;; Site Customization
 
 (defvar mh-send-prog "send"
   "Name of the MH send program.
 Some sites need to change this because of a name conflict.")
 
-(defvar mh-redist-full-contents nil
-  "Non-nil if the `dist' command needs whole letter for redistribution.
-This is the case only when `send' is compiled with the BERK option.
-If MH will not allow you to redist a previously redist'd msg, set to nil.")
+(defvar mh-send-uses-spost-flag nil
+  "Non-nil means \"send\" uses \"spost\" to submit messages.
+
+If the value of \"postproc:\" is \"spost\", you may need to set
+this variable to t to tell MH-E to avoid using features of
+\"post\" that are not supported by \"spost\". You'll know that
+you'll need to do this if sending mail fails with an error of
+\"spost: -msgid unknown\".")
 
 (defvar mh-redist-background nil
   "If non-nil redist will be done in background like send.
-This allows transaction log to be visible if -watch, -verbose or -snoop are
-used.")
-
-(defvar mh-note-repl "-"
-  "String whose first character is used to notate replied to messages.")
-
-(defvar mh-note-forw "F"
-  "String whose first character is used to notate forwarded messages.")
-
-(defvar mh-note-dist "R"
-  "String whose first character is used to notate redistributed messages.")
-
-(defvar mh-yank-hooks nil
-  "Obsolete hook for modifying a citation just inserted in the mail buffer.
-Each hook function can find the citation between point and mark.
-And each hook function should leave point and mark around the citation
-text as modified.
+This allows transaction log to be visible if -watch, -verbose or
+-snoop are used.")
 
-This is a normal hook, misnamed for historical reasons.
-It is semi-obsolete and is only used if `mail-citation-hook' is nil.")
-
-(defvar mail-citation-hook nil
-  "*Hook for modifying a citation just inserted in the mail buffer.
-Each hook function can find the citation between point and mark.
-And each hook function should leave point and mark around the citation
-text as modified.
-
-If this hook is entirely empty (nil), the text of the message is inserted
-with `mh-ins-buf-prefix' prefixed to each line.
-
-See also the variable `mh-yank-from-start-of-msg', which controls how
-much of the message passed to the hook.
+\f
 
-This hook was historically provided to set up supercite.  You may now leave
-this nil and set up supercite by setting the variable
-`mh-yank-from-start-of-msg' to 'supercite or, for more automatic insertion,
-to 'autosupercite.")
+;;; Variables
 
 (defvar mh-comp-formfile "components"
   "Name of file to be used as a skeleton for composing messages.
-Default is \"components\".  If not an absolute file name, the file
-is searched for first in the user's MH directory, then in the
-system MH lib directory.")
+
+Default is \"components\".
+
+If not an absolute file name, the file is searched for first in the
+user's MH directory, then in the system MH lib directory.")
 
 (defvar mh-repl-formfile "replcomps"
   "Name of file to be used as a skeleton for replying to messages.
-Default is \"replcomps\".  If not an absolute file name, the file
-is searched for first in the user's MH directory, then in the
-system MH lib directory.")
+
+Default is \"replcomps\".
+
+If not an absolute file name, the file is searched for first in the
+user's MH directory, then in the system MH lib directory.")
 
 (defvar mh-repl-group-formfile "replgroupcomps"
   "Name of file to be used as a skeleton for replying to messages.
-This file is used to form replies to the sender and all recipients of a
-message. Only used if `mh-nmh-flag' is non-nil. Default is \"replgroupcomps\".
-If not an absolute file name, the file is searched for first in the user's MH
-directory, then in the system MH lib directory.")
+
+Default is \"replgroupcomps\".
+
+This file is used to form replies to the sender and all recipients of
+a message. Only used if `(mh-variant-p 'nmh)' is non-nil.
+If not an absolute file name, the file is searched for first in the
+user's MH directory, then in the system MH lib directory.")
 
 (defvar mh-rejected-letter-start
   (format "^%s$"
           (regexp-opt
            '("Content-Type: message/rfc822" ;MIME MDN
+             "------ This is a copy of the message, including all the headers. ------";from exim
+             "--- Below this line is a copy of the message."; from qmail
              "   ----- Unsent message follows -----" ;from sendmail V5
              " --------Unsent Message below:" ; from sendmail at BU
              "   ----- Original message follows -----" ;from sendmail V8
@@ -163,16 +115,8 @@ directory, then in the system MH lib directory.")
 
 (defvar mh-new-draft-cleaned-headers
   "^Date:\\|^Received:\\|^Message-Id:\\|^From:\\|^Sender:\\|^Errors-To:\\|^Delivery-Date:\\|^Return-Path:"
-  "Regexp of header lines to remove before offering a message as a new draft.
-Used by the \\<mh-folder-mode-map>`\\[mh-edit-again]' and `\\[mh-extract-rejected-mail]' commands.")
-
-(defvar mh-to-field-choices '(("t" . "To:") ("s" . "Subject:") ("c" . "Cc:")
-                              ("b" . "Bcc:") ("f" . "Fcc:") ("r" . "From:")
-                              ("d" . "Dcc:"))
-  "Alist of (final-character . field-name) choices for `mh-to-field'.")
-
-(defvar mh-letter-mode-map (copy-keymap text-mode-map)
-  "Keymap for composing mail.")
+  "Regexp of header lines to remove before offering a message as a new draft\\<mh-folder-mode-map>.
+Used by the \\[mh-edit-again] and \\[mh-extract-rejected-mail] commands.")
 
 (defvar mh-letter-mode-syntax-table nil
   "Syntax table used by MH-E while in MH-Letter mode.")
@@ -183,13 +127,7 @@ Used by the \\<mh-folder-mode-map>`\\[mh-edit-again]' and `\\[mh-extract-rejecte
         (make-syntax-table text-mode-syntax-table))
   (modify-syntax-entry ?% "." mh-letter-mode-syntax-table))
 
-(defvar mh-sent-from-folder nil
-  "Folder of msg assoc with this letter.")
-
-(defvar mh-sent-from-msg nil
-  "Number of msg assoc with this letter.")
-
-(defvar mh-send-args nil
+(defvar mh-send-args ""
   "Extra args to pass to \"send\" command.")
 
 (defvar mh-annotate-char nil
@@ -198,49 +136,85 @@ Used by the \\<mh-folder-mode-map>`\\[mh-edit-again]' and `\\[mh-extract-rejecte
 (defvar mh-annotate-field nil
   "Field name for message annotation.")
 
+(defvar mh-insert-auto-fields-done-local nil
+  "Buffer-local variable set when `mh-insert-auto-fields' called successfully.")
+(make-variable-buffer-local 'mh-insert-auto-fields-done-local)
+
+\f
+
+;;; MH-E Entry Points
+
 ;;;###autoload
 (defun mh-smail ()
-  "Compose and send mail with the MH mail system.
-This function is an entry point to MH-E, the Emacs front end
-to the MH mail system.
-
-See documentation of `\\[mh-send]' for more details on composing mail."
+  "Compose a message with the MH mail system.
+See `mh-send' for more details on composing mail."
   (interactive)
   (mh-find-path)
   (call-interactively 'mh-send))
 
+;;;###autoload
+(defun mh-smail-other-window ()
+  "Compose a message with the MH mail system in other window.
+See `mh-send' for more details on composing mail."
+  (interactive)
+  (mh-find-path)
+  (call-interactively 'mh-send-other-window))
+
+(defun mh-send-other-window (to cc subject)
+  "Compose a message in another window.
+
+See `mh-send' for more information and a description of how the
+TO, CC, and SUBJECT arguments are used."
+  (interactive (list
+                (mh-interactive-read-address "To: ")
+                (mh-interactive-read-address "Cc: ")
+                (mh-interactive-read-string "Subject: ")))
+  (let ((pop-up-windows t))
+    (mh-send-sub to cc subject (current-window-configuration))))
+
 (defvar mh-error-if-no-draft nil)       ;raise error over using old draft
 
 ;;;###autoload
 (defun mh-smail-batch (&optional to subject other-headers &rest ignored)
-  "Set up a mail composition draft with the MH mail system.
-This function is an entry point to MH-E, the Emacs front end
-to the MH mail system.  This function does not prompt the user
-for any header fields, and thus is suitable for use by programs
-that want to create a mail buffer.
-Users should use `\\[mh-smail]' to compose mail.
-Optional arguments for setting certain fields include TO, SUBJECT, and
-OTHER-HEADERS. Additional arguments are IGNORED."
+  "Compose a message with the MH mail system.
+
+This function does not prompt the user for any header fields, and
+thus is suitable for use by programs that want to create a mail
+buffer. Users should use \\[mh-smail] to compose mail.
+
+Optional arguments for setting certain fields include TO,
+SUBJECT, and OTHER-HEADERS. Additional arguments are IGNORED.
+
+This function remains for Emacs 21 compatibility. New
+applications should use `mh-user-agent-compose'."
   (mh-find-path)
   (let ((mh-error-if-no-draft t))
     (mh-send (or to "") "" (or subject ""))))
 
-;; XEmacs needs this:
+;;;###autoload
+(define-mail-user-agent 'mh-e-user-agent
+  'mh-user-agent-compose 'mh-send-letter 'mh-fully-kill-draft
+  'mh-before-send-letter-hook)
+
 ;;;###autoload
 (defun mh-user-agent-compose (&optional to subject other-headers continue
                                         switch-function yank-action
                                         send-actions)
   "Set up mail composition draft with the MH mail system.
-This is `mail-user-agent' entry point to MH-E.
+This is the `mail-user-agent' entry point to MH-E. This function
+conforms to the contract specified by `define-mail-user-agent'
+which means that this function should accept the same arguments
+as `compose-mail'.
 
 The optional arguments TO and SUBJECT specify recipients and the
 initial Subject field, respectively.
 
-OTHER-HEADERS is an alist specifying additional
-header fields.  Elements look like (HEADER . VALUE) where both
-HEADER and VALUE are strings.
+OTHER-HEADERS is an alist specifying additional header fields.
+Elements look like (HEADER . VALUE) where both HEADER and VALUE
+are strings.
 
-CONTINUE, SWITCH-FUNCTION, YANK-ACTION and SEND-ACTIONS are ignored."
+CONTINUE, SWITCH-FUNCTION, YANK-ACTION and SEND-ACTIONS are
+ignored."
   (mh-find-path)
   (let ((mh-error-if-no-draft t))
     (mh-send to "" subject)
@@ -249,19 +223,157 @@ CONTINUE, SWITCH-FUNCTION, YANK-ACTION and SEND-ACTIONS are ignored."
                         (cdr (car other-headers)))
       (setq other-headers (cdr other-headers)))))
 
+;; Shush compiler.
+(defvar sendmail-coding-system)         ; XEmacs
+
+;;;###autoload
+(defun mh-send-letter (&optional arg)
+  "Save draft and send message.
+
+When you are all through editing a message, you send it with this
+command. You can give a prefix argument ARG to monitor the first stage
+of the delivery\; this output can be found in a buffer called \"*MH-E
+Mail Delivery*\".
+
+The hook `mh-before-send-letter-hook' is run at the beginning of
+this command. For example, if you want to check your spelling in
+your message before sending, add the function `ispell-message'.
+
+Unless `mh-insert-auto-fields' had previously been called
+manually, the function `mh-insert-auto-fields' is called to
+insert fields based upon the recipients. If fields are added, you
+are given a chance to see and to confirm these fields before the
+message is actually sent. You can do away with this confirmation
+by turning off the option `mh-auto-fields-prompt-flag'.
+
+In case the MH \"send\" program is installed under a different name,
+use `mh-send-prog' to tell MH-E the name."
+  (interactive "P")
+  (run-hooks 'mh-before-send-letter-hook)
+  (if (and (mh-insert-auto-fields t)
+           mh-auto-fields-prompt-flag
+           (goto-char (point-min)))
+      (if (not (y-or-n-p "Auto fields inserted, send? "))
+          (error "Send aborted")))
+  (cond ((mh-mh-directive-present-p)
+         (mh-mh-to-mime))
+        ((or (mh-mml-tag-present-p) (not (mh-ascii-buffer-p)))
+         (mh-mml-to-mime)))
+  (save-buffer)
+  (message "Sending...")
+  (let ((draft-buffer (current-buffer))
+        (file-name buffer-file-name)
+        (config mh-previous-window-config)
+        (coding-system-for-write
+         (if (and (local-variable-p 'buffer-file-coding-system
+                                    (current-buffer)) ;XEmacs needs two args
+                  ;; We're not sure why, but buffer-file-coding-system
+                  ;; tends to get set to undecided-unix.
+                  (not (memq buffer-file-coding-system
+                             '(undecided undecided-unix undecided-dos))))
+             buffer-file-coding-system
+           (or (and (boundp 'sendmail-coding-system) sendmail-coding-system)
+               (and (boundp 'default-buffer-file-coding-system )
+                    default-buffer-file-coding-system)
+               'iso-latin-1))))
+    ;; Older versions of spost do not support -msgid and -mime.
+    (unless mh-send-uses-spost-flag
+      ;; Adding a Message-ID field looks good, makes it easier to search for
+      ;; message in your +outbox, and best of all doesn't break threading for
+      ;; the recipient if you reply to a message in your +outbox.
+      (setq mh-send-args (concat "-msgid " mh-send-args))
+      ;; The default BCC encapsulation will make a MIME message unreadable.
+      ;; With nmh use the -mime arg to prevent this.
+      (if (and (mh-variant-p 'nmh)
+               (mh-goto-header-field "Bcc:")
+               (mh-goto-header-field "Content-Type:"))
+          (setq mh-send-args (concat "-mime " mh-send-args))))
+    (cond (arg
+           (pop-to-buffer mh-mail-delivery-buffer)
+           (erase-buffer)
+           (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush"
+                               "-nodraftfolder" mh-send-args file-name)
+           (goto-char (point-max))      ; show the interesting part
+           (recenter -1)
+           (set-buffer draft-buffer))   ; for annotation below
+          (t
+           (mh-exec-cmd-daemon mh-send-prog nil "-nodraftfolder" "-noverbose"
+                               (split-string mh-send-args) file-name)))
+    (if mh-annotate-char
+        (mh-annotate-msg mh-sent-from-msg
+                         mh-sent-from-folder
+                         mh-annotate-char
+                         "-component" mh-annotate-field
+                         "-text" (format "\"%s %s\""
+                                         (mh-get-header-field "To:")
+                                         (mh-get-header-field "Cc:"))))
+
+    (cond ((or (not arg)
+               (y-or-n-p "Kill draft buffer? "))
+           (kill-buffer draft-buffer)
+           (if config
+               (set-window-configuration config))))
+    (if arg
+        (message "Sending...done")
+      (message "Sending...backgrounded"))))
+
+;;;###autoload
+(defun mh-fully-kill-draft ()
+  "Quit editing and delete draft message.
+
+If for some reason you are not happy with the draft, you can use
+this command to kill the draft buffer and delete the draft
+message. Use the command \\[kill-buffer] if you don't want to
+delete the draft message."
+  (interactive)
+  (if (y-or-n-p "Kill draft message? ")
+      (let ((config mh-previous-window-config))
+        (if (file-exists-p buffer-file-name)
+            (delete-file buffer-file-name))
+        (set-buffer-modified-p nil)
+        (kill-buffer (buffer-name))
+        (message "")
+        (if config
+            (set-window-configuration config)))
+    (error "Message not killed")))
+
+\f
+
+;;; MH-Folder Commands
+
+;; Alphabetical.
+
 ;;;###mh-autoload
-(defun mh-edit-again (msg)
-  "Clean up a draft or a message MSG previously sent and make it resendable.
-Default is the current message.
-The variable `mh-new-draft-cleaned-headers' specifies the headers to remove.
-See also documentation for `\\[mh-send]' function."
+(defun mh-edit-again (message)
+  "Edit a MESSAGE to send it again.
+
+If you don't complete a draft for one reason or another, and if
+the draft buffer is no longer available, you can pick your draft
+up again with this command. If you don't use a draft folder, your
+last \"draft\" file will be used. If you use draft folders,
+you'll need to visit the draft folder with \"\\[mh-visit-folder]
+drafts <RET>\", use \\[mh-next-undeleted-msg] to move to the
+appropriate message, and then use \\[mh-edit-again] to prepare
+the message for editing.
+
+This command can also be used to take messages that were sent to
+you and to send them to more people.
+
+Don't use this command to re-edit a message from a Mailer-Daemon
+who complained that your mail wasn't posted for some reason or
+another (see `mh-extract-rejected-mail').
+
+The default message is the current message.
+
+See also `mh-send'."
   (interactive (list (mh-get-msg-num t)))
   (let* ((from-folder mh-current-folder)
          (config (current-window-configuration))
          (draft
           (cond ((and mh-draft-folder (equal from-folder mh-draft-folder))
-                 (pop-to-buffer (find-file-noselect (mh-msg-filename msg)) t)
-                 (rename-buffer (format "draft-%d" msg))
+                 (pop-to-buffer (find-file-noselect (mh-msg-filename message))
+                                t)
+                 (rename-buffer (format "draft-%d" message))
                  ;; Make buffer writable...
                  (setq buffer-read-only nil)
                  ;; If buffer was being used to display the message reinsert
@@ -271,36 +383,43 @@ See also documentation for `\\[mh-send]' function."
                    (insert-file-contents buffer-file-name))
                  (buffer-name))
                 (t
-                 (mh-read-draft "clean-up" (mh-msg-filename msg) nil)))))
+                 (mh-read-draft "clean-up" (mh-msg-filename message) nil)))))
     (mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil)
     (mh-insert-header-separator)
     (goto-char (point-min))
     (save-buffer)
     (mh-compose-and-send-mail draft "" from-folder nil nil nil nil nil nil
                               config)
-    (mh-letter-mode-message)))
+    (mh-letter-mode-message)
+    (mh-letter-adjust-point)))
 
 ;;;###mh-autoload
-(defun mh-extract-rejected-mail (msg)
-  "Extract message MSG returned by the mail system and make it resendable.
-Default is the current message.  The variable `mh-new-draft-cleaned-headers'
-gives the headers to clean out of the original message.
-See also documentation for `\\[mh-send]' function."
+(defun mh-extract-rejected-mail (message)
+  "Edit a MESSAGE that was returned by the mail system.
+
+This command prepares the message for editing by removing the
+Mailer-Daemon envelope and unneeded header fields. Fix whatever
+addressing problem you had, and send the message again with
+\\[mh-send-letter].
+
+The default message is the current message.
+
+See also `mh-send'."
   (interactive (list (mh-get-msg-num t)))
   (let ((from-folder mh-current-folder)
         (config (current-window-configuration))
-        (draft (mh-read-draft "extraction" (mh-msg-filename msg) nil)))
+        (draft (mh-read-draft "extraction" (mh-msg-filename message) nil)))
     (goto-char (point-min))
     (cond ((re-search-forward mh-rejected-letter-start nil t)
            (skip-chars-forward " \t\n")
            (delete-region (point-min) (point))
            (mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil))
           (t
-           (message "Does not appear to be a rejected letter.")))
+           (message "Does not appear to be a rejected letter")))
     (mh-insert-header-separator)
     (goto-char (point-min))
     (save-buffer)
-    (mh-compose-and-send-mail draft "" from-folder msg
+    (mh-compose-and-send-mail draft "" from-folder message
                               (mh-get-header-field "To:")
                               (mh-get-header-field "From:")
                               (mh-get-header-field "Cc:")
@@ -308,36 +427,39 @@ See also documentation for `\\[mh-send]' function."
     (mh-letter-mode-message)))
 
 ;;;###mh-autoload
-(defun mh-forward (to cc &optional msg-or-seq)
-  "Forward one or more messages to the recipients TO and CC.
-
-Use the optional MSG-OR-SEQ to specify a message or sequence to forward.
-
-Default is the displayed message.  If optional prefix argument is given then
-prompt for the message sequence.  If variable `transient-mark-mode' is non-nil
-and the mark is active, then the selected region is forwarded.
-See also documentation for `\\[mh-send]' function."
-  (interactive (list (mh-read-address "To: ")
-                     (mh-read-address "Cc: ")
-                     (cond
-                      ((mh-mark-active-p t)
-                       (mh-region-to-msg-list (region-beginning) (region-end)))
-                      (current-prefix-arg
-                       (mh-read-seq-default "Forward" t))
-                      (t
-                       (mh-get-msg-num t)))))
+(defun mh-forward (to cc &optional range)
+  "Forward message.
+
+You are prompted for the TO and CC recipients. You are given a
+draft to edit that looks like it would if you had run the MH
+command \"forw\". You can then add some text.
+
+You can forward several messages by using a RANGE. All of the
+messages in the range are inserted into your draft. Check the
+documentation of `mh-interactive-range' to see how RANGE is read
+in interactive use.
+
+The hook `mh-forward-hook' is called on the draft.
+
+See also `mh-compose-forward-as-mime-flag',
+`mh-forward-subject-format', and `mh-send'."
+  (interactive (list (mh-interactive-read-address "To: ")
+                     (mh-interactive-read-address "Cc: ")
+                     (mh-interactive-range "Forward")))
   (let* ((folder mh-current-folder)
-         (msgs (cond ((numberp msg-or-seq) (list msg-or-seq))
-                     ((listp msg-or-seq) msg-or-seq)
-                     (t (mh-seq-to-msgs msg-or-seq))))
+         (msgs (mh-range-to-msg-list range))
          (config (current-window-configuration))
          (fwd-msg-file (mh-msg-filename (car msgs) folder))
          ;; forw always leaves file in "draft" since it doesn't have -draft
          (draft-name (expand-file-name "draft" mh-user-path))
          (draft (cond ((or (not (file-exists-p draft-name))
-                           (y-or-n-p "The file 'draft' exists.  Discard it? "))
-                       (mh-exec-cmd "forw" "-build" (if mh-nmh-flag "-mime")
-                                    mh-current-folder msgs)
+                           (y-or-n-p "The file draft exists; discard it? "))
+                       (mh-exec-cmd "forw" "-build"
+                                    (if (and (mh-variant-p 'nmh)
+                                             mh-compose-forward-as-mime-flag)
+                                        "-mime")
+                                    mh-current-folder
+                                    (mh-coalesce-msg-list msgs))
                        (prog1
                            (mh-read-draft "" draft-name t)
                          (mh-insert-fields "To:" to "Cc:" cc)
@@ -353,16 +475,13 @@ See also documentation for `\\[mh-send]' function."
         (setq orig-from (mh-get-header-field "From:"))
         (setq orig-subject (mh-get-header-field "Subject:")))
       (let ((forw-subject
-             (mh-forwarded-letter-subject orig-from orig-subject))
-            (compose))
+             (mh-forwarded-letter-subject orig-from orig-subject)))
         (mh-insert-fields "Subject:" forw-subject)
         (goto-char (point-min))
-        ;; If using MML, translate mhn
-        (if (equal mh-compose-insertion 'gnus)
+        ;; If using MML, translate MH-style directive
+        (if (equal mh-compose-insertion 'mml)
             (save-excursion
-              (setq compose t)
-              (re-search-forward (format "^\\(%s\\)?$"
-                                         mh-mail-header-separator))
+              (goto-char (mh-mail-header-end))
               (while
                   (re-search-forward
                    "^#forw \\[\\([^]]+\\)\\] \\(+\\S-+\\) \\(.*\\)$"
@@ -382,17 +501,17 @@ See also documentation for `\\[mh-send]' function."
         ;; Postition just before forwarded message
         (if (re-search-forward "^------- Forwarded Message" nil t)
             (forward-line -1)
-          (re-search-forward (format "^\\(%s\\)?$" mh-mail-header-separator))
+          (goto-char (mh-mail-header-end))
           (forward-line 1))
         (delete-other-windows)
         (mh-add-msgs-to-seq msgs 'forwarded t)
-        (mh-compose-and-send-mail draft "" folder msg-or-seq
+        (mh-compose-and-send-mail draft "" folder msgs
                                   to forw-subject cc
                                   mh-note-forw "Forwarded:"
                                   config)
-        (if compose
-            (setq mh-mml-compose-insert-flag t))
-        (mh-letter-mode-message)))))
+        (mh-letter-mode-message)
+        (mh-letter-adjust-point)
+        (run-hooks 'mh-forward-hook)))))
 
 (defun mh-forwarded-letter-subject (from subject)
   "Return a Subject suitable for a forwarded message.
@@ -407,116 +526,118 @@ Original message has headers FROM and SUBJECT."
            (setq from (substring from (1+ comment) (1- (length from)))))))
   (format mh-forward-subject-format from subject))
 
-;;;###autoload
-(defun mh-smail-other-window ()
-  "Compose and send mail in other window with the MH mail system.
-This function is an entry point to MH-E, the Emacs front end
-to the MH mail system.
+;;;###mh-autoload
+(defun mh-redistribute (to cc &optional message)
+  "Redistribute a message.
 
-See documentation of `\\[mh-send]' for more details on composing mail."
-  (interactive)
-  (mh-find-path)
-  (call-interactively 'mh-send-other-window))
+This command is similar in function to forwarding mail, but it
+does not allow you to edit the message, nor does it add your name
+to the \"From\" header field. It appears to the recipient as if
+the message had come from the original sender. When you run this
+command, you are prompted for the TO and CC recipients. The
+default MESSAGE is the current message.
 
-;;;###mh-autoload
-(defun mh-redistribute (to cc &optional msg)
-  "Redistribute displayed message to recipients TO and CC.
-Use optional argument MSG to redistribute another message.
-Depending on how your copy of MH was compiled, you may need to change the
-setting of the variable `mh-redist-full-contents'.  See its documentation."
+Also investigate the command \\[mh-edit-again] for another way to
+redistribute messages.
+
+See also `mh-redist-full-contents-flag'."
   (interactive (list (mh-read-address "Redist-To: ")
                      (mh-read-address "Redist-Cc: ")
                      (mh-get-msg-num t)))
-  (or msg
-      (setq msg (mh-get-msg-num t)))
+  (or message
+      (setq message (mh-get-msg-num t)))
   (save-window-excursion
     (let ((folder mh-current-folder)
           (draft (mh-read-draft "redistribution"
-                                (if mh-redist-full-contents
-                                    (mh-msg-filename msg)
+                                (if mh-redist-full-contents-flag
+                                    (mh-msg-filename message)
                                   nil)
                                 nil)))
       (mh-goto-header-end 0)
       (insert "Resent-To: " to "\n")
       (if (not (equal cc "")) (insert "Resent-cc: " cc "\n"))
-      (mh-clean-msg-header (point-min)
-                           "^Message-Id:\\|^Received:\\|^Return-Path:\\|^Sender:\\|^Date:\\|^From:"
-                           nil)
+      (mh-clean-msg-header
+       (point-min)
+       "^Message-Id:\\|^Received:\\|^Return-Path:\\|^Sender:\\|^Date:\\|^From:"
+       nil)
       (save-buffer)
       (message "Redistributing...")
-      (if (not mh-redist-background)
-          (if mh-redist-full-contents
-              (call-process "/bin/sh" nil 0 nil "-c"
-                            (format "mhdist=1 mhaltmsg=%s %s -push %s"
-                                    buffer-file-name
-                                    (expand-file-name mh-send-prog mh-progs)
-                                    buffer-file-name))
-            (call-process "/bin/sh" nil 0 nil "-c"
-                          (format
-                           "mhdist=1 mhaltmsg=%s mhannotate=1 %s -push %s"
-                           (mh-msg-filename msg folder)
-                           (expand-file-name mh-send-prog mh-progs)
-                           buffer-file-name))))
-      (mh-annotate-msg msg folder mh-note-dist
-                       "-component" "Resent:"
-                       "-text" (format "\"%s %s\"" to cc))
-      (if mh-redist-background
-          (mh-exec-cmd-daemon "/bin/sh" nil "-c"
-                              (format "mhdist=1 mhaltmsg=%s %s %s %s"
-                                      (if mh-redist-full-contents
-                                          buffer-file-name
-                                        (mh-msg-filename msg folder))
-                                      (if mh-redist-full-contents
-                                          ""
-                                        "mhannotate=1")
-                                      (mh-expand-file-name "send" mh-progs)
-                                      buffer-file-name)))
+      (let ((env "mhdist=1"))
+        ;; Setup environment...
+        (setq env (concat env " mhaltmsg="
+                          (if mh-redist-full-contents-flag
+                              buffer-file-name
+                            (mh-msg-filename message folder))))
+        (unless mh-redist-full-contents-flag
+          (setq env (concat env " mhannotate=1")))
+        ;; Redistribute...
+        (if mh-redist-background
+            (mh-exec-cmd-env-daemon env mh-send-prog nil buffer-file-name)
+          (mh-exec-cmd-error env mh-send-prog "-push" buffer-file-name))
+        ;; Annotate...
+        (mh-annotate-msg message folder mh-note-dist
+                         "-component" "Resent:"
+                         "-text" (format "\"%s %s\"" to cc)))
       (kill-buffer draft)
       (message "Redistributing...done"))))
 
-(defun mh-show-buffer-message-number (&optional buffer)
-  "Message number of displayed message in corresponding show buffer.
-Return nil if show buffer not displayed.
-If in `mh-letter-mode', don't display the message number being replied to,
-but rather the message number of the show buffer associated with our
-originating folder buffer.
-Optional argument BUFFER can be used to specify the buffer."
-  (save-excursion
-    (if buffer
-        (set-buffer buffer))
-    (cond ((eq major-mode 'mh-show-mode)
-           (let ((number-start (mh-search-from-end ?/ buffer-file-name)))
-             (car (read-from-string (substring buffer-file-name
-                                               (1+ number-start))))))
-          ((and (eq major-mode 'mh-folder-mode)
-                mh-show-buffer
-                (get-buffer mh-show-buffer))
-           (mh-show-buffer-message-number mh-show-buffer))
-          ((and (eq major-mode 'mh-letter-mode)
-                mh-sent-from-folder
-                (get-buffer mh-sent-from-folder))
-           (mh-show-buffer-message-number mh-sent-from-folder))
-          (t
-           nil))))
-
 ;;;###mh-autoload
 (defun mh-reply (message &optional reply-to includep)
-  "Reply to MESSAGE (default: current message).
-If the optional argument REPLY-TO is not given, prompts for type of addresses
-to reply to:
-   from    sender only,
-   to      sender and primary recipients,
-   cc/all  sender and all recipients.
-If optional prefix argument INCLUDEP provided, then include the message
-in the reply using filter `mhl.reply' in your MH directory.
-If the file named by `mh-repl-formfile' exists, it is used as a skeleton
-for the reply.  See also documentation for `\\[mh-send]' function."
+  "Reply to a MESSAGE.
+
+When you reply to a message, you are first prompted with \"Reply
+to whom?\" (unless the optional argument REPLY-TO is provided).
+You have several choices here.
+
+     Response     Reply Goes To
+
+     from         The person who sent the message. This is the
+                  default, so <RET> is sufficient.
+
+     to           Replies to the sender, plus all recipients in the
+                  \"To:\" header field.
+
+     all cc       Forms a reply to the addresses in the
+                  \"Mail-Followup-To:\" header field if one
+                  exists; otherwise forms a reply to the sender,
+                  plus all recipients.
+
+Depending on your answer, \"repl\" is given a different argument
+to form your reply. Specifically, a choice of \"from\" or none at
+all runs \"repl -nocc all\", and a choice of \"to\" runs \"repl
+-cc to\". Finally, either \"cc\" or \"all\" runs \"repl -cc all
+-nocc me\".
+
+Two windows are then created. One window contains the message to
+which you are replying in an MH-Show buffer. Your draft, in
+MH-Letter mode (*note `mh-letter-mode'), is in the other window.
+If the reply draft was not one that you expected, check the
+things that affect the behavior of \"repl\" which include the
+\"repl:\" profile component and the \"replcomps\" and
+\"replgroupcomps\" files.
+
+If you supply a prefix argument INCLUDEP, the message you are
+replying to is inserted in your reply after having first been run
+through \"mhl\" with the format file \"mhl.reply\".
+
+Alternatively, you can customize the option `mh-yank-behavior'
+and choose one of its \"Automatically\" variants to do the same
+thing. If you do so, the prefix argument has no effect.
+
+Another way to include the message automatically in your draft is
+to use \"repl: -filter repl.filter\" in your MH profile.
+
+If you wish to customize the header or other parts of the reply
+draft, please see \"repl\" and \"mh-format\".
+
+See also `mh-reply-show-message-flag',
+`mh-reply-default-reply-to', and `mh-send'."
   (interactive (list
                 (mh-get-msg-num t)
                 (let ((minibuffer-help-form
                        "from => Sender only\nto => Sender and primary recipients\ncc or all => Sender and all recipients"))
                   (or mh-reply-default-reply-to
-                      (completing-read "Reply to whom? (from, to, all) [from]: "
+                      (completing-read "Reply to whom (default from): "
                                        '(("from") ("to") ("cc") ("all"))
                                        nil
                                        t)))
@@ -525,7 +646,7 @@ for the reply.  See also documentation for `\\[mh-send]' function."
          (show-buffer mh-show-buffer)
          (config (current-window-configuration))
          (group-reply (or (equal reply-to "cc") (equal reply-to "all")))
-         (form-file (cond ((and mh-nmh-flag group-reply
+         (form-file (cond ((and (mh-variant-p 'nmh 'mu-mh) group-reply
                                 (stringp mh-repl-group-formfile))
                            mh-repl-group-formfile)
                           ((stringp mh-repl-formfile) mh-repl-formfile)
@@ -539,11 +660,11 @@ for the reply.  See also documentation for `\\[mh-send]' function."
                         '("-nocc" "all"))
                        ((equal reply-to "to")
                         '("-cc" "to"))
-                       (group-reply (if mh-nmh-flag
+                       (group-reply (if (mh-variant-p 'nmh 'mu-mh)
                                         '("-group" "-nocc" "me")
                                       '("-cc" "all" "-nocc" "me"))))
-                 (cond ((or (eq mh-yank-from-start-of-msg 'autosupercite)
-                            (eq mh-yank-from-start-of-msg 'autoattrib))
+                 (cond ((or (eq mh-yank-behavior 'autosupercite)
+                            (eq mh-yank-behavior 'autoattrib))
                         '("-noformat"))
                        (includep '("-filter" "mhl.reply"))
                        (t '())))
@@ -566,8 +687,8 @@ for the reply.  See also documentation for `\\[mh-send]' function."
         (message "Composing a reply...done")
         (mh-compose-and-send-mail draft "" folder message to subject cc
                                   mh-note-repl "Replied:" config))
-      (when (and (or (eq 'autosupercite mh-yank-from-start-of-msg)
-                     (eq 'autoattrib mh-yank-from-start-of-msg))
+      (when (and (or (eq 'autosupercite mh-yank-behavior)
+                     (eq 'autoattrib mh-yank-behavior))
                  (eq (mh-show-buffer-message-number) mh-sent-from-msg))
         (undo-boundary)
         (mh-yank-cur-msg))
@@ -575,41 +696,73 @@ for the reply.  See also documentation for `\\[mh-send]' function."
 
 ;;;###mh-autoload
 (defun mh-send (to cc subject)
-  "Compose and send a letter.
+  "Compose a message.
 
-Do not call this function from outside MH-E; use \\[mh-smail] instead.
+Your letter appears in an Emacs buffer whose mode is
+MH-Letter (see `mh-letter-mode').
 
-The file named by `mh-comp-formfile' will be used as the form.
-The letter is composed in `mh-letter-mode'; see its documentation for more
-details.
-If `mh-compose-letter-function' is defined, it is called on the draft and
-passed three arguments: TO, CC, and SUBJECT."
+The arguments TO, CC, and SUBJECT can be used to prefill the
+draft fields or suppress the prompts if `mh-compose-prompt-flag'
+is on. They are also passed to the function set in the option
+`mh-compose-letter-function'.
+
+See also `mh-insert-x-mailer-flag' and `mh-letter-mode-hook'.
+
+Outside of an MH-Folder buffer (`mh-folder-mode'), you must call
+either \\[mh-smail] or \\[mh-smail-other-window] to compose a new
+message."
   (interactive (list
-                (mh-read-address "To: ")
-                (mh-read-address "Cc: ")
-                (read-string "Subject: ")))
+                (mh-interactive-read-address "To: ")
+                (mh-interactive-read-address "Cc: ")
+                (mh-interactive-read-string "Subject: ")))
   (let ((config (current-window-configuration)))
     (delete-other-windows)
     (mh-send-sub to cc subject config)))
 
-;;;###mh-autoload
-(defun mh-send-other-window (to cc subject)
-  "Compose and send a letter in another window.
+\f
 
-Do not call this function from outside MH-E; use \\[mh-smail-other-window]
-instead.
+;;; Support Routines
 
-The file named by `mh-comp-formfile' will be used as the form.
-The letter is composed in `mh-letter-mode'; see its documentation for more
-details.
-If `mh-compose-letter-function' is defined, it is called on the draft and
-passed three arguments: TO, CC, and SUBJECT."
-  (interactive (list
-                (mh-read-address "To: ")
-                (mh-read-address "Cc: ")
-                (read-string "Subject: ")))
-  (let ((pop-up-windows t))
-    (mh-send-sub to cc subject (current-window-configuration))))
+(defun mh-interactive-read-address (prompt)
+  "Read an address.
+If `mh-compose-prompt-flag' is non-nil, then read an address with
+PROMPT.
+Otherwise return the empty string."
+  (if mh-compose-prompt-flag (mh-read-address prompt) ""))
+
+(defun mh-interactive-read-string (prompt)
+  "Read a string.
+If `mh-compose-prompt-flag' is non-nil, then read a string with
+PROMPT.
+Otherwise return the empty string."
+  (if mh-compose-prompt-flag (read-string prompt) ""))
+
+;;;###mh-autoload
+(defun mh-show-buffer-message-number (&optional buffer)
+  "Message number of displayed message in corresponding show buffer.
+
+Return nil if show buffer not displayed.
+If in `mh-letter-mode', don't display the message number being replied
+to, but rather the message number of the show buffer associated with
+our originating folder buffer.
+Optional argument BUFFER can be used to specify the buffer."
+  (save-excursion
+    (if buffer
+        (set-buffer buffer))
+    (cond ((eq major-mode 'mh-show-mode)
+           (let ((number-start (mh-search-from-end ?/ buffer-file-name)))
+             (string-to-number (substring buffer-file-name
+                                          (1+ number-start)))))
+          ((and (eq major-mode 'mh-folder-mode)
+                mh-show-buffer
+                (get-buffer mh-show-buffer))
+           (mh-show-buffer-message-number mh-show-buffer))
+          ((and (eq major-mode 'mh-letter-mode)
+                mh-sent-from-folder
+                (get-buffer mh-sent-from-folder))
+           (mh-show-buffer-message-number mh-sent-from-folder))
+          (t
+           nil))))
 
 (defun mh-send-sub (to cc subject config)
   "Do the real work of composing and sending a letter.
@@ -630,36 +783,30 @@ CONFIG is the window configuration before sending mail."
                        (setq components
                              (expand-file-name mh-comp-formfile mh-lib)))
                       components)
-                     ((file-exists-p
-                       (setq components
-                             (expand-file-name mh-comp-formfile
-                                               ;; What is this mh-etc ??  -sm
-                                               ;; This is dead code, so
-                                               ;; remove it.
-                                        ;(and (boundp 'mh-etc) mh-etc)
-                                               )))
-                      components)
                      (t
-                      (error (format "Can't find components file \"%s\""
-                                     components)))))
+                      (error "Can't find %s in %s or %s"
+                             mh-comp-formfile mh-user-path mh-lib))))
                   nil)))
       (mh-insert-fields "To:" to "Subject:" subject "Cc:" cc)
       (goto-char (point-max))
       (mh-compose-and-send-mail draft "" folder msg-num
                                 to subject cc
                                 nil nil config)
-      (mh-letter-mode-message))))
+      (mh-letter-mode-message)
+      (mh-letter-adjust-point))))
 
 (defun mh-read-draft (use initial-contents delete-contents-file)
   "Read draft file into a draft buffer and make that buffer the current one.
-USE is a message used for prompting about the intended use of the message.
+
+USE is a message used for prompting about the intended use of the
+message.
 INITIAL-CONTENTS is filename that is read into an empty buffer, or nil
-if buffer should not be modified.  Delete the initial-contents file if
+if buffer should not be modified. Delete the initial-contents file if
 DELETE-CONTENTS-FILE flag is set.
 Returns the draft folder's name.
-If the draft folder facility is enabled in ~/.mh_profile, a new buffer is
-used each time and saved in the draft folder.  The draft file can then be
-reused."
+If the draft folder facility is enabled in ~/.mh_profile, a new buffer
+is used each time and saved in the draft folder. The draft file can
+then be reused."
   (cond (mh-draft-folder
          (let ((orig-default-dir default-directory)
                (draft-file-name (mh-new-draft-name)))
@@ -705,16 +852,6 @@ reused."
     (mh-exec-cmd-quiet t "mhpath" mh-draft-folder "new")
     (buffer-substring (point-min) (1- (point-max)))))
 
-(defun mh-annotate-msg (msg buffer note &rest args)
-  "Mark MSG in BUFFER with character NOTE and annotate message with ARGS."
-  (apply 'mh-exec-cmd "anno" buffer msg args)
-  (save-excursion
-    (cond ((get-buffer buffer)          ; Buffer may be deleted
-           (set-buffer buffer)
-           (if (numberp msg)
-               (mh-notate msg note (1+ mh-cmd-note))
-             (mh-notate-seq msg note (1+ mh-cmd-note)))))))
-
 (defun mh-insert-fields (&rest name-values)
   "Insert the NAME-VALUES pairs in the current buffer.
 If the field exists, append the value to it.
@@ -723,7 +860,10 @@ Do not insert any pairs whose value is the empty string."
     (while name-values
       (let ((field-name (car name-values))
             (value (car (cdr name-values))))
-        (cond ((equal value "")
+        (if (not (string-match "^.*:$" field-name))
+            (setq field-name (concat field-name ":")))
+        (cond ((or (null value)
+                   (equal value ""))
                nil)
               ((mh-position-on-field field-name)
                (insert " " (or value "")))
@@ -731,407 +871,6 @@ Do not insert any pairs whose value is the empty string."
                (insert field-name " " value "\n")))
         (setq name-values (cdr (cdr name-values)))))))
 
-(defun mh-position-on-field (field &optional ignored)
-  "Move to the end of the FIELD in the header.
-Move to end of entire header if FIELD not found.
-Returns non-nil iff FIELD was found.
-The optional second arg is for pre-version 4 compatibility and is IGNORED."
-  (cond ((mh-goto-header-field field)
-         (mh-header-field-end)
-         t)
-        ((mh-goto-header-end 0)
-         nil)))
-
-(defun mh-get-header-field (field)
-  "Find and return the body of FIELD in the mail header.
-Returns the empty string if the field is not in the header of the
-current buffer."
-  (if (mh-goto-header-field field)
-      (progn
-        (skip-chars-forward " \t")      ;strip leading white space in body
-        (let ((start (point)))
-          (mh-header-field-end)
-          (buffer-substring-no-properties start (point))))
-    ""))
-
-(fset 'mh-get-field 'mh-get-header-field) ;MH-E 4 compatibility
-
-(defun mh-goto-header-field (field)
-  "Move to FIELD in the message header.
-Move to the end of the FIELD name, which should end in a colon.
-Returns t if found, nil if not."
-  (goto-char (point-min))
-  (let ((case-fold-search t)
-        (headers-end (save-excursion
-                       (mh-goto-header-end 0)
-                       (point))))
-    (re-search-forward (format "^%s" field) headers-end t)))
-
-(defun mh-goto-header-end (arg)
-  "Move the cursor ARG lines after the header."
-  (if (re-search-forward "^-*$" nil nil)
-      (forward-line arg)))
-
-(defun mh-extract-from-header-value ()
-  "Extract From: string from header."
-  (save-excursion
-    (if (not (mh-goto-header-field "From:"))
-        (error "No From header line found")
-      (skip-chars-forward " \t")
-      (buffer-substring-no-properties
-       (point) (progn (mh-header-field-end)(point))))))
-
-\f
-
-;;; Mode for composing and sending a draft message.
-
-(put 'mh-letter-mode 'mode-class 'special)
-
-;;; Menu extracted from mh-menubar.el V1.1 (31 July 2001)
-(eval-when-compile (defvar mh-letter-menu nil))
-(cond
- ((fboundp 'easy-menu-define)
-  (easy-menu-define
-    mh-letter-menu mh-letter-mode-map "Menu for MH-E letter mode."
-    '("Letter"
-      ["Send This Draft"          mh-send-letter t]
-      ["Split Current Line"       mh-open-line t]
-      ["Check Recipient"          mh-check-whom t]
-      ["Yank Current Message"     mh-yank-cur-msg t]
-      ["Insert a Message..."      mh-insert-letter t]
-      ["Insert Signature"         mh-insert-signature t]
-      ["GPG Sign message"
-       mh-mml-secure-message-sign-pgpmime mh-gnus-pgp-support-flag]
-      ["GPG Encrypt message"
-       mh-mml-secure-message-encrypt-pgpmime mh-gnus-pgp-support-flag]
-      ["Compose Insertion (MIME)..."      mh-compose-insertion t]
-      ;;    ["Compose Compressed tar (MIME)..."
-      ;;mh-mhn-compose-external-compressed-tar t]
-      ;;    ["Compose Anon FTP (MIME)..."       mh-mhn-compose-anon-ftp t]
-      ["Compose Forward (MIME)..."        mh-compose-forward t]
-      ;; The next two will have to be merged. But I also need to make sure the
-      ;; user can't mix directives of both types.
-      ["Pull in All Compositions (mhn)"
-       mh-edit-mhn mh-mhn-compose-insert-flag]
-      ["Pull in All Compositions (gnus)"
-       mh-mml-to-mime mh-mml-compose-insert-flag]
-      ["Revert to Non-MIME Edit (mhn)"
-       mh-revert-mhn-edit (equal mh-compose-insertion 'mhn)]
-      ["Kill This Draft"          mh-fully-kill-draft t]))))
-
-;;; Help Messages
-;;; Group messages logically, more or less.
-(defvar mh-letter-mode-help-messages
-  '((nil
-     "Send letter:          \\[mh-send-letter]"
-     "\t\tOpen line:            \\[mh-open-line]\n"
-     "Kill letter:          \\[mh-fully-kill-draft]"
-     "\t\tInsert:\n"
-     "Check recipients:     \\[mh-check-whom]"
-     "\t\t  Current message:    \\[mh-yank-cur-msg]\n"
-     "Encrypt message:      \\[mh-mml-secure-message-encrypt-pgpmime]"
-     "\t\t  Attachment:         \\[mh-compose-insertion]\n"
-     "Sign message:         \\[mh-mml-secure-message-sign-pgpmime]"
-     "\t\t  Message to forward: \\[mh-compose-forward]\n"
-     "                          "
-     "\t\t  Signature:          \\[mh-insert-signature]"))
-  "Key binding cheat sheet.
-
-This is an associative array which is used to show the most common commands.
-The key is a prefix char. The value is one or more strings which are
-concatenated together and displayed in the minibuffer if ? is pressed after
-the prefix character. The special key nil is used to display the
-non-prefixed commands.
-
-The substitutions described in `substitute-command-keys' are performed as
-well.")
-
-;;;###mh-autoload
-(defun mh-fill-paragraph-function (arg)
-  "Fill paragraph at or after point.
-Prefix ARG means justify as well. This function enables `fill-paragraph' to
-work better in MH-Letter mode."
-  (interactive "P")
-  (let ((fill-paragraph-function) (fill-prefix))
-    (if (mh-in-header-p)
-        (mail-mode-fill-paragraph arg)
-      (fill-paragraph arg))))
-
-;;;###autoload
-(define-derived-mode mh-letter-mode text-mode "MH-Letter"
-  "Mode for composing letters in MH-E.\\<mh-letter-mode-map>
-
-When you have finished composing, type \\[mh-send-letter] to send the message
-using the MH mail handling system.
-
-There are two types of MIME directives used by MH-E: Gnus and MH. The option
-`mh-compose-insertion' controls what type of directives are inserted by MH-E
-commands. These directives can be converted to MIME body parts by running
-\\[mh-edit-mhn] for mhn directives or \\[mh-mml-to-mime] for Gnus directives.
-This step is mandatory if these directives are added manually. If the
-directives are inserted with MH-E commands such as \\[mh-compose-insertion],
-the directives are expanded automatically when the letter is sent.
-
-Options that control this mode can be changed with
-\\[customize-group]; specify the \"mh-compose\" group.
-
-When a message is composed, the hooks `text-mode-hook' and
-`mh-letter-mode-hook' are run.
-
-\\{mh-letter-mode-map}"
-
-  (or mh-user-path (mh-find-path))
-  (make-local-variable 'mh-send-args)
-  (make-local-variable 'mh-annotate-char)
-  (make-local-variable 'mh-annotate-field)
-  (make-local-variable 'mh-previous-window-config)
-  (make-local-variable 'mh-sent-from-folder)
-  (make-local-variable 'mh-sent-from-msg)
-  (make-local-variable 'mail-header-separator)
-  (setq mail-header-separator mh-mail-header-separator) ;override sendmail.el
-  (make-local-variable 'mh-help-messages)
-  (setq mh-help-messages mh-letter-mode-help-messages)
-
-  ;; From sendmail.el for proper paragraph fill
-  ;; sendmail.el also sets a normal-auto-fill-function (not done here)
-  (make-local-variable 'paragraph-separate)
-  (make-local-variable 'paragraph-start)
-  (make-local-variable 'fill-paragraph-function)
-  (setq fill-paragraph-function 'mh-fill-paragraph-function)
-  (make-local-variable 'adaptive-fill-regexp)
-  (setq adaptive-fill-regexp
-        (concat adaptive-fill-regexp
-                "\\|[ \t]*[-[:alnum:]]*>+[ \t]*"))
-  (make-local-variable 'adaptive-fill-first-line-regexp)
-  (setq adaptive-fill-first-line-regexp
-        (concat adaptive-fill-first-line-regexp
-                "\\|[ \t]*[-[:alnum:]]*>+[ \t]*"))
-  ;; `-- ' precedes the signature.  `-----' appears at the start of the
-  ;; lines that delimit forwarded messages.
-  ;; Lines containing just >= 3 dashes, perhaps after whitespace,
-  ;; are also sometimes used and should be separators.
-  (setq paragraph-start (concat (regexp-quote mail-header-separator)
-                                "\\|\t*\\([-|#;>* ]\\|(?[0-9]+[.)]\\)+$"
-                                "\\|[ \t]*[[:alnum:]]*>+[ \t]*$\\|[ \t]*$\\|"
-                                "-- $\\|---+$\\|"
-                                page-delimiter))
-  (setq paragraph-separate paragraph-start)
-  ;; --- End of code from sendmail.el ---
-
-  (if (and (boundp 'tool-bar-mode) tool-bar-mode)
-      (set (make-local-variable 'tool-bar-map) mh-letter-tool-bar-map))
-  (make-local-variable 'font-lock-defaults)
-  (cond
-   ((or (equal mh-highlight-citation-p 'font-lock)
-        (equal mh-highlight-citation-p 'gnus))
-    ;; Let's use font-lock even if gnus is used in show-mode.  The reason
-    ;; is that gnus uses static text properties which are not appropriate
-    ;; for a buffer that will be edited.  So the choice here is either fontify
-    ;; the citations and header...
-    (setq font-lock-defaults '(mh-show-font-lock-keywords-with-cite t)))
-   (t
-    ;; ...or the header only
-    (setq font-lock-defaults '(mh-show-font-lock-keywords t))))
-  (easy-menu-add mh-letter-menu)
-  ;; See if a "forw: -mime" message containing a MIME composition.
-  ;; Mode clears local vars, so can't do this in mh-forward.
-  (save-excursion
-    (goto-char (point-min))
-    (when (and (re-search-forward
-                (format "^\\(%s\\)?$" mail-header-separator) nil t)
-               (= 0 (forward-line 1))
-               (looking-at "^#forw"))
-      (require 'mh-mime)            ;Need mh-mhn-compose-insert-flag local var
-      (setq mh-mhn-compose-insert-flag t)))
-  (setq fill-column mh-letter-fill-column)
-  ;; If text-mode-hook turned on auto-fill, tune it for messages
-  (when auto-fill-function
-    (make-local-variable 'auto-fill-function)
-    (setq auto-fill-function 'mh-auto-fill-for-letter)))
-
-(defun mh-auto-fill-for-letter ()
-  "Perform auto-fill for message.
-Header is treated specially by inserting a tab before continuation lines."
-  (if (mh-in-header-p)
-      (let ((fill-prefix "\t"))
-        (do-auto-fill))
-    (do-auto-fill)))
-
-(defun mh-insert-header-separator ()
-  "Insert `mh-mail-header-separator', if absent."
-  (save-excursion
-    (goto-char (point-min))
-    (rfc822-goto-eoh)
-    (if (looking-at "$")
-        (insert mh-mail-header-separator))))
-
-;;;###mh-autoload
-(defun mh-to-field ()
-  "Move point to the end of a specified header field.
-The field is indicated by the previous keystroke (the last keystroke
-of the command) according to the list in the variable `mh-to-field-choices'.
-Create the field if it does not exist.  Set the mark to point before moving."
-  (interactive)
-  (expand-abbrev)
-  (let ((target (cdr (or (assoc (char-to-string (logior last-input-char ?`))
-                                mh-to-field-choices)
-                         ;; also look for a char for version 4 compat
-                         (assoc (logior last-input-char ?`)
-                                mh-to-field-choices))))
-        (case-fold-search t))
-    (push-mark)
-    (cond ((mh-position-on-field target)
-           (let ((eol (point)))
-             (skip-chars-backward " \t")
-             (delete-region (point) eol))
-           (if (and (not (eq (logior last-input-char ?`) ?s))
-                    (save-excursion
-                      (backward-char 1)
-                      (not (looking-at "[:,]"))))
-               (insert ", ")
-             (insert " ")))
-          (t
-           (if (mh-position-on-field "To:")
-               (forward-line 1))
-           (insert (format "%s \n" target))
-           (backward-char 1)))))
-
-;;;###mh-autoload
-(defun mh-to-fcc (&optional folder)
-  "Insert an Fcc: FOLDER field in the current message.
-Prompt for the field name with a completion list of the current folders."
-  (interactive)
-  (or folder
-      (setq folder (mh-prompt-for-folder
-                    "Fcc"
-                    (or (and mh-default-folder-for-message-function
-                             (save-excursion
-                               (goto-char (point-min))
-                               (funcall
-                                mh-default-folder-for-message-function)))
-                        "")
-                    t)))
-  (let ((last-input-char ?\C-f))
-    (expand-abbrev)
-    (save-excursion
-      (mh-to-field)
-      (insert (if (mh-folder-name-p folder)
-                  (substring folder 1)
-                folder)))))
-
-;;;###mh-autoload
-(defun mh-insert-signature ()
-  "Insert the file named by `mh-signature-file-name' at point.
-The value of `mh-letter-insert-signature-hook' is a list of functions to be
-called, with no arguments, before the signature is actually inserted."
-  (interactive)
-  (let ((mh-signature-file-name mh-signature-file-name))
-    (run-hooks 'mh-letter-insert-signature-hook)
-    (if mh-signature-file-name
-        (insert-file-contents mh-signature-file-name)))
-  (force-mode-line-update))
-
-;;;###mh-autoload
-(defun mh-check-whom ()
-  "Verify recipients of the current letter, showing expansion of any aliases."
-  (interactive)
-  (let ((file-name buffer-file-name))
-    (save-buffer)
-    (message "Checking recipients...")
-    (mh-in-show-buffer (mh-recipients-buffer)
-      (bury-buffer (current-buffer))
-      (erase-buffer)
-      (mh-exec-cmd-output "whom" t file-name))
-    (message "Checking recipients...done")))
-
-(defun mh-tidy-draft-buffer ()
-  "Run when a draft buffer is destroyed."
-  (let ((buffer (get-buffer mh-recipients-buffer)))
-    (if buffer
-       (kill-buffer buffer))))
-
-\f
-
-;;; Routines to compose and send a letter.
-
-(defun mh-insert-x-face ()
-  "Append X-Face field to header.
-If the field already exists, this function does nothing."
-  (when (and (file-exists-p mh-x-face-file)
-             (file-readable-p mh-x-face-file))
-    (save-excursion
-      (when (null (mh-position-on-field "X-Face"))
-        (insert "X-Face: ")
-        (goto-char (+ (point) (cadr (insert-file-contents mh-x-face-file))))
-        (if (not (looking-at "^"))
-            (insert "\n"))))))
-
-(defun mh-insert-x-mailer ()
-  "Append an X-Mailer field to the header.
-The versions of MH-E, Emacs, and MH are shown."
-
-  ;; Lazily initialize mh-x-mailer-string.
-  (when (null mh-x-mailer-string)
-    (save-window-excursion
-      ;; User would be confused if version info buffer disappeared magically,
-      ;; so don't delete buffer if it already existed.
-      (let ((info-buffer-exists-p (get-buffer mh-info-buffer)))
-        (mh-version)
-        (set-buffer mh-info-buffer)
-        (if mh-nmh-flag
-            (search-forward-regexp "^nmh-\\(\\S +\\)")
-          (search-forward-regexp "^MH \\(\\S +\\)" nil t))
-        (let ((x-mailer-mh (buffer-substring (match-beginning 1)
-                                             (match-end 1))))
-          (setq mh-x-mailer-string
-                (format "MH-E %s; %s %s; %sEmacs %s"
-                        mh-version (if mh-nmh-flag "nmh" "MH") x-mailer-mh
-                        (if mh-xemacs-flag "X" "GNU ")
-                        (cond ((not mh-xemacs-flag) emacs-version)
-                              ((string-match "[0-9.]*\\( +\([ a-z]+[0-9]+\)\\)?"
-                                             emacs-version)
-                               (match-string 0 emacs-version))
-                              (t (format "%s.%s"
-                                         emacs-major-version
-                                         emacs-minor-version))))))
-        (if (not info-buffer-exists-p)
-            (kill-buffer mh-info-buffer)))))
-  ;; Insert X-Mailer, but only if it doesn't already exist.
-  (save-excursion
-    (when (null (mh-goto-header-field "X-Mailer"))
-      (mh-insert-fields "X-Mailer:" mh-x-mailer-string))))
-
-(defun mh-regexp-in-field-p (regexp &rest fields)
-  "Non-nil means REGEXP was found in FIELDS."
-  (save-excursion
-    (let ((search-result nil)
-          (field))
-      (while fields
-        (setq field (car fields))
-        (if (and (mh-goto-header-field field)
-                 (re-search-forward
-                  regexp (save-excursion (mh-header-field-end)(point)) t))
-            (setq fields nil
-                  search-result t)
-          (setq fields (cdr fields))))
-      search-result)))
-
-(defun mh-insert-mail-followup-to ()
-  "Insert Mail-Followup-To: if To or Cc match `mh-insert-mail-followup-to-list'."
-  (save-excursion
-    (if (and (or (mh-goto-header-field "To:")(mh-goto-header-field "cc:"))
-             (not (mh-goto-header-field "Mail-Followup-To: ")))
-        (let ((list mh-insert-mail-followup-to-list))
-          (while list
-            (let ((regexp (nth 0 (car list)))
-                  (entry  (nth 1 (car list))))
-              (when (mh-regexp-in-field-p regexp "To:" "cc:")
-                (if (mh-goto-header-field "Mail-Followup-To: ")
-                    (insert entry ", ")
-                  (mh-goto-header-end 0)
-                  (insert "Mail-Followup-To: " entry "\n")))
-              (setq list (cdr list))))))))
-
 (defun mh-compose-and-send-mail (draft send-args
                                        sent-from-folder sent-from-msg
                                        to subject cc
@@ -1139,27 +878,29 @@ The versions of MH-E, Emacs, and MH are shown."
                                        config)
   "Edit and compose a draft message in buffer DRAFT and send or save it.
 SEND-ARGS is the argument passed to the send command.
-SENT-FROM-FOLDER is buffer containing scan listing of current folder, or
-nil if none exists.
+SENT-FROM-FOLDER is buffer containing scan listing of current folder,
+or nil if none exists.
 SENT-FROM-MSG is the message number or sequence name or nil.
 The TO, SUBJECT, and CC fields are passed to the
 `mh-compose-letter-function'.
-If ANNOTATE-CHAR is non-null, it is used to notate the scan listing of the
-message.  In that case, the ANNOTATE-FIELD is used to build a string
-for `mh-annotate-msg'.
-CONFIG is the window configuration to restore after sending the letter."
+If ANNOTATE-CHAR is non-null, it is used to notate the scan listing of
+the message. In that case, the ANNOTATE-FIELD is used to build a
+string for `mh-annotate-msg'.
+CONFIG is the window configuration to restore after sending the
+letter."
   (pop-to-buffer draft)
-  (if mh-insert-mail-followup-to-flag (mh-insert-mail-followup-to))
   (mh-letter-mode)
 
-  ;; mh-identity support
-  (if (and (boundp 'mh-identity-default)
-           mh-identity-default)
-      (mh-insert-identity mh-identity-default))
-  (when (and (boundp 'mh-identity-list)
-             mh-identity-list)
-    (mh-identity-make-menu)
-    (easy-menu-add mh-identity-menu))
+  ;; Insert identity.
+  (mh-insert-identity mh-identity-default t)
+  (mh-identity-make-menu)
+  (mh-identity-add-menu)
+
+  ;; Insert extra fields.
+  (mh-insert-x-mailer)
+  (mh-insert-x-face)
+
+  (mh-letter-hide-all-skipped-fields)
 
   (setq mh-sent-from-folder sent-from-folder)
   (setq mh-sent-from-msg sent-from-msg)
@@ -1169,374 +910,190 @@ CONFIG is the window configuration to restore after sending the letter."
   (setq mh-previous-window-config config)
   (setq mode-line-buffer-identification (list "    {%b}"))
   (mh-logo-display)
+  (mh-make-local-hook 'kill-buffer-hook)
   (add-hook 'kill-buffer-hook 'mh-tidy-draft-buffer nil t)
-  (if (and (boundp 'mh-compose-letter-function)
-           mh-compose-letter-function)
-      ;; run-hooks will not pass arguments.
-      (let ((value mh-compose-letter-function))
-        (if (and (listp value) (not (eq (car value) 'lambda)))
-            (while value
-              (funcall (car value) to subject cc)
-              (setq value (cdr value)))
-          (funcall mh-compose-letter-function to subject cc)))))
+  (run-hook-with-args 'mh-compose-letter-function to subject cc))
+
+(defun mh-insert-x-mailer ()
+  "Append an X-Mailer field to the header.
+The versions of MH-E, Emacs, and MH are shown."
+  ;; Lazily initialize mh-x-mailer-string.
+  (when (and mh-insert-x-mailer-flag (null mh-x-mailer-string))
+    (setq mh-x-mailer-string
+          (format "MH-E %s; %s; %sEmacs %s"
+                  mh-version mh-variant-in-use
+                  (if mh-xemacs-flag "X" "GNU ")
+                  (cond ((not mh-xemacs-flag)
+                         (string-match "[0-9]+\\.[0-9]+\\(\\.[0-9]+\\)?"
+                                       emacs-version)
+                         (match-string 0 emacs-version))
+                        ((string-match "[0-9.]*\\( +\([ a-z]+[0-9]+\)\\)?"
+                                       emacs-version)
+                         (match-string 0 emacs-version))
+                        (t (format "%s.%s" emacs-major-version
+                                   emacs-minor-version))))))
+  ;; Insert X-Mailer, but only if it doesn't already exist.
+  (save-excursion
+    (when (and mh-insert-x-mailer-flag
+               (null (mh-goto-header-field "X-Mailer")))
+      (mh-insert-fields "X-Mailer:" mh-x-mailer-string))))
+
+(defun mh-insert-x-face ()
+  "Append X-Face, Face or X-Image-URL field to header.
+If the field already exists, this function does nothing."
+  (when (and (file-exists-p mh-x-face-file)
+             (file-readable-p mh-x-face-file))
+    (save-excursion
+      (unless (or (mh-position-on-field "X-Face")
+                  (mh-position-on-field "Face")
+                  (mh-position-on-field "X-Image-URL"))
+        (save-excursion
+          (goto-char (+ (point) (cadr (insert-file-contents mh-x-face-file))))
+          (if (not (looking-at "^"))
+              (insert "\n")))
+        (unless (looking-at "\\(X-Face\\|Face\\|X-Image-URL\\): ")
+          (insert "X-Face: "))))))
+
+(defun mh-tidy-draft-buffer ()
+  "Run when a draft buffer is destroyed."
+  (let ((buffer (get-buffer mh-recipients-buffer)))
+    (if buffer
+        (kill-buffer buffer))))
 
 (defun mh-letter-mode-message ()
   "Display a help message for users of `mh-letter-mode'.
 This should be the last function called when composing the draft."
   (message "%s" (substitute-command-keys
                  (concat "Type \\[mh-send-letter] to send message, "
-                         "\\[mh-help] for help."))))
+                         "\\[mh-help] for help"))))
 
-;;;###mh-autoload
-(defun mh-send-letter (&optional arg)
-  "Send the draft letter in the current buffer.
-If optional prefix argument ARG is provided, monitor delivery.
-The value of `mh-before-send-letter-hook' is a list of functions to be called,
-with no arguments, before doing anything.
-Run `\\[mh-edit-mhn]' if variable `mh-mhn-compose-insert-flag' is set.
-Run `\\[mh-mml-to-mime]' if variable `mh-mml-compose-insert-flag' is set.
-Insert X-Mailer field if variable `mh-insert-x-mailer-flag' is set.
-Insert X-Face field if the file specified by `mh-x-face-file' exists."
-  (interactive "P")
-  (run-hooks 'mh-before-send-letter-hook)
-  (cond
-   ((and (boundp 'mh-mhn-compose-insert-flag)
-         mh-mhn-compose-insert-flag)
-    (mh-edit-mhn))
-   ((and (boundp 'mh-mml-compose-insert-flag)
-         mh-mml-compose-insert-flag)
-    (mh-mml-to-mime)))
-  (if mh-insert-x-mailer-flag (mh-insert-x-mailer))
-  (mh-insert-x-face)
-  (save-buffer)
-  (message "Sending...")
-  (let ((draft-buffer (current-buffer))
-        (file-name buffer-file-name)
-        (config mh-previous-window-config)
-        (coding-system-for-write
-         (if (and (local-variable-p 'buffer-file-coding-system
-                                    (current-buffer)) ;XEmacs needs two args
-                  ;; We're not sure why, but buffer-file-coding-system
-                  ;; tends to get set to undecided-unix.
-                  (not (memq buffer-file-coding-system
-                             '(undecided undecided-unix undecided-dos))))
-             buffer-file-coding-system
-           (or (and (boundp 'sendmail-coding-system) sendmail-coding-system)
-               (and (boundp 'default-buffer-file-coding-system )
-                    default-buffer-file-coding-system)
-               'iso-latin-1))))
-    ;; The default BCC encapsulation will make a MIME message unreadable.
-    ;; With nmh use the -mime arg to prevent this.
-    (if (and mh-nmh-flag
-             (mh-goto-header-field "Bcc:")
-             (mh-goto-header-field "Content-Type:"))
-        (setq mh-send-args (format "-mime %s" mh-send-args)))
-    (cond (arg
-           (pop-to-buffer "MH mail delivery")
-           (erase-buffer)
-           (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush"
-                               "-nodraftfolder" mh-send-args file-name)
-           (goto-char (point-max))      ; show the interesting part
-           (recenter -1)
-           (set-buffer draft-buffer))   ; for annotation below
-          (t
-           (mh-exec-cmd-daemon mh-send-prog nil "-nodraftfolder" "-noverbose"
-                               mh-send-args file-name)))
-    (if mh-annotate-char
-        (mh-annotate-msg mh-sent-from-msg
-                         mh-sent-from-folder
-                         mh-annotate-char
-                         "-component" mh-annotate-field
-                         "-text" (format "\"%s %s\""
-                                         (mh-get-header-field "To:")
-                                         (mh-get-header-field "Cc:"))))
+(defun mh-letter-adjust-point ()
+  "Move cursor to first header field if are using the no prompt mode."
+  (unless mh-compose-prompt-flag
+    (goto-char (point-max))
+    (mh-letter-next-header-field)))
 
-    (cond ((or (not arg)
-               (y-or-n-p "Kill draft buffer? "))
-           (kill-buffer draft-buffer)
-           (if config
-               (set-window-configuration config))))
-    (if arg
-        (message "Sending...done")
-      (message "Sending...backgrounded"))))
-
-;;;###mh-autoload
-(defun mh-insert-letter (folder message verbatim)
-  "Insert a message into the current letter.
-Removes the header fields according to the variable `mh-invisible-headers'.
-Prefixes each non-blank line with `mh-ins-buf-prefix', unless
-`mh-yank-from-start-of-msg' is set for supercite in which case supercite is
-used to format the message.
-Prompts for FOLDER and MESSAGE.  If prefix argument VERBATIM provided, do
-not indent and do not delete headers.  Leaves the mark before the letter
-and point after it."
-  (interactive
-   (list (mh-prompt-for-folder "Message from" mh-sent-from-folder nil)
-         (read-input (format "Message number%s: "
-                             (if (numberp mh-sent-from-msg)
-                                 (format " [%d]" mh-sent-from-msg)
-                               "")))
-         current-prefix-arg))
-  (save-restriction
-    (narrow-to-region (point) (point))
-    (let ((start (point-min)))
-      (if (equal message "") (setq message (int-to-string mh-sent-from-msg)))
-      (insert-file-contents
-       (expand-file-name message (mh-expand-file-name folder)))
-      (when (not verbatim)
-        (mh-clean-msg-header start mh-invisible-headers mh-visible-headers)
-        (goto-char (point-max))         ;Needed for sc-cite-original
-        (push-mark)                     ;Needed for sc-cite-original
-        (goto-char (point-min))         ;Needed for sc-cite-original
-        (mh-insert-prefix-string mh-ins-buf-prefix)))))
-
-(defun mh-extract-from-attribution ()
-  "Extract phrase or comment from From header field."
+(defun mh-annotate-msg (msg buffer note &rest args)
+  "Mark MSG in BUFFER with character NOTE and annotate message with ARGS.
+MSG can be a message number, a list of message numbers, or a
+sequence."
+  (apply 'mh-exec-cmd "anno" buffer
+         (if (listp msg) (append msg args) (cons msg args)))
   (save-excursion
-    (if (not (mh-goto-header-field "From: "))
-        nil
-      (skip-chars-forward " ")
-      (cond
-       ((looking-at "\"\\([^\"\n]+\\)\" \\(<.+>\\)")
-        (format "%s %s %s" (match-string 1)(match-string 2)
-                mh-extract-from-attribution-verb))
-       ((looking-at "\\([^<\n]+<.+>\\)$")
-        (format "%s %s" (match-string 1) mh-extract-from-attribution-verb))
-       ((looking-at "\\([^ ]+@[^ ]+\\) +(\\(.+\\))$")
-        (format "%s <%s> %s" (match-string 2)(match-string 1)
-                mh-extract-from-attribution-verb))
-       ((looking-at " *\\(.+\\)$")
-        (format "%s %s" (match-string 1) mh-extract-from-attribution-verb))))))
+    (cond ((get-buffer buffer)          ; Buffer may be deleted
+           (set-buffer buffer)
+           (mh-iterate-on-range nil msg
+             (mh-notate nil note
+                        (+ mh-cmd-note mh-scan-field-destination-offset)))))))
 
-;;;###mh-autoload
-(defun mh-yank-cur-msg ()
-  "Insert the current message into the draft buffer.
-Prefix each non-blank line in the message with the string in
-`mh-ins-buf-prefix'.  If a region is set in the message's buffer, then
-only the region will be inserted.  Otherwise, the entire message will
-be inserted if `mh-yank-from-start-of-msg' is non-nil.  If this variable
-is nil, the portion of the message following the point will be yanked.
-If `mh-delete-yanked-msg-window-flag' is non-nil, any window displaying the
-yanked message will be deleted."
-  (interactive)
-  (if (and mh-sent-from-folder
-           (save-excursion (set-buffer mh-sent-from-folder) mh-show-buffer)
-           (save-excursion (set-buffer mh-sent-from-folder)
-                           (get-buffer mh-show-buffer))
-           mh-sent-from-msg)
-      (let ((to-point (point))
-            (to-buffer (current-buffer)))
-        (set-buffer mh-sent-from-folder)
-        (if mh-delete-yanked-msg-window-flag
-            (delete-windows-on mh-show-buffer))
-        (set-buffer mh-show-buffer)     ; Find displayed message
-        (let* ((from-attr (mh-extract-from-attribution))
-               (yank-region (mh-mark-active-p nil))
-               (mh-ins-str
-                (cond ((and yank-region
-                            (or (eq 'supercite mh-yank-from-start-of-msg)
-                                (eq 'autosupercite mh-yank-from-start-of-msg)
-                                (eq t mh-yank-from-start-of-msg)))
-                       ;; supercite needs the full header
-                       (concat
-                        (buffer-substring (point-min) (mail-header-end))
-                        "\n"
-                        (buffer-substring (region-beginning) (region-end))))
-                      (yank-region
-                       (buffer-substring (region-beginning) (region-end)))
-                      ((or (eq 'body mh-yank-from-start-of-msg)
-                           (eq 'attribution
-                               mh-yank-from-start-of-msg)
-                           (eq 'autoattrib
-                               mh-yank-from-start-of-msg))
-                       (buffer-substring
-                        (save-excursion
-                          (goto-char (point-min))
-                          (mh-goto-header-end 1)
-                          (point))
-                        (point-max)))
-                      ((or (eq 'supercite mh-yank-from-start-of-msg)
-                           (eq 'autosupercite mh-yank-from-start-of-msg)
-                           (eq t mh-yank-from-start-of-msg))
-                       (buffer-substring (point-min) (point-max)))
-                      (t
-                       (buffer-substring (point) (point-max))))))
-          (set-buffer to-buffer)
-          (save-restriction
-            (narrow-to-region to-point to-point)
-            (insert (mh-filter-out-non-text mh-ins-str))
-            (goto-char (point-max))     ;Needed for sc-cite-original
-            (push-mark)                 ;Needed for sc-cite-original
-            (goto-char (point-min))     ;Needed for sc-cite-original
-            (mh-insert-prefix-string mh-ins-buf-prefix)
-            (if (or (eq 'attribution mh-yank-from-start-of-msg)
-                    (eq 'autoattrib mh-yank-from-start-of-msg))
-                (insert from-attr "\n\n"))
-            ;; If the user has selected a region, he has already "edited" the
-            ;; text, so leave the cursor at the end of the yanked text. In
-            ;; either case, leave a mark at the opposite end of the included
-            ;; text to make it easy to jump or delete to the other end of the
-            ;; text.
-            (push-mark)
-            (goto-char (point-max))
-            (if (null yank-region)
-                (mh-exchange-point-and-mark-preserving-active-mark)))))
-    (error "There is no current message")))
-
-(defun mh-filter-out-non-text (string)
-  "Return STRING but without adornments such as MIME buttons and smileys."
-  (with-temp-buffer
-    ;; Insert the string to filter
-    (insert string)
+(defun mh-insert-header-separator ()
+  "Insert `mh-mail-header-separator', if absent."
+  (save-excursion
     (goto-char (point-min))
-
-    ;; Remove the MIME buttons
-    (let ((can-move-forward t)
-          (in-button nil))
-      (while can-move-forward
-        (cond ((and (not (get-text-property (point) 'mh-data))
-                    in-button)
-               (delete-region (1- (point)) (point))
-               (setq in-button nil))
-              ((get-text-property (point) 'mh-data)
-               (delete-region (point)
-                              (save-excursion (forward-line) (point)))
-               (setq in-button t))
-              (t (setq can-move-forward (= (forward-line) 0))))))
-
-    ;; Return the contents without properties... This gets rid of emphasis
-    ;; and smileys
-    (buffer-substring-no-properties (point-min) (point-max))))
-
-(defun mh-insert-prefix-string (mh-ins-string)
-  "Insert prefix string before each line in buffer.
-The inserted letter is cited using `sc-cite-original' if
-`mh-yank-from-start-of-msg' is one of 'supercite or 'autosupercite. Otherwise,
-simply insert MH-INS-STRING before each line."
-  (goto-char (point-min))
-  (cond ((or (eq mh-yank-from-start-of-msg 'supercite)
-             (eq mh-yank-from-start-of-msg 'autosupercite))
-         (sc-cite-original))
-        (mail-citation-hook
-         (run-hooks 'mail-citation-hook))
-        (mh-yank-hooks                  ;old hook name
-         (run-hooks 'mh-yank-hooks))
-        (t
-         (or (bolp) (forward-line 1))
-         (while (< (point) (point-max))
-           (insert mh-ins-string)
-           (forward-line 1))
-         (goto-char (point-min)))))     ;leave point like sc-cite-original
+    (rfc822-goto-eoh)
+    (if (looking-at "$")
+        (insert mh-mail-header-separator))))
 
 ;;;###mh-autoload
-(defun mh-fully-kill-draft ()
-  "Kill the draft message file and the draft message buffer.
-Use \\[kill-buffer] if you don't want to delete the draft message file."
+(defun mh-insert-auto-fields (&optional non-interactive)
+  "Insert custom fields if recipient is found in `mh-auto-fields-list'.
+
+Once the header contains one or more recipients, you may run this
+command to insert these fields manually. However, if you use this
+command, the automatic insertion when the message is sent is
+disabled.
+
+In a program, set buffer-local `mh-insert-auto-fields-done-local'
+if header fields were added. If NON-INTERACTIVE is non-nil,
+perform actions quietly and only if
+`mh-insert-auto-fields-done-local' is nil. Return t if fields
+added; otherwise return nil."
   (interactive)
-  (if (y-or-n-p "Kill draft message? ")
-      (let ((config mh-previous-window-config))
-        (if (file-exists-p buffer-file-name)
-            (delete-file buffer-file-name))
-        (set-buffer-modified-p nil)
-        (kill-buffer (buffer-name))
-        (message "")
-        (if config
-            (set-window-configuration config)))
-    (error "Message not killed")))
+  (when (or (not non-interactive)
+            (not mh-insert-auto-fields-done-local))
+    (save-excursion
+      (when (and (or (mh-goto-header-field "To:")
+                     (mh-goto-header-field "cc:")))
+        (let ((list mh-auto-fields-list)
+              (fields-inserted nil))
+          (while list
+            (let ((regexp (nth 0 (car list)))
+                  (entries (nth 1 (car list))))
+              (when (mh-regexp-in-field-p regexp "To:" "cc:")
+                (setq mh-insert-auto-fields-done-local t)
+                (setq fields-inserted t)
+                (if (not non-interactive)
+                    (message "Fields for %s added" regexp))
+                (let ((entry-list entries))
+                  (while entry-list
+                    (let ((field (caar entry-list))
+                          (value (cdar entry-list)))
+                      (cond
+                       ((equal ":identity" field)
+                        (when
+                            ;;(and (not mh-identity-local)
+                            ;; Bug 1204506.  But do we need to be able
+                            ;; to set an identity manually that won't be
+                            ;; overridden by mh-insert-auto-fields?
+                            (assoc value mh-identity-list)
+                          ;;)
+                          (mh-insert-identity value)))
+                       (t
+                        (mh-modify-header-field field value
+                                                (equal field "From")))))
+                    (setq entry-list (cdr entry-list))))))
+            (setq list (cdr list)))
+          fields-inserted)))))
+
+(defun mh-modify-header-field (field value &optional overwrite-flag)
+  "To header FIELD add VALUE.
+If OVERWRITE-FLAG is non-nil then the old value, if present, is
+discarded."
+  (cond ((and overwrite-flag
+              (mh-goto-header-field (concat field ":")))
+         (insert " " value)
+         (delete-region (point) (mh-line-end-position)))
+        ((and (not overwrite-flag)
+              (mh-regexp-in-field-p (concat "\\b" value "\\b") field))
+         ;; Already there, do nothing.
+         )
+        ((and (not overwrite-flag)
+              (mh-goto-header-field (concat field ":")))
+         (insert " " value ","))
+        (t
+         (mh-goto-header-end 0)
+         (insert field ": " value "\n"))))
 
-(defun mh-current-fill-prefix ()
-  "Return the `fill-prefix' on the current line as a string."
+(defun mh-regexp-in-field-p (regexp &rest fields)
+  "Non-nil means REGEXP was found in FIELDS."
   (save-excursion
-    (beginning-of-line)
-    ;; This assumes that the major-mode sets up adaptive-fill-regexp
-    ;; correctly such as mh-letter-mode or sendmail.el's mail-mode.  But
-    ;; perhaps I should use the variable and simply inserts its value here,
-    ;; and set it locally in a let scope.  --psg
-    (if (re-search-forward adaptive-fill-regexp nil t)
-        (match-string 0)
-      "")))
-
-;;;###mh-autoload
-(defun mh-open-line ()
-  "Insert a newline and leave point after it.
-In addition, insert newline and quoting characters before text after point.
-This is useful in breaking up paragraphs in replies."
-  (interactive)
-  (let ((column (current-column))
-        (prefix (mh-current-fill-prefix)))
-    (if (> (length prefix) column)
-        (message "Sorry, point seems to be within the line prefix")
-      (newline 2)
-      (insert prefix)
-      (while (> column (current-column))
-        (insert " "))
-      (forward-line -1))))
+    (let ((search-result nil)
+          (field))
+      (while fields
+        (setq field (car fields))
+        (if (and (mh-goto-header-field field)
+                 (re-search-forward
+                  regexp (save-excursion (mh-header-field-end)(point)) t))
+            (setq fields nil
+                  search-result t)
+          (setq fields (cdr fields))))
+      search-result)))
 
-;;;###mh-autoload
-(defun mh-letter-complete (arg)
-  "Perform completion on header field or word preceding point.
-Alias completion is done within the mail header on selected fields and
-by the function designated by `mh-letter-complete-function' elsewhere,
-passing the prefix ARG if any."
-  (interactive "P")
-  (let ((case-fold-search t))
-    (if (and (mh-in-header-p)
-             (save-excursion
-               (mh-header-field-beginning)
-               (looking-at "^.*\\(to\\|cc\\|from\\):")))
-        (mh-alias-letter-expand-alias)
-      (funcall mh-letter-complete-function arg))))
-
-;;; Build the letter-mode keymap:
-;;; If this changes, modify mh-letter-mode-help-messages accordingly, above.
-(gnus-define-keys  mh-letter-mode-map
-  "\C-c?"               mh-help
-  "\C-c\C-c"            mh-send-letter
-  "\C-c\C-d"            mh-insert-identity
-  "\C-c\C-e"            mh-edit-mhn
-  "\C-c\C-f\C-b"        mh-to-field
-  "\C-c\C-f\C-c"        mh-to-field
-  "\C-c\C-f\C-d"        mh-to-field
-  "\C-c\C-f\C-f"        mh-to-fcc
-  "\C-c\C-f\C-r"        mh-to-field
-  "\C-c\C-f\C-s"        mh-to-field
-  "\C-c\C-f\C-t"        mh-to-field
-  "\C-c\C-fb"           mh-to-field
-  "\C-c\C-fc"           mh-to-field
-  "\C-c\C-fd"           mh-to-field
-  "\C-c\C-ff"           mh-to-fcc
-  "\C-c\C-fr"           mh-to-field
-  "\C-c\C-fs"           mh-to-field
-  "\C-c\C-ft"           mh-to-field
-  "\C-c\C-i"            mh-insert-letter
-  "\C-c\C-m\C-e"        mh-mml-secure-message-encrypt-pgpmime
-  "\C-c\C-m\C-f"        mh-compose-forward
-  "\C-c\C-m\C-i"        mh-compose-insertion
-  "\C-c\C-m\C-m"        mh-mml-to-mime
-  "\C-c\C-m\C-s"        mh-mml-secure-message-sign-pgpmime
-  "\C-c\C-m\C-u"        mh-revert-mhn-edit
-  "\C-c\C-me"           mh-mml-secure-message-encrypt-pgpmime
-  "\C-c\C-mf"           mh-compose-forward
-  "\C-c\C-mi"           mh-compose-insertion
-  "\C-c\C-mm"           mh-mml-to-mime
-  "\C-c\C-ms"           mh-mml-secure-message-sign-pgpmime
-  "\C-c\C-mu"           mh-revert-mhn-edit
-  "\C-c\C-o"            mh-open-line
-  "\C-c\C-q"            mh-fully-kill-draft
-  "\C-c\C-\\"           mh-fully-kill-draft ;if no C-q
-  "\C-c\C-s"            mh-insert-signature
-  "\C-c\C-^"            mh-insert-signature ;if no C-s
-  "\C-c\C-w"            mh-check-whom
-  "\C-c\C-y"            mh-yank-cur-msg
-  "\M-\t"               mh-letter-complete)
-
-;; "C-c /" prefix is used in mh-letter-mode by pgp.el and mailcrypt.el.
+(defun mh-ascii-buffer-p ()
+  "Check if current buffer is entirely composed of ASCII.
+The function doesn't work for XEmacs since `find-charset-region'
+doesn't exist there."
+  (loop for charset in (mh-funcall-if-exists
+                        find-charset-region (point-min) (point-max))
+        unless (eq charset 'ascii) return nil
+        finally return t))
 
 (provide 'mh-comp)
 
-;;; Local Variables:
-;;; indent-tabs-mode: nil
-;;; sentence-end-double-space: nil
-;;; End:
+;; Local Variables:
+;; indent-tabs-mode: nil
+;; sentence-end-double-space: nil
+;; End:
 
+;; arch-tag: 62865511-e610-4923-b0b5-f45a8ab70a34
 ;;; mh-comp.el ends here