summaryrefslogtreecommitdiff
path: root/lisp/mail/mh-comp.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/mail/mh-comp.el')
-rw-r--r--lisp/mail/mh-comp.el607
1 files changed, 417 insertions, 190 deletions
diff --git a/lisp/mail/mh-comp.el b/lisp/mail/mh-comp.el
index bc6556cc31b..9ad5a49cc0d 100644
--- a/lisp/mail/mh-comp.el
+++ b/lisp/mail/mh-comp.el
@@ -1,11 +1,11 @@
;;; mh-comp.el --- mh-e functions for composing messages
-;; Time-stamp: <2001-12-20 18:55:07 pavel>
-;; Copyright (C) 1993,1995,1997,2000 Free Software Foundation, Inc.
+;; Copyright (C) 1993,1995,1997,2000,2001,2002 Free Software Foundation, Inc.
+;; Author: Bill Wohler <wohler@newt.com>
;; Maintainer: Bill Wohler <wohler@newt.com>
;; Keywords: mail
-;; Bug-reports: include `M-x mh-version' output in any correspondence
+;; See: mh-e.el
;; This file is part of GNU Emacs.
@@ -30,17 +30,69 @@
;;; Change Log:
-;; $Id: mh-comp.el,v 1.22 2001/07/15 19:53:53 pj Exp $
+;; $Id: mh-comp.el,v 1.56 2002/04/07 19:20:56 wohler Exp $
;;; Code:
(provide 'mh-comp)
+(require 'mh-e)
(require 'mh-utils)
+(require 'gnus-util)
+(require 'easymenu)
+
+;;; autoloads from mh-mime
+
+(autoload 'mh-mhn-compose-insertion "mh-mime"
+ "Add a directive to insert a MIME message part from a file.
+This is the typical way to insert non-text parts in a message.
+See also \\[mh-edit-mhn]." t)
+
+(autoload 'mh-mhn-compose-anon-ftp "mh-mime"
+ "Add a directive for a MIME anonymous ftp external body part.
+This directive tells MH to include a reference to a
+message/external-body part retrievable by anonymous FTP.
+See also \\[mh-edit-mhn]." t)
+
+(autoload 'mh-mhn-compose-external-compressed-tar "mh-mime"
+ "Add a directive to include a MIME reference to a compressed tar file.
+The file should be available via anonymous ftp. This directive
+tells MH to include a reference to a message/external-body part.
+See also \\[mh-edit-mhn]." t)
+
+(autoload 'mh-mhn-compose-forw "mh-mime"
+ "Add a forw directive to this message, to forward a message with MIME.
+This directive tells MH to include another message in this one.
+See also \\[mh-edit-mhn]." t)
+
+(autoload 'mh-edit-mhn "mh-mime"
+ "Format the current draft for MIME, expanding any mhn directives.
+Process the current draft with the mhn program, which,
+using directives already inserted in the draft, fills in
+all the MIME components and header fields.
+This step should be done last just before sending the message.
+The mhn program is part of MH version 6.8 or later.
+The \\[mh-revert-mhn-edit] command undoes this command.
+For assistance with creating mhn directives to insert
+various types of components in a message, see
+\\[mh-mhn-compose-insertion] (generic insertion from a file),
+\\[mh-mhn-compose-anon-ftp] (external reference to file via anonymous ftp),
+\\[mh-mhn-compose-external-compressed-tar] \
+\(reference to compressed tar file via anonymous ftp), and
+\\[mh-mhn-compose-forw] (forward message)." t)
+
+(autoload 'mh-revert-mhn-edit "mh-mime"
+ "Undoes the effect of \\[mh-edit-mhn] by reverting to the backup file.
+Optional non-nil argument means don't ask for confirmation." t)
+
+;;; Other Autoloads.
+
+(autoload 'Info-goto-node "info")
+(autoload 'mail-mode-fill-paragraph "sendmail")
;;; Site customization (see also mh-utils.el):
(defgroup mh-compose nil
- "Mh-e functions for composing messages"
+ "Mh-e functions for composing messages."
:prefix "mh-"
:group 'mh)
@@ -54,6 +106,9 @@ Some sites need to change this because of a name conflict.")
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-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.")
@@ -85,12 +140,18 @@ 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.")
-;;; Copied from sendmail.el for Hyperbole
-(defvar mail-header-separator "--------"
- "*Line used by MH to separate headers from text in messages being composed.")
-
;;; Personal preferences:
+(defcustom mh-insert-x-mailer-p t
+ "*If t, append an X-Mailer field to the header."
+ :type 'boolean
+ :group 'mh-compose)
+
+(defvar mh-x-mailer-string nil
+ "*String containing the contents of the X-Mailer header field.
+If nil, this variable is initialized to show the version of mh-e, Emacs, and
+MH the first time a message is composed.")
+
(defcustom mh-delete-yanked-msg-window nil
"*Controls window display when a message is yanked by \\<mh-letter-mode-map>\\[mh-yank-cur-msg].
If non-nil, yanking the current message into a draft letter deletes any
@@ -152,11 +213,30 @@ 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 the sender
-and all recipients of a messages. Only used if mh-nmh-p 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.")
+ "Name of file to be used as a skeleton for replying to the sender and all recipients of a message.
+Only used if `mh-nmh-p' 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.")
+
+(defcustom mh-reply-show-message-p t
+ "*Whether the show buffer is displayed using \\<mh-letter-mode-map>\\[mh-reply].
+
+The setting of this variable determines whether the MH `show-buffer' is
+displayed with the current message when using `mh-reply' without a prefix
+argument. Set it to nil if you already include the message automatically
+in your draft using
+ repl: -filter repl.filter
+in your ~/.mh_profile file."
+ :type 'boolean
+ :group 'mh-compose)
+
+(defcustom mh-letter-fill-column 72
+ "*Fill column to use in `mh-letter-mode'.
+This is usually less than in other text modes because email messages get
+quoted by some prefix (sometimes many times) when they are replied-to,
+and it's best to avoid quoted lines that span more than 80 columns."
+ :type 'integer
+ :group 'mh-compose)
;;; Hooks:
@@ -176,18 +256,17 @@ It is passed three arguments: TO recipients, SUBJECT, and CC recipients."
:type 'hook
:group 'mh-compose)
-
(defvar mh-rejected-letter-start
- (concat "^ ----- Unsent message follows -----$" ;from sendmail V5
- "\\|^ ----- Original message follows -----$" ;from sendmail V8
- "\\|^------- Unsent Draft$" ;from MH itself
- "\\|^---------- Original Message ----------$" ;from zmailer
- "\\|^ --- The unsent message follows ---$" ;from AIX mail system
- "\\|^ Your message follows:$" ;from MMDF-II
- "\\|^Content-Description: Returned Content$" ;1993 KJ sendmail
- )
- "Regexp specifying the beginning of the wrapper around a returned letter.
-This wrapper is generated by the mail system when rejecting a letter.")
+ (regexp-opt
+ '("^Content-Type: message/rfc822$" ;MIME MDN
+ "^ ----- Unsent message follows -----$" ;from sendmail V5
+ "^ ----- Original message follows -----$" ;from sendmail V8
+ "^------- Unsent Draft$" ;from MH itself
+ "^---------- Original Message ----------$" ;from zmailer
+ "^ --- The unsent message follows ---$" ;from AIX mail system
+ "^ Your message follows:$" ;from MMDF-II
+ "^Content-Description: Returned Content$" ;1993 KJ sendmail
+ )))
(defvar mh-new-draft-cleaned-headers
"^Date:\\|^Received:\\|^Message-Id:\\|^From:\\|^Sender:\\|^Errors-To:\\|^Delivery-Date:\\|^Return-Path:"
@@ -197,7 +276,7 @@ Used by the \\<mh-folder-mode-map>`\\[mh-edit-again]' and `\\[mh-extract-rejecte
(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.")
+ "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.")
@@ -234,16 +313,41 @@ 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."
+Users should use `\\[mh-smail]' to compose mail.
+Optional arguments for setting certain fields include TO, SUBJECT, and
+OTHER-HEADERS."
(mh-find-path)
(let ((mh-error-if-no-draft t))
(mh-send (or to "") "" (or subject ""))))
+;; XEmacs needs this:
+;;;###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.
+
+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.
+
+CONTINUE, SWITCH-FUNCTION, YANK-ACTION and SEND-ACTIONS are ignored."
+ (mh-find-path)
+ (let ((mh-error-if-no-draft t))
+ (mh-send to "" subject)
+ (while other-headers
+ (mh-insert-fields (concat (car (car other-headers)) ":")
+ (cdr (car other-headers)))
+ (setq other-headers (cdr other-headers)))))
(defun mh-edit-again (msg)
- "Clean-up a draft or a message previously sent and make it resendable.
+ "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.
+The variable `mh-new-draft-cleaned-headers' specifies the headers to remove.
See also documentation for `\\[mh-send]' function."
(interactive (list (mh-get-msg-num t)))
(let* ((from-folder mh-current-folder)
@@ -256,6 +360,7 @@ See also documentation for `\\[mh-send]' function."
(t
(mh-read-draft "clean-up" (mh-msg-filename msg) 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
@@ -263,7 +368,7 @@ See also documentation for `\\[mh-send]' function."
(defun mh-extract-rejected-mail (msg)
- "Extract a letter returned by the mail system and make it resendable.
+ "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."
@@ -278,6 +383,7 @@ See also documentation for `\\[mh-send]' function."
(mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil))
(t
(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
@@ -288,9 +394,9 @@ See also documentation for `\\[mh-send]' function."
(defun mh-forward (to cc &optional msg-or-seq)
- "Forward a message or message sequence. Defaults to displayed message.
-If optional prefix argument provided, then prompt for the message sequence.
-See also documentation for `\\[mh-send]' function."
+ "Forward displayed message to recipients TO and CC.
+If optional prefix argument MSG-OR-SEQ provided, then prompt for the message
+sequence. See also documentation for `\\[mh-send]' function."
(interactive (list (mh-read-address "To: ")
(mh-read-address "Cc: ")
(if current-prefix-arg
@@ -300,6 +406,10 @@ See also documentation for `\\[mh-send]' function."
(setq msg-or-seq (mh-get-msg-num t)))
(let* ((folder mh-current-folder)
(config (current-window-configuration))
+ (fwd-msg-file (mh-msg-filename (if (numberp msg-or-seq)
+ msg-or-seq
+ (car (mh-seq-to-msgs msg-or-seq)))
+ 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))
@@ -311,11 +421,7 @@ See also documentation for `\\[mh-send]' function."
(mh-insert-fields "To:" to "Cc:" cc)
(save-buffer)))
(t
- (mh-read-draft "" draft-name nil))))
- (fwd-msg-file (mh-msg-filename (if (numberp msg-or-seq)
- msg-or-seq
- (car (mh-seq-to-msgs msg-or-seq)))
- folder)))
+ (mh-read-draft "" draft-name nil)))))
(let (orig-from
orig-subject)
(save-excursion
@@ -325,12 +431,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)))
+ (mh-forwarded-letter-subject orig-from orig-subject))
+ (mail-header-separator mh-mail-header-separator))
(mh-insert-fields "Subject:" forw-subject)
(goto-char (point-min))
(if (re-search-forward "^------- Forwarded Message" nil t)
(forward-line -1)
- (re-search-forward "^--------")
+ (re-search-forward mail-header-separator)
(forward-line 1))
(delete-other-windows)
(if (numberp msg-or-seq)
@@ -368,7 +475,8 @@ See documentation of `\\[mh-send]' for more details on composing mail."
(defun mh-redistribute (to cc &optional msg)
- "Redistribute a letter.
+ "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."
(interactive (list (mh-read-address "Redist-To: ")
@@ -391,20 +499,32 @@ setting of the variable `mh-redist-full-contents'. See its documentation."
nil)
(save-buffer)
(message "Redistributing...")
- (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)))
+ (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" "-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)))
(kill-buffer draft)
(message "Redistributing...done"))))
@@ -462,6 +582,7 @@ for the reply. See also documentation for `\\[mh-send]' function."
(goto-char (point-min))
(mh-goto-header-end 1)
(or includep
+ (not mh-reply-show-message-p)
(mh-in-show-buffer (show-buffer)
(mh-display-msg message folder)))
(mh-add-msgs-to-seq message 'answered t)
@@ -472,12 +593,14 @@ for the reply. See also documentation for `\\[mh-send]' function."
(defun mh-send (to cc subject)
"Compose and send a letter.
-The file named by `mh-comp-formfile' will be used as the form.
+
Do not call this function from outside mh-e; use \\[mh-smail] instead.
-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, SUBJECT, and CC."
+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: ")
@@ -489,9 +612,15 @@ draft and passed three arguments: TO, SUBJECT, and CC."
(defun mh-send-other-window (to cc subject)
"Compose and send a letter in another window.
-Do not call this function from outside mh-e;
-use \\[mh-smail-other-window] instead.
-See also documentation for `\\[mh-send]' function."
+
+Do not call this function from outside mh-e; use \\[mh-smail-other-window]
+instead.
+
+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: ")
@@ -540,7 +669,7 @@ See also documentation for `\\[mh-send]' function."
(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.
- ;; INITIAL-CONTENTS is filename that is read into an empty buffer, or nil
+ ;; 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
;; DELETE-CONTENTS-FILE flag is set.
;; Returns the draft folder's name.
@@ -617,7 +746,7 @@ See also documentation for `\\[mh-send]' function."
(cond ((equal value "")
nil)
((mh-position-on-field field-name)
- (insert " " value))
+ (insert " " (or value "")))
(t
(insert field-name " " value "\n")))
(setq name-values (cdr (cdr name-values)))))))
@@ -628,10 +757,11 @@ See also documentation for `\\[mh-send]' function."
;; 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.
- (if (mh-goto-header-field field)
- (progn
- (mh-header-field-end)
- t)))
+ (cond ((mh-goto-header-field field)
+ (mh-header-field-end)
+ t)
+ ((mh-goto-header-end 0)
+ nil)))
(defun mh-get-header-field (field)
@@ -651,7 +781,7 @@ See also documentation for `\\[mh-send]' function."
(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.
+ ;; Returns T if found, NIL if not.
(goto-char (point-min))
(let ((case-fold-search t)
(headers-end (save-excursion
@@ -659,15 +789,6 @@ See also documentation for `\\[mh-send]' function."
(point))))
(re-search-forward (format "^%s" field) headers-end t)))
-(defun mh-header-field-end ()
- ;; Move to the end of the current header field.
- ;; Handles RFC 822 continuation lines.
- (forward-line 1)
- (while (looking-at "^[ \t]")
- (forward-line 1))
- (backward-char 1)) ;to end of previous line
-
-
(defun mh-goto-header-end (arg)
;; Find the end of the message header in the current buffer and position
;; the cursor at the ARG'th newline after the header.
@@ -699,39 +820,24 @@ See also documentation for `\\[mh-send]' function."
;;;###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.
-See the documentation for \\[mh-edit-mhn] for information on composing MIME
-messages.
-\\{mh-letter-mode-map}
+If MH MIME directives are added manually, you must first run \\[mh-edit-mhn]
+before sending the message. MIME directives that are added by mh-e commands
+such as \\[mh-mhn-compose-insertion] are processed automatically when the
+message is sent.
-Variables controlling this mode (defaults in parentheses):
+Options that control this mode can be changed with
+\\[customize-group]; specify the \"mh-compose\" group.
- mh-delete-yanked-msg-window (nil)
- If non-nil, \\[mh-yank-cur-msg] will delete any windows displaying
- the yanked message.
+When a message is composed, the hooks `text-mode-hook' and
+`mh-letter-mode-hook' are run.
- mh-yank-from-start-of-msg (t)
- If non-nil, \\[mh-yank-cur-msg] will include the entire message.
- If `body', just yank the body (no header).
- If nil, only the portion of the message following the point will be yanked.
- If there is a region, this variable is ignored.
+\\{mh-letter-mode-map}"
- mh-ins-buf-prefix (\"> \")
- String to insert before each non-blank line of a message as it is
- inserted in a draft letter.
-
- mh-signature-file-name (\"~/.signature\")
- File to be inserted into message by \\[mh-insert-signature].
-
-This command runs the normal hooks `text-mode-hook' and `mh-letter-mode-hook'."
(or mh-user-path (mh-find-path))
- (make-local-variable 'paragraph-start)
- (setq paragraph-start (concat "^[ \t]*[-_][-_][-_]+$\\|" paragraph-start))
- (make-local-variable 'paragraph-separate)
- (setq paragraph-separate
- (concat "^[ \t]*[-_][-_][-_]+$\\|" paragraph-separate))
(make-local-variable 'mh-send-args)
(make-local-variable 'mh-annotate-char)
(make-local-variable 'mh-annotate-field)
@@ -739,7 +845,56 @@ This command runs the normal hooks `text-mode-hook' and `mh-letter-mode-hook'."
(make-local-variable 'mh-sent-from-folder)
(make-local-variable 'mh-sent-from-msg)
(make-local-variable 'mail-header-separator)
- (setq mail-header-separator "--------") ;for Hyperbole
+ (setq mail-header-separator mh-mail-header-separator) ;override sendmail.el
+
+ ;; 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 'mail-mode-fill-paragraph)
+ (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
+ ((equal mh-highlight-citation-p 'font-lock)
+ (setq font-lock-defaults '(mh-show-font-lock-keywords-with-cite t)))
+ ((equal mh-highlight-citation-p 'gnus)
+ (setq font-lock-defaults '(mh-show-font-lock-keywords t))
+ (mh-gnus-article-highlight-citation))
+ (t
+ (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 mail-header-separator nil t)
+ (= 0 (forward-line 1))
+ (looking-at "^#forw"))
+ (require 'mh-mime) ;Need mh-mhn-compose-insert-p local var
+ (setq mh-mhn-compose-insert-p 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)
@@ -755,14 +910,13 @@ This command runs the normal hooks `text-mode-hook' and `mh-letter-mode-hook'."
(do-auto-fill)))
-(defun mh-in-header-p ()
- ;; Return non-nil if the point is in the header of a draft message.
+(defun mh-insert-header-separator ()
+ ;; Inserts `mh-mail-header-separator', if absent.
(save-excursion
- (let ((cur-point (point)))
- (goto-char (point-min))
- (re-search-forward "^-*$" nil t)
- (< cur-point (point)))))
-
+ (goto-char (point-min))
+ (rfc822-goto-eoh)
+ (if (looking-at "$")
+ (insert mh-mail-header-separator))))
(defun mh-to-field ()
"Move point to the end of a specified header field.
@@ -839,6 +993,30 @@ Prompt for the field name with a completion list of the current folders."
;;; Routines to compose and send a letter.
+(defun mh-insert-x-mailer ()
+ ;; Appends 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
+ (mh-version)
+ (set-buffer mh-temp-buffer)
+ (if mh-nmh-p
+ (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; Emacs %d.%d"
+ mh-version (if mh-nmh-p "nmh" "MH") x-mailer-mh
+ emacs-major-version emacs-minor-version)))
+ (kill-buffer mh-temp-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-compose-and-send-mail (draft send-args
sent-from-folder sent-from-msg
to subject cc
@@ -877,24 +1055,31 @@ Prompt for the field name with a completion list of the current folders."
(defun mh-send-letter (&optional arg)
"Send the draft letter in the current buffer.
-If optional prefix argument is provided, monitor delivery.
-Run `mh-before-send-letter-hook' before actually doing anything."
+If optional prefix argument ARG is provided, monitor delivery.
+Run `mh-before-send-letter-hook' before actually doing anything.
+Run `\\[mh-edit-mhn]' if variable `mh-mhn-compose-insert-p' is set."
(interactive "P")
(run-hooks 'mh-before-send-letter-hook)
+ (if (and (boundp 'mh-mhn-compose-insert-p)
+ mh-mhn-compose-insert-p)
+ (mh-edit-mhn))
+ (if mh-insert-x-mailer-p (mh-insert-x-mailer))
(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)
+ (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 sendmail-coding-system
- default-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))))
(cond (arg
(pop-to-buffer "MH mail delivery")
@@ -1006,9 +1191,10 @@ yanked message will be deleted."
(run-hooks 'mh-yank-hooks))
(t
(or (bolp) (forward-line 1))
- (while (< (point) (mark))
- (insert mh-ins-string)
- (forward-line 1)))))
+ (let ((zmacs-regions nil)) ;so "(mark)" works in XEmacs
+ (while (< (point) (mark))
+ (insert mh-ins-string)
+ (forward-line 1))))))
(defun mh-fully-kill-draft ()
@@ -1027,81 +1213,122 @@ Use \\[kill-buffer] if you don't want to delete the draft message file."
(error "Message not killed")))
-;;; Build the letter-mode keymap:
-
-(define-key mh-letter-mode-map "\C-c\C-f\C-b" 'mh-to-field)
-(define-key mh-letter-mode-map "\C-c\C-f\C-c" 'mh-to-field)
-(define-key mh-letter-mode-map "\C-c\C-f\C-d" 'mh-to-field)
-(define-key mh-letter-mode-map "\C-c\C-f\C-f" 'mh-to-fcc)
-(define-key mh-letter-mode-map "\C-c\C-f\C-r" 'mh-to-field)
-(define-key mh-letter-mode-map "\C-c\C-f\C-s" 'mh-to-field)
-(define-key mh-letter-mode-map "\C-c\C-f\C-t" 'mh-to-field)
-(define-key mh-letter-mode-map "\C-c\C-fb" 'mh-to-field)
-(define-key mh-letter-mode-map "\C-c\C-fc" 'mh-to-field)
-(define-key mh-letter-mode-map "\C-c\C-fd" 'mh-to-field)
-(define-key mh-letter-mode-map "\C-c\C-ff" 'mh-to-fcc)
-(define-key mh-letter-mode-map "\C-c\C-fr" 'mh-to-field)
-(define-key mh-letter-mode-map "\C-c\C-fs" 'mh-to-field)
-(define-key mh-letter-mode-map "\C-c\C-ft" 'mh-to-field)
-(define-key mh-letter-mode-map "\C-c\C-i" 'mh-insert-letter)
-(define-key mh-letter-mode-map "\C-c\C-q" 'mh-fully-kill-draft)
-(define-key mh-letter-mode-map "\C-c\C-\\" 'mh-fully-kill-draft) ;if no C-q
-(define-key mh-letter-mode-map "\C-c\C-s" 'mh-insert-signature)
-(define-key mh-letter-mode-map "\C-c\C-^" 'mh-insert-signature) ;if no C-s
-(define-key mh-letter-mode-map "\C-c\C-w" 'mh-check-whom)
-(define-key mh-letter-mode-map "\C-c\C-y" 'mh-yank-cur-msg)
-(define-key mh-letter-mode-map "\C-c\C-c" 'mh-send-letter)
-(define-key mh-letter-mode-map "\C-c\C-m\C-f" 'mh-mhn-compose-forw)
-(define-key mh-letter-mode-map "\C-c\C-m\C-e" 'mh-mhn-compose-anon-ftp)
-(define-key mh-letter-mode-map "\C-c\C-m\C-t" 'mh-mhn-compose-external-compressed-tar)
-(define-key mh-letter-mode-map "\C-c\C-m\C-i" 'mh-mhn-compose-insertion)
-(define-key mh-letter-mode-map "\C-c\C-e" 'mh-edit-mhn)
-(define-key mh-letter-mode-map "\C-c\C-m\C-u" 'mh-revert-mhn-edit)
-
-;; "C-c /" prefix is used in mh-letter-mode by pgp.el
-
-;;; autoloads from mh-mime
-
-(autoload 'mh-mhn-compose-insertion "mh-mime"
- "Add a directive to insert a MIME message part from a file.
-This is the typical way to insert non-text parts in a message.
-See also \\[mh-edit-mhn]." t)
-
-(autoload 'mh-mhn-compose-anon-ftp "mh-mime"
- "Add a directive for a MIME anonymous ftp external body part.
-This directive tells MH to include a reference to a
-message/external-body part retrievable by anonymous FTP.
-See also \\[mh-edit-mhn]." t)
-
-(autoload 'mh-mhn-compose-external-compressed-tar "mh-mime"
- "Add a directive to include a MIME reference to a compressed tar file.
-The file should be available via anonymous ftp. This directive
-tells MH to include a reference to a message/external-body part.
-See also \\[mh-edit-mhn]." t)
+(defun mh-current-fill-prefix ()
+ ;; Return the fill-prefix on the current line as a string.
+ (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)
+ "")))
+
+
+(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))
+ (point (point))
+ (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))))
-(autoload 'mh-mhn-compose-forw "mh-mime"
- "Add a forw directive to this message, to forward a message with MIME.
-This directive tells MH to include another message in this one.
-See also \\[mh-edit-mhn]." t)
-(autoload 'mh-edit-mhn "mh-mime"
- "Format the current draft for MIME, expanding any mhn directives.
-Process the current draft with the mhn program, which,
-using directives already inserted in the draft, fills in
-all the MIME components and header fields.
-This step should be done last just before sending the message.
-The mhn program is part of MH version 6.8 or later.
-The \\[mh-revert-mhn-edit] command undoes this command.
-For assistance with creating mhn directives to insert
-various types of components in a message, see
-\\[mh-mhn-compose-insertion] (generic insertion from a file),
-\\[mh-mhn-compose-anon-ftp] (external reference to file via anonymous ftp),
-\\[mh-mhn-compose-external-compressed-tar] \
-\(reference to compressed tar file via anonymous ftp), and
-\\[mh-mhn-compose-forw] (forward message)." t)
-
-(autoload 'mh-revert-mhn-edit "mh-mime"
- "Undoes the effect of \\[mh-edit-mhn] by reverting to the backup file.
-Optional non-nil argument means don't ask for confirmation." t)
+;;; Build the letter-mode keymap:
+(gnus-define-keys mh-letter-mode-map
+ "\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-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
+ "\C-c\C-c" mh-send-letter
+ "\C-c\C-m\C-f" mh-mhn-compose-forw
+ "\C-c\C-m\C-e" mh-mhn-compose-anon-ftp
+ "\C-c\C-m\C-t" mh-mhn-compose-external-compressed-tar
+ "\C-c\C-m\C-i" mh-mhn-compose-insertion
+ "\C-c\C-e" mh-edit-mhn
+ "\C-c\C-m\C-u" mh-revert-mhn-edit)
+
+;; "C-c /" prefix is used in mh-letter-mode by pgp.el and mailcrypt.el.
+
+;;; Menu extracted from mh-menubar.el V1.1 (31 July 2001)
+(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]
+ ["Compose Insertion (MIME)..." mh-mhn-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-mhn-compose-forw t]
+ ["Pull in All Compositions (MIME)" mh-edit-mhn t]
+ ["Revert to Non-MIME Edit" mh-revert-mhn-edit t]
+ ["Kill This Draft" mh-fully-kill-draft t]))))
+
+(defun mh-customize ()
+ "Customize mh-e variables."
+ (interactive)
+ (customize-group 'mh))
+
+;;; Support for emacs21 toolbar using gnus/message.el icons (and code).
+(eval-when-compile (defvar tool-bar-map))
+(when (and (fboundp 'tool-bar-add-item)
+ tool-bar-mode)
+ (defvar mh-letter-tool-bar-map
+ (let ((tool-bar-map (make-sparse-keymap)))
+ (tool-bar-add-item "mail_send" 'mh-send-letter 'mh-letter-send
+ :help "Send this letter")
+ (tool-bar-add-item "attach" 'mh-mhn-compose-insertion 'mh-letter-compose
+ :help "Insert attachment")
+ (tool-bar-add-item "spell" 'ispell-message 'mh-letter-ispell
+ :help "Check spelling")
+ (tool-bar-add-item-from-menu 'save-buffer "save")
+ (tool-bar-add-item-from-menu 'undo "undo")
+ (tool-bar-add-item-from-menu 'kill-region "cut")
+ (tool-bar-add-item-from-menu 'menu-bar-kill-ring-save "copy")
+ (tool-bar-add-item "close" 'mh-fully-kill-draft 'mh-letter-kill
+ :help "Kill this draft")
+ (tool-bar-add-item "preferences" (lambda ()
+ (interactive)
+ (customize-group "mh-compose"))
+ 'mh-letter-customize
+ :help "mh-e composition preferences")
+ (tool-bar-add-item "help" (lambda ()
+ (interactive)
+ (Info-goto-node "(mh-e)Draft Editing"))
+ 'mh-letter-help :help "Help")
+ tool-bar-map)))
;;; mh-comp.el ends here