-;;; mh-comp --- mh-e functions for composing messages
-;; Time-stamp: <94/12/31 14:07:28 gildea>
+;;; mh-comp.el --- mh-e functions for composing messages
+;; Time-stamp: <2001-12-20 18:55:07 pavel>
-;; Copyright (C) 1993, 1995 Free Software Foundation, Inc.
+;; Copyright (C) 1993,1995,1997,2000 Free Software Foundation, Inc.
-;; This file is part of mh-e.
+;; Maintainer: Bill Wohler <wohler@newt.com>
+;; Keywords: mail
+;; Bug-reports: include `M-x mh-version' output in any correspondence
-;; mh-e is free software; you can redistribute it and/or modify
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
-;; mh-e is distributed in the hope that it will be useful,
+;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with mh-e; see the file COPYING. If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; 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.
;;; Commentary:
;;; Change Log:
-;; $Id: mh-comp.el,v 1.8 94/12/31 19:11:42 gildea Exp $
+;; $Id: mh-comp.el,v 1.22 2001/07/15 19:53:53 pj Exp $
;;; Code:
;;; Site customization (see also mh-utils.el):
+(defgroup mh-compose nil
+ "Mh-e functions for composing messages"
+ :prefix "mh-"
+ :group 'mh)
+
+
(defvar mh-send-prog "send"
"Name of the MH send program.
Some sites need to change this because of a name conflict.")
text as modified.
This is a normal hook, misnamed for historical reasons.
-It is semi-obsolete and is only used if mail-citation-hook is nil.")
+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.
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.
+with `mh-ins-buf-prefix' prefixed to each line.
-See also the variable mh-yank-from-start-of-msg, which controls how
+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
;;; Personal preferences:
-(defvar mh-delete-yanked-msg-window nil
+(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
-windows displaying the message.")
+windows displaying the message."
+ :type 'boolean
+ :group 'mh-compose)
-(defvar mh-yank-from-start-of-msg t
+(defcustom mh-yank-from-start-of-msg t
"*Controls which part of a message is yanked by \\<mh-letter-mode-map>\\[mh-yank-cur-msg].
If non-nil, include the entire message. If the symbol `body', then yank the
message minus the header. If nil, yank only the portion of the message
following the point. If the show buffer has a region, this variable is
-ignored.")
+ignored."
+ :type '(choice (const :tag "Below point" nil)
+ (const :tag "Without header" body)
+ (other :tag "Entire message" t))
+ :group 'mh-compose)
-(defvar mh-ins-buf-prefix "> "
+(defcustom mh-ins-buf-prefix "> "
"*String to put before each non-blank line of a yanked or inserted message.
\\<mh-letter-mode-map>Used when the message is inserted into an outgoing letter
-by \\[mh-insert-letter] or \\[mh-yank-cur-msg].")
+by \\[mh-insert-letter] or \\[mh-yank-cur-msg]."
+ :type 'string
+ :group 'mh-compose)
-(defvar mh-reply-default-reply-to nil
+(defcustom mh-reply-default-reply-to nil
"*Sets the person or persons to whom a reply will be sent.
If nil, prompt for recipient. If non-nil, then \\<mh-folder-mode-map>`\\[mh-reply]' will use this
value and it should be one of \"from\", \"to\", \"cc\", or \"all\".
-The values \"cc\" and \"all\" do the same thing.")
+The values \"cc\" and \"all\" do the same thing."
+ :type '(choice (const :tag "Prompt" nil)
+ (const "from") (const "to")
+ (const "cc") (const "all"))
+ :group 'mh-compose)
-(defvar mh-signature-file-name "~/.signature"
+(defcustom mh-signature-file-name "~/.signature"
"*Name of file containing the user's signature.
-Inserted into message by \\<mh-letter-mode-map>\\[mh-insert-signature].")
+Inserted into message by \\<mh-letter-mode-map>\\[mh-insert-signature]."
+ :type 'file
+ :group 'mh-compose)
-(defvar mh-forward-subject-format "%s: %s"
+(defcustom mh-forward-subject-format "%s: %s"
"*Format to generate the Subject: line contents for a forwarded message.
The two string arguments to the format are the sender of the original
-message and the original subject line.")
+message and the original subject line."
+ :type 'string
+ :group 'mh-compose)
(defvar mh-comp-formfile "components"
"Name of file to be used as a skeleton for composing messages.
-Default is \"components\". If not a complete path name, the file
+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 a complete path name, the file
+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 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.")
+
;;; Hooks:
-(defvar mh-letter-mode-hook nil
- "Invoked in `mh-letter-mode' on a new letter.")
+(defcustom mh-letter-mode-hook nil
+ "Invoked in `mh-letter-mode' on a new letter."
+ :type 'hook
+ :group 'mh-compose)
-(defvar mh-compose-letter-function nil
+(defcustom mh-compose-letter-function nil
"Invoked when setting up a letter draft.
-It is passed three arguments: TO recipients, SUBJECT, and CC recipients.")
+It is passed three arguments: TO recipients, SUBJECT, and CC recipients."
+ :type '(choice (const nil) function)
+ :group 'mh-compose)
-(defvar mh-before-send-letter-hook nil
- "Invoked at the beginning of the \\<mh-letter-mode-map>\\[mh-send-letter] command.")
+(defcustom mh-before-send-letter-hook nil
+ "Invoked at the beginning of the \\<mh-letter-mode-map>\\[mh-send-letter] command."
+ :type 'hook
+ :group 'mh-compose)
(defvar mh-rejected-letter-start
(call-interactively 'mh-send))
+(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."
+ (mh-find-path)
+ (let ((mh-error-if-no-draft t))
+ (mh-send (or to "") "" (or subject ""))))
+
+
(defun mh-edit-again (msg)
"Clean-up a draft or a message previously sent and make it resendable.
Default is the current message.
(mh-read-draft "clean-up" (mh-msg-filename msg) nil)))))
(mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil)
(goto-char (point-min))
- (set-buffer-modified-p nil)
+ (save-buffer)
(mh-compose-and-send-mail draft "" from-folder nil nil nil nil nil nil
config)))
(defun mh-extract-rejected-mail (msg)
"Extract a letter returned by the mail system and make it resendable.
-Default is the current message. The variable mh-new-draft-cleaned-headers
+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."
(interactive (list (mh-get-msg-num t)))
(t
(message "Does not appear to be a rejected letter.")))
(goto-char (point-min))
- (set-buffer-modified-p nil)
+ (save-buffer)
(mh-compose-and-send-mail draft "" from-folder msg
(mh-get-header-field "To:")
(mh-get-header-field "From:")
(prog1
(mh-read-draft "" draft-name t)
(mh-insert-fields "To:" to "Cc:" cc)
- (set-buffer-modified-p nil)))
+ (save-buffer)))
(t
- (mh-read-draft "" draft-name nil)))))
+ (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)))
(let (orig-from
orig-subject)
- (goto-char (point-min))
- (re-search-forward "^------- Forwarded Message")
- (forward-line 1)
- (skip-chars-forward " \t\n")
- (save-restriction
- (narrow-to-region (point) (point-max))
+ (save-excursion
+ (set-buffer (get-buffer-create mh-temp-buffer))
+ (erase-buffer)
+ (insert-file-contents fwd-msg-file)
(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-insert-fields "Subject:" forw-subject)
(goto-char (point-min))
- (re-search-forward "^------- Forwarded Message")
- (forward-line -1)
+ (if (re-search-forward "^------- Forwarded Message" nil t)
+ (forward-line -1)
+ (re-search-forward "^--------")
+ (forward-line 1))
(delete-other-windows)
(if (numberp msg-or-seq)
(mh-add-msgs-to-seq msg-or-seq 'forwarded t)
(defun mh-redistribute (to cc &optional msg)
"Redistribute a letter.
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."
+setting of the variable `mh-redist-full-contents'. See its documentation."
(interactive (list (mh-read-address "Redist-To: ")
(mh-read-address "Redist-Cc: ")
(mh-get-msg-num t)))
(defun mh-reply (message &optional includep)
"Reply to MESSAGE (default: current message).
If optional prefix argument INCLUDEP provided, then include the message
-in the reply using filter mhl.reply in your MH directory.
+in the reply using filter `mhl.reply' in your MH directory.
Prompts for type of addresses to reply to:
from sender only,
to sender and primary recipients,
(interactive (list (mh-get-msg-num t) current-prefix-arg))
(let ((minibuffer-help-form
"from => Sender only\nto => Sender and primary recipients\ncc or all => Sender and all recipients"))
- (let ((reply-to (or mh-reply-default-reply-to
+ (let* ((reply-to (or mh-reply-default-reply-to
(completing-read "Reply to whom: "
'(("from") ("to") ("cc") ("all"))
nil
t)))
- (folder mh-current-folder)
- (show-buffer mh-show-buffer)
- (config (current-window-configuration)))
+ (folder mh-current-folder)
+ (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-p group-reply
+ (stringp mh-repl-group-formfile))
+ mh-repl-group-formfile)
+ ((stringp mh-repl-formfile) mh-repl-formfile)
+ (t nil))))
(message "Composing a reply...")
(mh-exec-cmd "repl" "-build" "-noquery" "-nodraftfolder"
- (if (stringp mh-repl-formfile) ;must be string, but we're paranoid
- (list "-form" mh-repl-formfile))
+ (if form-file
+ (list "-form" form-file))
mh-current-folder message
(cond ((or (equal reply-to "from") (equal reply-to ""))
'("-nocc" "all"))
((equal reply-to "to")
'("-cc" "to"))
- ((or (equal reply-to "cc") (equal reply-to "all"))
- '("-cc" "all" "-nocc" "me")))
+ (group-reply (if mh-nmh-p
+ '("-group" "-nocc" "me")
+ '("-cc" "all" "-nocc" "me"))))
(if includep
'("-filter" "mhl.reply")))
(let ((draft (mh-read-draft "reply"
(expand-file-name "reply" mh-user-path)
t)))
(delete-other-windows)
- (set-buffer-modified-p nil)
+ (save-buffer)
(let ((to (mh-get-header-field "To:"))
(subject (mh-get-header-field "Subject:"))
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."
+draft and passed three arguments: TO, SUBJECT, and CC."
(interactive (list
(mh-read-address "To: ")
(mh-read-address "Cc: ")
(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
+ (and (boundp 'mh-etc) mh-etc))))
+ components)
(t
(error (format "Can't find components file \"%s\""
components)))))
(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.
(delete-file draft-name))))))
(cond ((and initial-contents
(or (zerop (buffer-size))
- (not (y-or-n-p
- (format "A draft exists. Use for %s? " use)))))
+ (if (y-or-n-p
+ (format "A draft exists. Use for %s? " use))
+ (if mh-error-if-no-draft
+ (error "A prior draft exists"))
+ t)))
(erase-buffer)
(insert-file-contents initial-contents)
(if delete-contents-file (delete-file initial-contents))))
(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
(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.
- (if (re-search-forward "^$\\|^-+$" nil nil)
+ (if (re-search-forward "^-*$" nil nil)
(forward-line arg)))
(put 'mh-letter-mode 'mode-class 'special)
;;;###autoload
-(defun mh-letter-mode ()
+(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.
mh-signature-file-name (\"~/.signature\")
File to be inserted into message by \\[mh-insert-signature].
-Upon invoking mh-letter-mode, text-mode-hook and mh-letter-mode-hook are
-invoked with no args, if those values are non-nil."
-
- (interactive)
+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 'mh-sent-from-msg)
(make-local-variable 'mail-header-separator)
(setq mail-header-separator "--------") ;for Hyperbole
- (use-local-map mh-letter-mode-map)
- (setq major-mode 'mh-letter-mode)
- (mh-set-mode-name "MH-Letter")
- (set-syntax-table mh-letter-mode-syntax-table)
- (run-hooks 'text-mode-hook)
;; if text-mode-hook turned on auto-fill, tune it for messages
- (cond ((and (boundp 'auto-fill-hook) auto-fill-hook) ;emacs 18
- (make-local-variable 'auto-fill-hook)
- (setq auto-fill-hook 'mh-auto-fill-for-letter)))
- (cond ((and (boundp 'auto-fill-function) auto-fill-function) ;emacs 19
- (make-local-variable 'auto-fill-function)
- (setq auto-fill-function 'mh-auto-fill-for-letter)))
- (run-hooks 'mh-letter-mode-hook))
+ (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 ()
;; Auto-fill in letters treats the header specially by inserting a tab
;; before continuation line.
- (do-auto-fill)
(if (mh-in-header-p)
- (save-excursion
- (beginning-of-line nil)
- (insert-char ?\t 1))))
+ (let ((fill-prefix "\t"))
+ (do-auto-fill))
+ (do-auto-fill)))
(defun mh-in-header-p ()
(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.
+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)
(defun mh-insert-signature ()
- "Insert the file named by mh-signature-file-name at the current point."
+ "Insert the file named by `mh-signature-file-name' at point."
(interactive)
(insert-file-contents mh-signature-file-name)
- (set-buffer-modified-p (buffer-modified-p))) ; force mode line update
+ (force-mode-line-update))
(defun mh-check-whom ()
(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 doing anything."
+Run `mh-before-send-letter-hook' before actually doing anything."
(interactive "P")
(run-hooks 'mh-before-send-letter-hook)
- (set-buffer-modified-p t) ; Make sure buffer is written
(save-buffer)
(message "Sending...")
(let ((draft-buffer (current-buffer))
(file-name buffer-file-name)
- (config mh-previous-window-config))
+ (config mh-previous-window-config)
+ (coding-system-for-write
+ (if (and (local-variable-p 'buffer-file-coding-system)
+ ;; 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
+ 'iso-latin-1))))
(cond (arg
(pop-to-buffer "MH mail delivery")
(erase-buffer)
(defun mh-insert-letter (folder message verbatim)
"Insert a message into the current letter.
-Removes the message's headers using mh-invisible-headers. Prefixes
-each non-blank line with mh-ins-buf-prefix. Prompts for FOLDER and
+Removes the message's headers using `mh-invisible-headers'. Prefixes
+each non-blank line with `mh-ins-buf-prefix'. 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
(run-hooks 'mh-yank-hooks))
(t
(or (bolp) (forward-line 1))
- (let ((zmacs-regions nil)) ;so "(mark)" works in XEmacs
- (while (< (point) (mark))
- (insert mh-ins-string)
- (forward-line 1))))))
+ (while (< (point) (mark))
+ (insert mh-ins-string)
+ (forward-line 1)))))
(defun mh-fully-kill-draft ()
(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 message part from a file.
+ "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 an anonymous ftp external body part.
+ "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 reference to a compressed tar file.
+ "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.
+ "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)
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.
+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),
(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)
+
+;;; mh-comp.el ends here