Mercurial > emacs
annotate lisp/mail/mh-comp.el @ 22843:63f6e25f0cbd
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 29 Jul 1998 03:01:39 +0000 |
parents | fd24f556ad8f |
children | d072093cd922 |
rev | line source |
---|---|
6365 | 1 ;;; mh-comp --- mh-e functions for composing messages |
13385 | 2 ;; Time-stamp: <95/08/19 17:48:59 gildea> |
6365 | 3 |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
4 ;; Copyright (C) 1993, 1995, 1997 Free Software Foundation, Inc. |
6365 | 5 |
13385 | 6 ;; This file is part of mh-e, part of GNU Emacs. |
6365 | 7 |
11333 | 8 ;; GNU Emacs is free software; you can redistribute it and/or modify |
6365 | 9 ;; it under the terms of the GNU General Public License as published by |
10 ;; the Free Software Foundation; either version 2, or (at your option) | |
11 ;; any later version. | |
12 | |
11333 | 13 ;; GNU Emacs is distributed in the hope that it will be useful, |
6365 | 14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 ;; GNU General Public License for more details. | |
17 | |
18 ;; You should have received a copy of the GNU General Public License | |
14169 | 19 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 ;; Boston, MA 02111-1307, USA. | |
6365 | 22 |
23 ;;; Commentary: | |
24 | |
25 ;; Internal support for mh-e package. | |
26 | |
11332 | 27 ;;; Change Log: |
28 | |
22590
fd24f556ad8f
(mh-yank-from-start-of-msg): Use `other' widget
Andreas Schwab <schwab@suse.de>
parents:
19952
diff
changeset
|
29 ;; $Id: mh-comp.el,v 1.12 1997/09/19 04:27:56 rms Exp $ |
11332 | 30 |
6365 | 31 ;;; Code: |
32 | |
33 (provide 'mh-comp) | |
34 (require 'mh-utils) | |
35 | |
11332 | 36 ;;; Site customization (see also mh-utils.el): |
37 | |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
38 (defgroup mh-compose nil |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
39 "Mh-e functions for composing messages" |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
40 :prefix "mh-" |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
41 :group 'mh) |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
42 |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
43 |
11332 | 44 (defvar mh-send-prog "send" |
45 "Name of the MH send program. | |
46 Some sites need to change this because of a name conflict.") | |
47 | |
48 (defvar mh-redist-full-contents nil | |
49 "Non-nil if the `dist' command needs whole letter for redistribution. | |
50 This is the case only when `send' is compiled with the BERK option. | |
51 If MH will not allow you to redist a previously redist'd msg, set to nil.") | |
52 | |
53 | |
6365 | 54 (defvar mh-note-repl "-" |
55 "String whose first character is used to notate replied to messages.") | |
56 | |
57 (defvar mh-note-forw "F" | |
58 "String whose first character is used to notate forwarded messages.") | |
59 | |
60 (defvar mh-note-dist "R" | |
61 "String whose first character is used to notate redistributed messages.") | |
62 | |
63 (defvar mh-yank-hooks nil | |
64 "Obsolete hook for modifying a citation just inserted in the mail buffer. | |
65 Each hook function can find the citation between point and mark. | |
66 And each hook function should leave point and mark around the citation | |
67 text as modified. | |
68 | |
69 This is a normal hook, misnamed for historical reasons. | |
19936 | 70 It is semi-obsolete and is only used if `mail-citation-hook' is nil.") |
6365 | 71 |
72 (defvar mail-citation-hook nil | |
73 "*Hook for modifying a citation just inserted in the mail buffer. | |
74 Each hook function can find the citation between point and mark. | |
75 And each hook function should leave point and mark around the citation | |
76 text as modified. | |
77 | |
78 If this hook is entirely empty (nil), the text of the message is inserted | |
19936 | 79 with `mh-ins-buf-prefix' prefixed to each line. |
6365 | 80 |
19936 | 81 See also the variable `mh-yank-from-start-of-msg', which controls how |
6365 | 82 much of the message passed to the hook.") |
83 | |
84 ;;; Copied from sendmail.el for Hyperbole | |
85 (defvar mail-header-separator "--------" | |
86 "*Line used by MH to separate headers from text in messages being composed.") | |
87 | |
88 ;;; Personal preferences: | |
89 | |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
90 (defcustom mh-delete-yanked-msg-window nil |
6365 | 91 "*Controls window display when a message is yanked by \\<mh-letter-mode-map>\\[mh-yank-cur-msg]. |
92 If non-nil, yanking the current message into a draft letter deletes any | |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
93 windows displaying the message." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
94 :type 'boolean |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
95 :group 'mh-compose) |
6365 | 96 |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
97 (defcustom mh-yank-from-start-of-msg t |
6365 | 98 "*Controls which part of a message is yanked by \\<mh-letter-mode-map>\\[mh-yank-cur-msg]. |
99 If non-nil, include the entire message. If the symbol `body', then yank the | |
100 message minus the header. If nil, yank only the portion of the message | |
101 following the point. If the show buffer has a region, this variable is | |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
102 ignored." |
22590
fd24f556ad8f
(mh-yank-from-start-of-msg): Use `other' widget
Andreas Schwab <schwab@suse.de>
parents:
19952
diff
changeset
|
103 :type '(choice (const :tag "Below point" nil) |
fd24f556ad8f
(mh-yank-from-start-of-msg): Use `other' widget
Andreas Schwab <schwab@suse.de>
parents:
19952
diff
changeset
|
104 (const :tag "Without header" body) |
fd24f556ad8f
(mh-yank-from-start-of-msg): Use `other' widget
Andreas Schwab <schwab@suse.de>
parents:
19952
diff
changeset
|
105 (other :tag "Entire message" t)) |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
106 :group 'mh-compose) |
6365 | 107 |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
108 (defcustom mh-ins-buf-prefix "> " |
11332 | 109 "*String to put before each non-blank line of a yanked or inserted message. |
110 \\<mh-letter-mode-map>Used when the message is inserted into an outgoing letter | |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
111 by \\[mh-insert-letter] or \\[mh-yank-cur-msg]." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
112 :type 'string |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
113 :group 'mh-compose) |
11332 | 114 |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
115 (defcustom mh-reply-default-reply-to nil |
6365 | 116 "*Sets the person or persons to whom a reply will be sent. |
117 If nil, prompt for recipient. If non-nil, then \\<mh-folder-mode-map>`\\[mh-reply]' will use this | |
11332 | 118 value and it should be one of \"from\", \"to\", \"cc\", or \"all\". |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
119 The values \"cc\" and \"all\" do the same thing." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
120 :type '(choice (const :tag "Prompt" nil) |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
121 (const "from") (const "to") |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
122 (const "cc") (const "all")) |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
123 :group 'mh-compose) |
6365 | 124 |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
125 (defcustom mh-signature-file-name "~/.signature" |
6365 | 126 "*Name of file containing the user's signature. |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
127 Inserted into message by \\<mh-letter-mode-map>\\[mh-insert-signature]." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
128 :type 'file |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
129 :group 'mh-compose) |
6365 | 130 |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
131 (defcustom mh-forward-subject-format "%s: %s" |
6365 | 132 "*Format to generate the Subject: line contents for a forwarded message. |
133 The two string arguments to the format are the sender of the original | |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
134 message and the original subject line." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
135 :type 'string |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
136 :group 'mh-compose) |
6365 | 137 |
138 (defvar mh-comp-formfile "components" | |
139 "Name of file to be used as a skeleton for composing messages. | |
19936 | 140 Default is \"components\". If not an absolute file name, the file |
6365 | 141 is searched for first in the user's MH directory, then in the |
142 system MH lib directory.") | |
143 | |
11332 | 144 (defvar mh-repl-formfile "replcomps" |
145 "Name of file to be used as a skeleton for replying to messages. | |
19936 | 146 Default is \"replcomps\". If not an absolute file name, the file |
11332 | 147 is searched for first in the user's MH directory, then in the |
148 system MH lib directory.") | |
149 | |
6365 | 150 ;;; Hooks: |
151 | |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
152 (defcustom mh-letter-mode-hook nil |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
153 "Invoked in `mh-letter-mode' on a new letter." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
154 :type 'hook |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
155 :group 'mh-compose) |
6365 | 156 |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
157 (defcustom mh-compose-letter-function nil |
11332 | 158 "Invoked when setting up a letter draft. |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
159 It is passed three arguments: TO recipients, SUBJECT, and CC recipients." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
160 :type 'function |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
161 :group 'mh-compose) |
6365 | 162 |
17426
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
163 (defcustom mh-before-send-letter-hook nil |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
164 "Invoked at the beginning of the \\<mh-letter-mode-map>\\[mh-send-letter] command." |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
165 :type 'hook |
5c5fa38a1c79
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
166 :group 'mh-compose) |
6365 | 167 |
168 | |
169 (defvar mh-rejected-letter-start | |
11332 | 170 (concat "^ ----- Unsent message follows -----$" ;from sendmail V5 |
171 "\\|^ ----- Original message follows -----$" ;from sendmail V8 | |
172 "\\|^------- Unsent Draft$" ;from MH itself | |
6365 | 173 "\\|^---------- Original Message ----------$" ;from zmailer |
11332 | 174 "\\|^ --- The unsent message follows ---$" ;from AIX mail system |
175 "\\|^ Your message follows:$" ;from MMDF-II | |
176 "\\|^Content-Description: Returned Content$" ;1993 KJ sendmail | |
177 ) | |
6365 | 178 "Regexp specifying the beginning of the wrapper around a returned letter. |
179 This wrapper is generated by the mail system when rejecting a letter.") | |
180 | |
181 (defvar mh-new-draft-cleaned-headers | |
11332 | 182 "^Date:\\|^Received:\\|^Message-Id:\\|^From:\\|^Sender:\\|^Errors-To:\\|^Delivery-Date:\\|^Return-Path:" |
6365 | 183 "Regexp of header lines to remove before offering a message as a new draft. |
184 Used by the \\<mh-folder-mode-map>`\\[mh-edit-again]' and `\\[mh-extract-rejected-mail]' commands.") | |
185 | |
11332 | 186 (defvar mh-to-field-choices '(("t" . "To:") ("s" . "Subject:") ("c" . "Cc:") |
187 ("b" . "Bcc:") ("f" . "Fcc:") ("r" . "From:") | |
188 ("d" . "Dcc:")) | |
6365 | 189 "Alist of (final-character . field-name) choices for mh-to-field.") |
190 | |
191 (defvar mh-letter-mode-map (copy-keymap text-mode-map) | |
192 "Keymap for composing mail.") | |
193 | |
194 (defvar mh-letter-mode-syntax-table nil | |
195 "Syntax table used by mh-e while in MH-Letter mode.") | |
196 | |
197 (if mh-letter-mode-syntax-table | |
198 () | |
199 (setq mh-letter-mode-syntax-table | |
200 (make-syntax-table text-mode-syntax-table)) | |
201 (modify-syntax-entry ?% "." mh-letter-mode-syntax-table)) | |
202 | |
203 | |
204 ;;;###autoload | |
205 (defun mh-smail () | |
206 "Compose and send mail with the MH mail system. | |
207 This function is an entry point to mh-e, the Emacs front end | |
11332 | 208 to the MH mail system. |
209 | |
210 See documentation of `\\[mh-send]' for more details on composing mail." | |
6365 | 211 (interactive) |
212 (mh-find-path) | |
213 (call-interactively 'mh-send)) | |
214 | |
215 | |
13385 | 216 (defvar mh-error-if-no-draft nil) ;raise error over using old draft |
217 | |
218 | |
219 ;;;###autoload | |
17593
f3bbebd5c01d
(mh-smail-batch): Accpt &rest arg `ignored'.
Richard M. Stallman <rms@gnu.org>
parents:
17426
diff
changeset
|
220 (defun mh-smail-batch (&rest ignored) |
13385 | 221 "Set up a mail composition draft with the MH mail system. |
222 This function is an entry point to mh-e, the Emacs front end | |
223 to the MH mail system. This function does not prompt the user | |
224 for any header fields, and thus is suitable for use by programs | |
225 that want to create a mail buffer. | |
226 Users should use `\\[mh-smail]' to compose mail." | |
227 (mh-find-path) | |
228 (let ((mh-error-if-no-draft t)) | |
229 (mh-send "" "" ""))) | |
230 | |
231 | |
6365 | 232 (defun mh-edit-again (msg) |
233 "Clean-up a draft or a message previously sent and make it resendable. | |
11332 | 234 Default is the current message. |
6365 | 235 The variable mh-new-draft-cleaned-headers specifies the headers to remove. |
236 See also documentation for `\\[mh-send]' function." | |
237 (interactive (list (mh-get-msg-num t))) | |
238 (let* ((from-folder mh-current-folder) | |
239 (config (current-window-configuration)) | |
240 (draft | |
241 (cond ((and mh-draft-folder (equal from-folder mh-draft-folder)) | |
242 (pop-to-buffer (find-file-noselect (mh-msg-filename msg)) t) | |
243 (rename-buffer (format "draft-%d" msg)) | |
244 (buffer-name)) | |
245 (t | |
246 (mh-read-draft "clean-up" (mh-msg-filename msg) nil))))) | |
247 (mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil) | |
248 (goto-char (point-min)) | |
13385 | 249 (save-buffer) |
6365 | 250 (mh-compose-and-send-mail draft "" from-folder nil nil nil nil nil nil |
251 config))) | |
252 | |
253 | |
254 (defun mh-extract-rejected-mail (msg) | |
255 "Extract a letter returned by the mail system and make it resendable. | |
19936 | 256 Default is the current message. The variable `mh-new-draft-cleaned-headers' |
6365 | 257 gives the headers to clean out of the original message. |
258 See also documentation for `\\[mh-send]' function." | |
259 (interactive (list (mh-get-msg-num t))) | |
260 (let ((from-folder mh-current-folder) | |
261 (config (current-window-configuration)) | |
262 (draft (mh-read-draft "extraction" (mh-msg-filename msg) nil))) | |
263 (goto-char (point-min)) | |
264 (cond ((re-search-forward mh-rejected-letter-start nil t) | |
265 (skip-chars-forward " \t\n") | |
266 (delete-region (point-min) (point)) | |
267 (mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil)) | |
268 (t | |
269 (message "Does not appear to be a rejected letter."))) | |
270 (goto-char (point-min)) | |
13385 | 271 (save-buffer) |
11332 | 272 (mh-compose-and-send-mail draft "" from-folder msg |
273 (mh-get-header-field "To:") | |
274 (mh-get-header-field "From:") | |
275 (mh-get-header-field "Cc:") | |
6365 | 276 nil nil config))) |
277 | |
278 | |
279 (defun mh-forward (to cc &optional msg-or-seq) | |
280 "Forward a message or message sequence. Defaults to displayed message. | |
281 If optional prefix argument provided, then prompt for the message sequence. | |
282 See also documentation for `\\[mh-send]' function." | |
283 (interactive (list (mh-read-address "To: ") | |
284 (mh-read-address "Cc: ") | |
285 (if current-prefix-arg | |
286 (mh-read-seq-default "Forward" t) | |
11332 | 287 (mh-get-msg-num t)))) |
6365 | 288 (or msg-or-seq |
289 (setq msg-or-seq (mh-get-msg-num t))) | |
290 (let* ((folder mh-current-folder) | |
291 (config (current-window-configuration)) | |
292 ;; forw always leaves file in "draft" since it doesn't have -draft | |
293 (draft-name (expand-file-name "draft" mh-user-path)) | |
294 (draft (cond ((or (not (file-exists-p draft-name)) | |
295 (y-or-n-p "The file 'draft' exists. Discard it? ")) | |
11332 | 296 (mh-exec-cmd "forw" "-build" |
297 mh-current-folder msg-or-seq) | |
6365 | 298 (prog1 |
299 (mh-read-draft "" draft-name t) | |
300 (mh-insert-fields "To:" to "Cc:" cc) | |
13385 | 301 (save-buffer))) |
6365 | 302 (t |
303 (mh-read-draft "" draft-name nil))))) | |
11332 | 304 (let (orig-from |
305 orig-subject) | |
306 (goto-char (point-min)) | |
307 (re-search-forward "^------- Forwarded Message") | |
308 (forward-line 1) | |
309 (skip-chars-forward " \t\n") | |
310 (save-restriction | |
311 (narrow-to-region (point) (point-max)) | |
312 (setq orig-from (mh-get-header-field "From:")) | |
313 (setq orig-subject (mh-get-header-field "Subject:"))) | |
6365 | 314 (let ((forw-subject |
315 (mh-forwarded-letter-subject orig-from orig-subject))) | |
11332 | 316 (mh-insert-fields "Subject:" forw-subject) |
317 (goto-char (point-min)) | |
318 (re-search-forward "^------- Forwarded Message") | |
319 (forward-line -1) | |
320 (delete-other-windows) | |
321 (if (numberp msg-or-seq) | |
322 (mh-add-msgs-to-seq msg-or-seq 'forwarded t) | |
6365 | 323 (mh-add-msgs-to-seq (mh-seq-to-msgs msg-or-seq) 'forwarded t)) |
11332 | 324 (mh-compose-and-send-mail draft "" folder msg-or-seq |
325 to forw-subject cc | |
326 mh-note-forw "Forwarded:" | |
327 config))))) | |
6365 | 328 |
329 (defun mh-forwarded-letter-subject (from subject) | |
330 ;; Return a Subject suitable for a forwarded message. | |
331 ;; Original message has headers FROM and SUBJECT. | |
332 (let ((addr-start (string-match "<" from)) | |
333 (comment (string-match "(" from))) | |
334 (cond ((and addr-start (> addr-start 0)) | |
335 ;; Full Name <luser@host> | |
336 (setq from (substring from 0 (1- addr-start)))) | |
337 (comment | |
338 ;; luser@host (Full Name) | |
339 (setq from (substring from (1+ comment) (1- (length from))))))) | |
340 (format mh-forward-subject-format from subject)) | |
341 | |
342 | |
343 ;;;###autoload | |
344 (defun mh-smail-other-window () | |
345 "Compose and send mail in other window with the MH mail system. | |
346 This function is an entry point to mh-e, the Emacs front end | |
11332 | 347 to the MH mail system. |
348 | |
349 See documentation of `\\[mh-send]' for more details on composing mail." | |
6365 | 350 (interactive) |
351 (mh-find-path) | |
352 (call-interactively 'mh-send-other-window)) | |
353 | |
354 | |
355 (defun mh-redistribute (to cc &optional msg) | |
356 "Redistribute a letter. | |
357 Depending on how your copy of MH was compiled, you may need to change the | |
19936 | 358 setting of the variable `mh-redist-full-contents'. See its documentation." |
6365 | 359 (interactive (list (mh-read-address "Redist-To: ") |
360 (mh-read-address "Redist-Cc: ") | |
361 (mh-get-msg-num t))) | |
362 (or msg | |
363 (setq msg (mh-get-msg-num t))) | |
364 (save-window-excursion | |
365 (let ((folder mh-current-folder) | |
366 (draft (mh-read-draft "redistribution" | |
367 (if mh-redist-full-contents | |
368 (mh-msg-filename msg) | |
369 nil) | |
370 nil))) | |
371 (mh-goto-header-end 0) | |
372 (insert "Resent-To: " to "\n") | |
373 (if (not (equal cc "")) (insert "Resent-cc: " cc "\n")) | |
374 (mh-clean-msg-header (point-min) | |
375 "^Message-Id:\\|^Received:\\|^Return-Path:\\|^Sender:\\|^Date:\\|^From:" | |
376 nil) | |
377 (save-buffer) | |
378 (message "Redistributing...") | |
379 (if mh-redist-full-contents | |
380 (call-process "/bin/sh" nil 0 nil "-c" | |
381 (format "mhdist=1 mhaltmsg=%s %s -push %s" | |
11332 | 382 buffer-file-name |
6365 | 383 (expand-file-name mh-send-prog mh-progs) |
11332 | 384 buffer-file-name)) |
6365 | 385 (call-process "/bin/sh" nil 0 nil "-c" |
386 (format "mhdist=1 mhaltmsg=%s mhannotate=1 %s -push %s" | |
387 (mh-msg-filename msg folder) | |
388 (expand-file-name mh-send-prog mh-progs) | |
11332 | 389 buffer-file-name))) |
6365 | 390 (mh-annotate-msg msg folder mh-note-dist |
391 "-component" "Resent:" | |
392 "-text" (format "\"%s %s\"" to cc)) | |
393 (kill-buffer draft) | |
394 (message "Redistributing...done")))) | |
395 | |
396 | |
11332 | 397 (defun mh-reply (message &optional includep) |
398 "Reply to MESSAGE (default: current message). | |
6365 | 399 If optional prefix argument INCLUDEP provided, then include the message |
19936 | 400 in the reply using filter `mhl.reply' in your MH directory. |
6365 | 401 Prompts for type of addresses to reply to: |
402 from sender only, | |
403 to sender and primary recipients, | |
404 cc/all sender and all recipients. | |
11332 | 405 If the file named by `mh-repl-formfile' exists, it is used as a skeleton |
406 for the reply. See also documentation for `\\[mh-send]' function." | |
6365 | 407 (interactive (list (mh-get-msg-num t) current-prefix-arg)) |
408 (let ((minibuffer-help-form | |
409 "from => Sender only\nto => Sender and primary recipients\ncc or all => Sender and all recipients")) | |
410 (let ((reply-to (or mh-reply-default-reply-to | |
411 (completing-read "Reply to whom: " | |
412 '(("from") ("to") ("cc") ("all")) | |
413 nil | |
414 t))) | |
415 (folder mh-current-folder) | |
416 (show-buffer mh-show-buffer) | |
417 (config (current-window-configuration))) | |
418 (message "Composing a reply...") | |
419 (mh-exec-cmd "repl" "-build" "-noquery" "-nodraftfolder" | |
11332 | 420 (if (stringp mh-repl-formfile) ;must be string, but we're paranoid |
421 (list "-form" mh-repl-formfile)) | |
422 mh-current-folder message | |
6365 | 423 (cond ((or (equal reply-to "from") (equal reply-to "")) |
424 '("-nocc" "all")) | |
425 ((equal reply-to "to") | |
426 '("-cc" "to")) | |
427 ((or (equal reply-to "cc") (equal reply-to "all")) | |
428 '("-cc" "all" "-nocc" "me"))) | |
429 (if includep | |
430 '("-filter" "mhl.reply"))) | |
431 (let ((draft (mh-read-draft "reply" | |
432 (expand-file-name "reply" mh-user-path) | |
433 t))) | |
434 (delete-other-windows) | |
13385 | 435 (save-buffer) |
6365 | 436 |
11332 | 437 (let ((to (mh-get-header-field "To:")) |
438 (subject (mh-get-header-field "Subject:")) | |
439 (cc (mh-get-header-field "Cc:"))) | |
6365 | 440 (goto-char (point-min)) |
441 (mh-goto-header-end 1) | |
442 (or includep | |
443 (mh-in-show-buffer (show-buffer) | |
11332 | 444 (mh-display-msg message folder))) |
445 (mh-add-msgs-to-seq message 'answered t) | |
6365 | 446 (message "Composing a reply...done") |
11332 | 447 (mh-compose-and-send-mail draft "" folder message to subject cc |
6365 | 448 mh-note-repl "Replied:" config)))))) |
449 | |
450 | |
451 (defun mh-send (to cc subject) | |
452 "Compose and send a letter. | |
453 The file named by `mh-comp-formfile' will be used as the form. | |
11332 | 454 Do not call this function from outside mh-e; use \\[mh-smail] instead. |
455 | |
6365 | 456 The letter is composed in mh-letter-mode; see its documentation for more |
457 details. If `mh-compose-letter-function' is defined, it is called on the | |
19936 | 458 draft and passed three arguments: TO, SUBJECT, and CC." |
6365 | 459 (interactive (list |
460 (mh-read-address "To: ") | |
461 (mh-read-address "Cc: ") | |
462 (read-string "Subject: "))) | |
463 (let ((config (current-window-configuration))) | |
464 (delete-other-windows) | |
465 (mh-send-sub to cc subject config))) | |
466 | |
467 | |
468 (defun mh-send-other-window (to cc subject) | |
469 "Compose and send a letter in another window. | |
470 Do not call this function from outside mh-e; | |
471 use \\[mh-smail-other-window] instead. | |
472 See also documentation for `\\[mh-send]' function." | |
473 (interactive (list | |
474 (mh-read-address "To: ") | |
475 (mh-read-address "Cc: ") | |
476 (read-string "Subject: "))) | |
477 (let ((pop-up-windows t)) | |
478 (mh-send-sub to cc subject (current-window-configuration)))) | |
479 | |
480 | |
481 (defun mh-send-sub (to cc subject config) | |
11332 | 482 ;; Do the real work of composing and sending a letter. |
483 ;; Expects the TO, CC, and SUBJECT fields as arguments. | |
484 ;; CONFIG is the window configuration before sending mail. | |
6365 | 485 (let ((folder mh-current-folder) |
486 (msg-num (mh-get-msg-num nil))) | |
487 (message "Composing a message...") | |
488 (let ((draft (mh-read-draft | |
489 "message" | |
490 (let (components) | |
491 (cond | |
492 ((file-exists-p | |
493 (setq components | |
494 (expand-file-name mh-comp-formfile mh-user-path))) | |
495 components) | |
496 ((file-exists-p | |
497 (setq components | |
498 (expand-file-name mh-comp-formfile mh-lib))) | |
499 components) | |
500 (t | |
501 (error (format "Can't find components file \"%s\"" | |
502 components))))) | |
503 nil))) | |
504 (mh-insert-fields "To:" to "Subject:" subject "Cc:" cc) | |
505 (goto-char (point-max)) | |
506 (message "Composing a message...done") | |
507 (mh-compose-and-send-mail draft "" folder msg-num | |
508 to subject cc | |
509 nil nil config)))) | |
510 | |
511 | |
512 (defun mh-read-draft (use initial-contents delete-contents-file) | |
513 ;; Read draft file into a draft buffer and make that buffer the current one. | |
514 ;; USE is a message used for prompting about the intended use of the message. | |
515 ;; INITIAL-CONTENTS is filename that is read into an empty buffer, or NIL | |
516 ;; if buffer should not be modified. Delete the initial-contents file if | |
517 ;; DELETE-CONTENTS-FILE flag is set. | |
518 ;; Returns the draft folder's name. | |
519 ;; If the draft folder facility is enabled in ~/.mh_profile, a new buffer is | |
520 ;; used each time and saved in the draft folder. The draft file can then be | |
521 ;; reused. | |
522 (cond (mh-draft-folder | |
523 (let ((orig-default-dir default-directory) | |
524 (draft-file-name (mh-new-draft-name))) | |
525 (pop-to-buffer (generate-new-buffer | |
526 (format "draft-%s" | |
527 (file-name-nondirectory draft-file-name)))) | |
528 (condition-case () | |
529 (insert-file-contents draft-file-name t) | |
530 (file-error)) | |
531 (setq default-directory orig-default-dir))) | |
532 (t | |
533 (let ((draft-name (expand-file-name "draft" mh-user-path))) | |
534 (pop-to-buffer "draft") ; Create if necessary | |
535 (if (buffer-modified-p) | |
536 (if (y-or-n-p "Draft has been modified; kill anyway? ") | |
537 (set-buffer-modified-p nil) | |
538 (error "Draft preserved"))) | |
539 (setq buffer-file-name draft-name) | |
540 (clear-visited-file-modtime) | |
541 (unlock-buffer) | |
542 (cond ((and (file-exists-p draft-name) | |
543 (not (equal draft-name initial-contents))) | |
544 (insert-file-contents draft-name) | |
545 (delete-file draft-name)))))) | |
546 (cond ((and initial-contents | |
547 (or (zerop (buffer-size)) | |
13385 | 548 (if (y-or-n-p |
549 (format "A draft exists. Use for %s? " use)) | |
550 (if mh-error-if-no-draft | |
551 (error "A prior draft exists.")) | |
552 t))) | |
6365 | 553 (erase-buffer) |
554 (insert-file-contents initial-contents) | |
555 (if delete-contents-file (delete-file initial-contents)))) | |
556 (auto-save-mode 1) | |
557 (if mh-draft-folder | |
558 (save-buffer)) ; Do not reuse draft name | |
559 (buffer-name)) | |
560 | |
561 | |
562 (defun mh-new-draft-name () | |
563 ;; Returns the pathname of folder for draft messages. | |
564 (save-excursion | |
565 (mh-exec-cmd-quiet t "mhpath" mh-draft-folder "new") | |
566 (buffer-substring (point-min) (1- (point-max))))) | |
567 | |
568 | |
569 (defun mh-annotate-msg (msg buffer note &rest args) | |
570 ;; Mark the MESSAGE in BUFFER listing with the character NOTE and annotate | |
571 ;; the saved message with ARGS. | |
572 (apply 'mh-exec-cmd "anno" buffer msg args) | |
573 (save-excursion | |
574 (cond ((get-buffer buffer) ; Buffer may be deleted | |
575 (set-buffer buffer) | |
576 (if (symbolp msg) | |
577 (mh-notate-seq msg note (1+ mh-cmd-note)) | |
578 (mh-notate msg note (1+ mh-cmd-note))))))) | |
579 | |
580 | |
581 (defun mh-insert-fields (&rest name-values) | |
582 ;; Insert the NAME-VALUE pairs in the current buffer. | |
583 ;; If field NAME exists, append VALUE to it. | |
584 ;; Do not insert any pairs whose value is the empty string. | |
585 (let ((case-fold-search t)) | |
586 (while name-values | |
587 (let ((field-name (car name-values)) | |
588 (value (car (cdr name-values)))) | |
589 (cond ((equal value "") | |
590 nil) | |
591 ((mh-position-on-field field-name) | |
592 (insert " " value)) | |
593 (t | |
594 (insert field-name " " value "\n"))) | |
595 (setq name-values (cdr (cdr name-values))))))) | |
596 | |
597 | |
598 (defun mh-position-on-field (field &optional ignore) | |
599 ;; Move to the end of the FIELD in the header. | |
600 ;; Move to end of entire header if FIELD not found. | |
601 ;; Returns non-nil iff FIELD was found. | |
602 ;; The optional second arg is for pre-version 4 compatibility. | |
11332 | 603 (if (mh-goto-header-field field) |
604 (progn | |
605 (mh-header-field-end) | |
606 t))) | |
607 | |
608 | |
609 (defun mh-get-header-field (field) | |
610 ;; Find and return the body of FIELD in the mail header. | |
611 ;; Returns the empty string if the field is not in the header of the | |
612 ;; current buffer. | |
613 (if (mh-goto-header-field field) | |
614 (progn | |
615 (skip-chars-forward " \t") ;strip leading white space in body | |
616 (let ((start (point))) | |
617 (mh-header-field-end) | |
618 (buffer-substring start (point)))) | |
619 "")) | |
620 | |
621 (fset 'mh-get-field 'mh-get-header-field) ;mh-e 4 compatibility | |
6365 | 622 |
11332 | 623 (defun mh-goto-header-field (field) |
624 ;; Move to FIELD in the message header. | |
625 ;; Move to the end of the FIELD name, which should end in a colon. | |
626 ;; Returns T if found, NIL if not. | |
627 (goto-char (point-min)) | |
628 (let ((case-fold-search t) | |
629 (headers-end (save-excursion | |
630 (mh-goto-header-end 0) | |
631 (point)))) | |
632 (re-search-forward (format "^%s" field) headers-end t))) | |
633 | |
634 (defun mh-header-field-end () | |
635 ;; Move to the end of the current header field. | |
636 ;; Handles RFC 822 continuation lines. | |
637 (forward-line 1) | |
638 (while (looking-at "^[ \t]") | |
639 (forward-line 1)) | |
640 (backward-char 1)) ;to end of previous line | |
641 | |
6365 | 642 |
643 (defun mh-goto-header-end (arg) | |
644 ;; Find the end of the message header in the current buffer and position | |
645 ;; the cursor at the ARG'th newline after the header. | |
11507 | 646 (if (re-search-forward "^-*$" nil nil) |
6365 | 647 (forward-line arg))) |
648 | |
649 | |
650 (defun mh-read-address (prompt) | |
651 ;; Read a To: or Cc: address, prompting in the minibuffer with PROMPT. | |
652 ;; May someday do completion on aliases. | |
653 (read-string prompt)) | |
654 | |
655 | |
656 | |
657 ;;; Mode for composing and sending a draft message. | |
658 | |
11332 | 659 (defvar mh-sent-from-folder nil) ;Folder of msg assoc with this letter. |
6365 | 660 |
11332 | 661 (defvar mh-sent-from-msg nil) ;Number of msg assoc with this letter. |
6365 | 662 |
11332 | 663 (defvar mh-send-args nil) ;Extra args to pass to "send" command. |
6365 | 664 |
11332 | 665 (defvar mh-annotate-char nil) ;Character to use to annotate mh-sent-from-msg. |
6365 | 666 |
11332 | 667 (defvar mh-annotate-field nil) ;Field name for message annotation. |
6365 | 668 |
669 (put 'mh-letter-mode 'mode-class 'special) | |
670 | |
671 ;;;###autoload | |
672 (defun mh-letter-mode () | |
673 "Mode for composing letters in mh-e.\\<mh-letter-mode-map> | |
11332 | 674 When you have finished composing, type \\[mh-send-letter] to send the message |
675 using the MH mail handling system. | |
676 See the documentation for \\[mh-edit-mhn] for information on composing MIME | |
677 messages. | |
6365 | 678 |
679 \\{mh-letter-mode-map} | |
680 | |
681 Variables controlling this mode (defaults in parentheses): | |
682 | |
683 mh-delete-yanked-msg-window (nil) | |
684 If non-nil, \\[mh-yank-cur-msg] will delete any windows displaying | |
685 the yanked message. | |
686 | |
687 mh-yank-from-start-of-msg (t) | |
688 If non-nil, \\[mh-yank-cur-msg] will include the entire message. | |
689 If `body', just yank the body (no header). | |
690 If nil, only the portion of the message following the point will be yanked. | |
691 If there is a region, this variable is ignored. | |
692 | |
11332 | 693 mh-ins-buf-prefix (\"> \") |
694 String to insert before each non-blank line of a message as it is | |
695 inserted in a draft letter. | |
696 | |
6365 | 697 mh-signature-file-name (\"~/.signature\") |
698 File to be inserted into message by \\[mh-insert-signature]. | |
699 | |
19936 | 700 This command runs the normal hooks `text-mode-hook' and `mh-letter-mode-hook'." |
6365 | 701 |
702 (interactive) | |
703 (or mh-user-path (mh-find-path)) | |
704 (make-local-variable 'paragraph-start) | |
11332 | 705 (setq paragraph-start (concat "^[ \t]*[-_][-_][-_]+$\\|" paragraph-start)) |
6365 | 706 (make-local-variable 'paragraph-separate) |
707 (setq paragraph-separate | |
11332 | 708 (concat "^[ \t]*[-_][-_][-_]+$\\|" paragraph-separate)) |
6365 | 709 (make-local-variable 'mh-send-args) |
710 (make-local-variable 'mh-annotate-char) | |
711 (make-local-variable 'mh-annotate-field) | |
712 (make-local-variable 'mh-previous-window-config) | |
713 (make-local-variable 'mh-sent-from-folder) | |
714 (make-local-variable 'mh-sent-from-msg) | |
715 (make-local-variable 'mail-header-separator) | |
716 (setq mail-header-separator "--------") ;for Hyperbole | |
717 (use-local-map mh-letter-mode-map) | |
718 (setq major-mode 'mh-letter-mode) | |
719 (mh-set-mode-name "MH-Letter") | |
720 (set-syntax-table mh-letter-mode-syntax-table) | |
721 (run-hooks 'text-mode-hook) | |
722 ;; if text-mode-hook turned on auto-fill, tune it for messages | |
723 (cond ((and (boundp 'auto-fill-hook) auto-fill-hook) ;emacs 18 | |
724 (make-local-variable 'auto-fill-hook) | |
725 (setq auto-fill-hook 'mh-auto-fill-for-letter))) | |
726 (cond ((and (boundp 'auto-fill-function) auto-fill-function) ;emacs 19 | |
727 (make-local-variable 'auto-fill-function) | |
728 (setq auto-fill-function 'mh-auto-fill-for-letter))) | |
729 (run-hooks 'mh-letter-mode-hook)) | |
730 | |
731 | |
732 (defun mh-auto-fill-for-letter () | |
733 ;; Auto-fill in letters treats the header specially by inserting a tab | |
734 ;; before continuation line. | |
735 (if (mh-in-header-p) | |
11507 | 736 (let ((fill-prefix "\t")) |
737 (do-auto-fill)) | |
738 (do-auto-fill))) | |
6365 | 739 |
740 | |
741 (defun mh-in-header-p () | |
742 ;; Return non-nil if the point is in the header of a draft message. | |
743 (save-excursion | |
744 (let ((cur-point (point))) | |
745 (goto-char (point-min)) | |
746 (re-search-forward "^-*$" nil t) | |
747 (< cur-point (point))))) | |
748 | |
749 | |
750 (defun mh-to-field () | |
751 "Move point to the end of a specified header field. | |
752 The field is indicated by the previous keystroke (the last keystroke | |
19936 | 753 of the command) according to the list in the variable `mh-to-field-choices'. |
6365 | 754 Create the field if it does not exist. Set the mark to point before moving." |
755 (interactive) | |
756 (expand-abbrev) | |
11332 | 757 (let ((target (cdr (or (assoc (char-to-string (logior last-input-char ?`)) |
758 mh-to-field-choices) | |
759 ;; also look for a char for version 4 compat | |
760 (assoc (logior last-input-char ?`) mh-to-field-choices)))) | |
6365 | 761 (case-fold-search t)) |
762 (push-mark) | |
763 (cond ((mh-position-on-field target) | |
764 (let ((eol (point))) | |
765 (skip-chars-backward " \t") | |
766 (delete-region (point) eol)) | |
767 (if (and (not (eq (logior last-input-char ?`) ?s)) | |
768 (save-excursion | |
769 (backward-char 1) | |
770 (not (looking-at "[:,]")))) | |
771 (insert ", ") | |
772 (insert " "))) | |
773 (t | |
774 (if (mh-position-on-field "To:") | |
775 (forward-line 1)) | |
776 (insert (format "%s \n" target)) | |
777 (backward-char 1))))) | |
778 | |
779 | |
780 (defun mh-to-fcc (&optional folder) | |
781 "Insert an Fcc: FOLDER field in the current message. | |
782 Prompt for the field name with a completion list of the current folders." | |
783 (interactive) | |
784 (or folder | |
785 (setq folder (mh-prompt-for-folder | |
786 "Fcc" | |
11332 | 787 (or (and mh-default-folder-for-message-function |
6365 | 788 (save-excursion |
789 (goto-char (point-min)) | |
11332 | 790 (funcall mh-default-folder-for-message-function))) |
6365 | 791 "") |
792 t))) | |
793 (let ((last-input-char ?\C-f)) | |
794 (expand-abbrev) | |
795 (save-excursion | |
796 (mh-to-field) | |
797 (insert (if (mh-folder-name-p folder) | |
798 (substring folder 1) | |
799 folder))))) | |
800 | |
801 | |
802 (defun mh-insert-signature () | |
19936 | 803 "Insert the file named by `mh-signature-file-name' at point." |
6365 | 804 (interactive) |
805 (insert-file-contents mh-signature-file-name) | |
11578
d8480e4513ea
(mh-insert-signature): Use force-mode-line-update.
Karl Heuer <kwzh@gnu.org>
parents:
11507
diff
changeset
|
806 (force-mode-line-update)) |
6365 | 807 |
808 | |
809 (defun mh-check-whom () | |
11332 | 810 "Verify recipients of the current letter, showing expansion of any aliases." |
6365 | 811 (interactive) |
11332 | 812 (let ((file-name buffer-file-name)) |
6365 | 813 (save-buffer) |
814 (message "Checking recipients...") | |
815 (mh-in-show-buffer ("*Recipients*") | |
816 (bury-buffer (current-buffer)) | |
817 (erase-buffer) | |
818 (mh-exec-cmd-output "whom" t file-name)) | |
819 (message "Checking recipients...done"))) | |
820 | |
821 | |
822 | |
823 ;;; Routines to compose and send a letter. | |
824 | |
825 (defun mh-compose-and-send-mail (draft send-args | |
826 sent-from-folder sent-from-msg | |
827 to subject cc | |
828 annotate-char annotate-field | |
829 config) | |
830 ;; Edit and compose a draft message in buffer DRAFT and send or save it. | |
831 ;; SENT-FROM-FOLDER is buffer containing scan listing of current folder, or | |
832 ;; nil if none exists. | |
833 ;; SENT-FROM-MSG is the message number or sequence name or nil. | |
834 ;; SEND-ARGS is an optional argument passed to the send command. | |
835 ;; The TO, SUBJECT, and CC fields are passed to the | |
836 ;; mh-compose-letter-function. | |
837 ;; If ANNOTATE-CHAR is non-null, it is used to notate the scan listing of the | |
838 ;; message. In that case, the ANNOTATE-FIELD is used to build a string | |
839 ;; for mh-annotate-msg. | |
840 ;; CONFIG is the window configuration to restore after sending the letter. | |
841 (pop-to-buffer draft) | |
842 (mh-letter-mode) | |
843 (setq mh-sent-from-folder sent-from-folder) | |
844 (setq mh-sent-from-msg sent-from-msg) | |
845 (setq mh-send-args send-args) | |
846 (setq mh-annotate-char annotate-char) | |
847 (setq mh-annotate-field annotate-field) | |
848 (setq mh-previous-window-config config) | |
849 (setq mode-line-buffer-identification (list "{%b}")) | |
850 (if (and (boundp 'mh-compose-letter-function) | |
11332 | 851 mh-compose-letter-function) |
6365 | 852 ;; run-hooks will not pass arguments. |
11332 | 853 (let ((value mh-compose-letter-function)) |
6365 | 854 (if (and (listp value) (not (eq (car value) 'lambda))) |
855 (while value | |
856 (funcall (car value) to subject cc) | |
857 (setq value (cdr value))) | |
858 (funcall mh-compose-letter-function to subject cc))))) | |
859 | |
860 | |
861 (defun mh-send-letter (&optional arg) | |
862 "Send the draft letter in the current buffer. | |
863 If optional prefix argument is provided, monitor delivery. | |
19936 | 864 Run `mh-before-send-letter-hook' before actually doing anything." |
6365 | 865 (interactive "P") |
866 (run-hooks 'mh-before-send-letter-hook) | |
867 (save-buffer) | |
868 (message "Sending...") | |
869 (let ((draft-buffer (current-buffer)) | |
11332 | 870 (file-name buffer-file-name) |
19936 | 871 (config mh-previous-window-config) |
872 (coding-system-for-write | |
19952 | 873 (if (and (local-variable-p 'buffer-file-coding-system) |
874 ;; We're not sure why, but buffer-file-coding-system | |
875 ;; tends to get set to undecided-unix. | |
876 (not (memq buffer-file-coding-system | |
877 '(undecided undecided-unix undecided-dos)))) | |
19936 | 878 buffer-file-coding-system |
879 (or sendmail-coding-system | |
880 default-buffer-file-coding-system | |
881 'iso-latin-1)))) | |
6365 | 882 (cond (arg |
883 (pop-to-buffer "MH mail delivery") | |
884 (erase-buffer) | |
885 (mh-exec-cmd-output mh-send-prog t "-watch" "-nopush" | |
886 "-nodraftfolder" mh-send-args file-name) | |
887 (goto-char (point-max)) ; show the interesting part | |
888 (recenter -1) | |
889 (set-buffer draft-buffer)) ; for annotation below | |
890 (t | |
891 (mh-exec-cmd-daemon mh-send-prog "-nodraftfolder" "-noverbose" | |
892 mh-send-args file-name))) | |
893 (if mh-annotate-char | |
894 (mh-annotate-msg mh-sent-from-msg | |
895 mh-sent-from-folder | |
896 mh-annotate-char | |
897 "-component" mh-annotate-field | |
898 "-text" (format "\"%s %s\"" | |
11332 | 899 (mh-get-header-field "To:") |
900 (mh-get-header-field "Cc:")))) | |
6365 | 901 |
902 (cond ((or (not arg) | |
903 (y-or-n-p "Kill draft buffer? ")) | |
904 (kill-buffer draft-buffer) | |
905 (if config | |
906 (set-window-configuration config)))) | |
907 (if arg | |
908 (message "Sending...done") | |
909 (message "Sending...backgrounded")))) | |
910 | |
911 | |
11332 | 912 (defun mh-insert-letter (folder message verbatim) |
913 "Insert a message into the current letter. | |
19936 | 914 Removes the message's headers using `mh-invisible-headers'. Prefixes |
915 each non-blank line with `mh-ins-buf-prefix'. Prompts for FOLDER and | |
11332 | 916 MESSAGE. If prefix argument VERBATIM provided, do not indent and do |
917 not delete headers. Leaves the mark before the letter and point after it." | |
6365 | 918 (interactive |
11332 | 919 (list (mh-prompt-for-folder "Message from" mh-sent-from-folder nil) |
920 (read-input (format "Message number%s: " | |
6365 | 921 (if mh-sent-from-msg |
922 (format " [%d]" mh-sent-from-msg) | |
11332 | 923 ""))) |
6365 | 924 current-prefix-arg)) |
925 (save-restriction | |
926 (narrow-to-region (point) (point)) | |
927 (let ((start (point-min))) | |
11332 | 928 (if (equal message "") (setq message (int-to-string mh-sent-from-msg))) |
6365 | 929 (mh-exec-lib-cmd-output "mhl" "-nobell" "-noclear" |
11332 | 930 (expand-file-name message |
6365 | 931 (mh-expand-file-name folder))) |
11332 | 932 (cond ((not verbatim) |
6365 | 933 (mh-clean-msg-header start mh-invisible-headers mh-visible-headers) |
934 (set-mark start) ; since mh-clean-msg-header moves it | |
935 (mh-insert-prefix-string mh-ins-buf-prefix)))))) | |
936 | |
937 | |
938 (defun mh-yank-cur-msg () | |
939 "Insert the current message into the draft buffer. | |
940 Prefix each non-blank line in the message with the string in | |
941 `mh-ins-buf-prefix'. If a region is set in the message's buffer, then | |
942 only the region will be inserted. Otherwise, the entire message will | |
943 be inserted if `mh-yank-from-start-of-msg' is non-nil. If this variable | |
944 is nil, the portion of the message following the point will be yanked. | |
945 If `mh-delete-yanked-msg-window' is non-nil, any window displaying the | |
946 yanked message will be deleted." | |
947 (interactive) | |
948 (if (and mh-sent-from-folder mh-sent-from-msg) | |
949 (let ((to-point (point)) | |
950 (to-buffer (current-buffer))) | |
951 (set-buffer mh-sent-from-folder) | |
952 (if mh-delete-yanked-msg-window | |
953 (delete-windows-on mh-show-buffer)) | |
954 (set-buffer mh-show-buffer) ; Find displayed message | |
955 (let ((mh-ins-str (cond ((if (boundp 'mark-active) | |
11332 | 956 mark-active ;Emacs 19 |
957 (mark)) ;Emacs 18 | |
6365 | 958 (buffer-substring (region-beginning) |
959 (region-end))) | |
960 ((eq 'body mh-yank-from-start-of-msg) | |
961 (buffer-substring | |
962 (save-excursion | |
963 (goto-char (point-min)) | |
964 (mh-goto-header-end 1) | |
965 (point)) | |
966 (point-max))) | |
967 (mh-yank-from-start-of-msg | |
968 (buffer-substring (point-min) (point-max))) | |
969 (t | |
970 (buffer-substring (point) (point-max)))))) | |
971 (set-buffer to-buffer) | |
11332 | 972 (save-restriction |
973 (narrow-to-region to-point to-point) | |
974 (push-mark) | |
975 (insert mh-ins-str) | |
976 (mh-insert-prefix-string mh-ins-buf-prefix) | |
977 (insert "\n")))) | |
978 (error "There is no current message"))) | |
6365 | 979 |
980 | |
981 (defun mh-insert-prefix-string (mh-ins-string) | |
11332 | 982 ;; Run mail-citation-hook to insert a prefix string before each line |
6365 | 983 ;; in the buffer. Generality for supercite users. |
11332 | 984 (set-mark (point-max)) |
985 (goto-char (point-min)) | |
986 (cond (mail-citation-hook | |
987 (run-hooks 'mail-citation-hook)) | |
988 (mh-yank-hooks ;old hook name | |
989 (run-hooks 'mh-yank-hooks)) | |
990 (t | |
991 (or (bolp) (forward-line 1)) | |
992 (let ((zmacs-regions nil)) ;so "(mark)" works in XEmacs | |
6365 | 993 (while (< (point) (mark)) |
994 (insert mh-ins-string) | |
995 (forward-line 1)))))) | |
996 | |
997 | |
998 (defun mh-fully-kill-draft () | |
999 "Kill the draft message file and the draft message buffer. | |
1000 Use \\[kill-buffer] if you don't want to delete the draft message file." | |
1001 (interactive) | |
1002 (if (y-or-n-p "Kill draft message? ") | |
1003 (let ((config mh-previous-window-config)) | |
11332 | 1004 (if (file-exists-p buffer-file-name) |
1005 (delete-file buffer-file-name)) | |
6365 | 1006 (set-buffer-modified-p nil) |
1007 (kill-buffer (buffer-name)) | |
1008 (message "") | |
1009 (if config | |
1010 (set-window-configuration config))) | |
1011 (error "Message not killed"))) | |
1012 | |
11332 | 1013 |
6365 | 1014 ;;; Build the letter-mode keymap: |
1015 | |
1016 (define-key mh-letter-mode-map "\C-c\C-f\C-b" 'mh-to-field) | |
1017 (define-key mh-letter-mode-map "\C-c\C-f\C-c" 'mh-to-field) | |
11332 | 1018 (define-key mh-letter-mode-map "\C-c\C-f\C-d" 'mh-to-field) |
6365 | 1019 (define-key mh-letter-mode-map "\C-c\C-f\C-f" 'mh-to-fcc) |
11332 | 1020 (define-key mh-letter-mode-map "\C-c\C-f\C-r" 'mh-to-field) |
6365 | 1021 (define-key mh-letter-mode-map "\C-c\C-f\C-s" 'mh-to-field) |
1022 (define-key mh-letter-mode-map "\C-c\C-f\C-t" 'mh-to-field) | |
1023 (define-key mh-letter-mode-map "\C-c\C-fb" 'mh-to-field) | |
1024 (define-key mh-letter-mode-map "\C-c\C-fc" 'mh-to-field) | |
11332 | 1025 (define-key mh-letter-mode-map "\C-c\C-fd" 'mh-to-field) |
6365 | 1026 (define-key mh-letter-mode-map "\C-c\C-ff" 'mh-to-fcc) |
11332 | 1027 (define-key mh-letter-mode-map "\C-c\C-fr" 'mh-to-field) |
6365 | 1028 (define-key mh-letter-mode-map "\C-c\C-fs" 'mh-to-field) |
1029 (define-key mh-letter-mode-map "\C-c\C-ft" 'mh-to-field) | |
11332 | 1030 (define-key mh-letter-mode-map "\C-c\C-i" 'mh-insert-letter) |
6365 | 1031 (define-key mh-letter-mode-map "\C-c\C-q" 'mh-fully-kill-draft) |
11332 | 1032 (define-key mh-letter-mode-map "\C-c\C-\\" 'mh-fully-kill-draft) ;if no C-q |
1033 (define-key mh-letter-mode-map "\C-c\C-s" 'mh-insert-signature) | |
1034 (define-key mh-letter-mode-map "\C-c\C-^" 'mh-insert-signature) ;if no C-s | |
6365 | 1035 (define-key mh-letter-mode-map "\C-c\C-w" 'mh-check-whom) |
1036 (define-key mh-letter-mode-map "\C-c\C-y" 'mh-yank-cur-msg) | |
1037 (define-key mh-letter-mode-map "\C-c\C-c" 'mh-send-letter) | |
1038 (define-key mh-letter-mode-map "\C-c\C-m\C-f" 'mh-mhn-compose-forw) | |
1039 (define-key mh-letter-mode-map "\C-c\C-m\C-e" 'mh-mhn-compose-anon-ftp) | |
1040 (define-key mh-letter-mode-map "\C-c\C-m\C-t" 'mh-mhn-compose-external-compressed-tar) | |
1041 (define-key mh-letter-mode-map "\C-c\C-m\C-i" 'mh-mhn-compose-insertion) | |
1042 (define-key mh-letter-mode-map "\C-c\C-e" 'mh-edit-mhn) | |
1043 (define-key mh-letter-mode-map "\C-c\C-m\C-u" 'mh-revert-mhn-edit) | |
1044 | |
13385 | 1045 ;; "C-c /" prefix is used in mh-letter-mode by pgp.el |
6365 | 1046 |
1047 ;;; autoloads from mh-mime | |
1048 | |
1049 (autoload 'mh-mhn-compose-insertion "mh-mime" | |
11507 | 1050 "Add a directive to insert a MIME message part from a file. |
11332 | 1051 This is the typical way to insert non-text parts in a message. |
1052 See also \\[mh-edit-mhn]." t) | |
1053 | |
6365 | 1054 (autoload 'mh-mhn-compose-anon-ftp "mh-mime" |
11507 | 1055 "Add a directive for a MIME anonymous ftp external body part. |
11332 | 1056 This directive tells MH to include a reference to a |
1057 message/external-body part retrievable by anonymous FTP. | |
1058 See also \\[mh-edit-mhn]." t) | |
1059 | |
6365 | 1060 (autoload 'mh-mhn-compose-external-compressed-tar "mh-mime" |
11507 | 1061 "Add a directive to include a MIME reference to a compressed tar file. |
11332 | 1062 The file should be available via anonymous ftp. This directive |
1063 tells MH to include a reference to a message/external-body part. | |
1064 See also \\[mh-edit-mhn]." t) | |
1065 | |
6365 | 1066 (autoload 'mh-mhn-compose-forw "mh-mime" |
11507 | 1067 "Add a forw directive to this message, to forward a message with MIME. |
11332 | 1068 This directive tells MH to include another message in this one. |
1069 See also \\[mh-edit-mhn]." t) | |
1070 | |
6365 | 1071 (autoload 'mh-edit-mhn "mh-mime" |
11332 | 1072 "Format the current draft for MIME, expanding any mhn directives. |
1073 Process the current draft with the mhn program, which, | |
1074 using directives already inserted in the draft, fills in | |
6365 | 1075 all the MIME components and header fields. |
1076 This step should be done last just before sending the message. | |
1077 The mhn program is part of MH version 6.8 or later. | |
19936 | 1078 The \\[mh-revert-mhn-edit] command undoes this command. |
11332 | 1079 For assistance with creating mhn directives to insert |
6365 | 1080 various types of components in a message, see |
1081 \\[mh-mhn-compose-insertion] (generic insertion from a file), | |
1082 \\[mh-mhn-compose-anon-ftp] (external reference to file via anonymous ftp), | |
1083 \\[mh-mhn-compose-external-compressed-tar] \ | |
1084 \(reference to compressed tar file via anonymous ftp), and | |
1085 \\[mh-mhn-compose-forw] (forward message)." t) | |
1086 | |
1087 (autoload 'mh-revert-mhn-edit "mh-mime" | |
11332 | 1088 "Undoes the effect of \\[mh-edit-mhn] by reverting to the backup file. |
1089 Optional non-nil argument means don't ask for confirmation." t) |