]> code.delx.au - gnu-emacs/blob - lisp/mh-e/mh-comp.el
Merge from emacs-24; up to 2012-12-06T01:39:03Z!monnier@iro.umontreal.ca
[gnu-emacs] / lisp / mh-e / mh-comp.el
1 ;;; mh-comp.el --- MH-E functions for composing and sending messages
2
3 ;; Copyright (C) 1993, 1995, 1997, 2000-2013 Free Software Foundation,
4 ;; Inc.
5
6 ;; Author: Bill Wohler <wohler@newt.com>
7 ;; Maintainer: Bill Wohler <wohler@newt.com>
8 ;; Keywords: mail
9 ;; See: mh-e.el
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25
26 ;;; Commentary:
27
28 ;; This file includes the functions in the MH-Folder maps that get us
29 ;; into MH-Letter mode, as well the functions in the MH-Letter mode
30 ;; that are used to send the mail. Other that those, functions that
31 ;; are needed in mh-letter.el should be found there.
32
33 ;;; Change Log:
34
35 ;;; Code:
36
37 (require 'mh-e)
38 (require 'mh-gnus) ;needed because mh-gnus.el not compiled
39 (require 'mh-scan)
40
41 (require 'sendmail)
42
43 (autoload 'easy-menu-add "easymenu")
44 (autoload 'mml-insert-tag "mml")
45
46 \f
47
48 ;;; Site Customization
49
50 (defvar mh-send-prog "send"
51 "Name of the MH send program.
52 Some sites need to change this because of a name conflict.")
53
54 (defvar mh-send-uses-spost-flag nil
55 "Non-nil means \"send\" uses \"spost\" to submit messages.
56
57 If the value of \"postproc:\" is \"spost\", you may need to set
58 this variable to t to tell MH-E to avoid using features of
59 \"post\" that are not supported by \"spost\". You'll know that
60 you'll need to do this if sending mail fails with an error of
61 \"spost: -msgid unknown\".")
62
63 (defvar mh-redist-background nil
64 "If non-nil redist will be done in background like send.
65 This allows transaction log to be visible if -watch, -verbose or
66 -snoop are used.")
67
68 \f
69
70 ;;; Variables
71
72 (defvar mh-comp-formfile "components"
73 "Name of file to be used as a skeleton for composing messages.
74
75 Default is \"components\".
76
77 If not an absolute file name, the file is searched for first in the
78 user's MH directory, then in the system MH lib directory.")
79
80 (defvar mh-repl-formfile "replcomps"
81 "Name of file to be used as a skeleton for replying to messages.
82
83 Default is \"replcomps\".
84
85 If not an absolute file name, the file is searched for first in the
86 user's MH directory, then in the system MH lib directory.")
87
88 (defvar mh-repl-group-formfile "replgroupcomps"
89 "Name of file to be used as a skeleton for replying to messages.
90
91 Default is \"replgroupcomps\".
92
93 This file is used to form replies to the sender and all recipients of
94 a message. Only used if `(mh-variant-p 'nmh)' is non-nil.
95 If not an absolute file name, the file is searched for first in the
96 user's MH directory, then in the system MH lib directory.")
97
98 (defvar mh-rejected-letter-start
99 (format "^%s$"
100 (regexp-opt
101 '("Content-Type: message/rfc822" ;MIME MDN
102 "------ This is a copy of the message, including all the headers. ------";from exim
103 "--- Below this line is a copy of the message."; from qmail
104 " ----- Unsent message follows -----" ;from sendmail V5
105 " --------Unsent Message below:" ; from sendmail at BU
106 " ----- Original message follows -----" ;from sendmail V8
107 "------- Unsent Draft" ;from MH itself
108 "---------- Original Message ----------" ;from zmailer
109 " --- The unsent message follows ---" ;from AIX mail system
110 " Your message follows:" ;from MMDF-II
111 "Content-Description: Returned Content" ;1993 KJ sendmail
112 ))))
113
114 (defvar mh-new-draft-cleaned-headers
115 "^Date:\\|^Received:\\|^Message-Id:\\|^From:\\|^Sender:\\|^Errors-To:\\|^Delivery-Date:\\|^Return-Path:"
116 "Regexp of header lines to remove before offering a message as a new draft\\<mh-folder-mode-map>.
117 Used by the \\[mh-edit-again] and \\[mh-extract-rejected-mail] commands.")
118
119 (defvar mh-letter-mode-syntax-table
120 (let ((syntax-table (make-syntax-table text-mode-syntax-table)))
121 (modify-syntax-entry ?% "." syntax-table)
122 syntax-table)
123 "Syntax table used by MH-E while in MH-Letter mode.")
124
125 (defvar mh-regexp-in-field-syntax-table nil
126 "Specify a syntax table for `mh-regexp-in-field-p' to use.")
127
128 (defvar mh-fcc-syntax-table
129 (let ((syntax-table (make-syntax-table text-mode-syntax-table)))
130 (modify-syntax-entry ?+ "w" syntax-table)
131 (modify-syntax-entry ?/ "w" syntax-table)
132 syntax-table)
133 "Syntax table used by MH-E while searching an Fcc field.")
134
135 (defvar mh-addr-syntax-table
136 (let ((syntax-table (make-syntax-table text-mode-syntax-table)))
137 (modify-syntax-entry ?! "w" syntax-table)
138 (modify-syntax-entry ?# "w" syntax-table)
139 (modify-syntax-entry ?$ "w" syntax-table)
140 (modify-syntax-entry ?% "w" syntax-table)
141 (modify-syntax-entry ?& "w" syntax-table)
142 (modify-syntax-entry ?' "w" syntax-table)
143 (modify-syntax-entry ?* "w" syntax-table)
144 (modify-syntax-entry ?+ "w" syntax-table)
145 (modify-syntax-entry ?- "w" syntax-table)
146 (modify-syntax-entry ?/ "w" syntax-table)
147 (modify-syntax-entry ?= "w" syntax-table)
148 (modify-syntax-entry ?? "w" syntax-table)
149 (modify-syntax-entry ?^ "w" syntax-table)
150 (modify-syntax-entry ?_ "w" syntax-table)
151 (modify-syntax-entry ?` "w" syntax-table)
152 (modify-syntax-entry ?{ "w" syntax-table)
153 (modify-syntax-entry ?| "w" syntax-table)
154 (modify-syntax-entry ?} "w" syntax-table)
155 (modify-syntax-entry ?~ "w" syntax-table)
156 (modify-syntax-entry ?. "w" syntax-table)
157 (modify-syntax-entry ?@ "w" syntax-table)
158 syntax-table)
159 "Syntax table used by MH-E while searching an address field.")
160
161 (defvar mh-send-args ""
162 "Extra args to pass to \"send\" command.")
163
164 (defvar mh-annotate-char nil
165 "Character to use to annotate `mh-sent-from-msg'.")
166
167 (defvar mh-annotate-field nil
168 "Field name for message annotation.")
169
170 (defvar mh-annotate-list nil
171 "Messages annotated, either a sequence name or a list of message numbers.
172 This variable can be used by `mh-annotate-msg-hook'.")
173
174 (defvar mh-insert-auto-fields-done-local nil
175 "Buffer-local variable set when `mh-insert-auto-fields' called successfully.")
176 (make-variable-buffer-local 'mh-insert-auto-fields-done-local)
177
178 \f
179
180 ;;; MH-E Entry Points
181
182 ;;;###autoload
183 (defun mh-smail ()
184 "Compose a message with the MH mail system.
185 See `mh-send' for more details on composing mail."
186 (interactive)
187 (mh-find-path)
188 (call-interactively 'mh-send))
189
190 ;;;###autoload
191 (defun mh-smail-other-window ()
192 "Compose a message with the MH mail system in other window.
193 See `mh-send' for more details on composing mail."
194 (interactive)
195 (mh-find-path)
196 (call-interactively 'mh-send-other-window))
197
198 (defun mh-send-other-window (to cc subject)
199 "Compose a message in another window.
200
201 See `mh-send' for more information and a description of how the
202 TO, CC, and SUBJECT arguments are used."
203 (interactive (list
204 (mh-interactive-read-address "To: ")
205 (mh-interactive-read-address "Cc: ")
206 (mh-interactive-read-string "Subject: ")))
207 (let ((pop-up-windows t))
208 (mh-send-sub to cc subject (current-window-configuration))))
209
210 (defvar mh-error-if-no-draft nil) ;raise error over using old draft
211
212 ;;;###autoload
213 (defun mh-smail-batch (&optional to subject other-headers &rest ignored)
214 "Compose a message with the MH mail system.
215
216 This function does not prompt the user for any header fields, and
217 thus is suitable for use by programs that want to create a mail
218 buffer. Users should use \\[mh-smail] to compose mail.
219
220 Optional arguments for setting certain fields include TO,
221 SUBJECT, and OTHER-HEADERS. Additional arguments are IGNORED.
222
223 This function remains for Emacs 21 compatibility. New
224 applications should use `mh-user-agent-compose'."
225 (mh-find-path)
226 (let ((mh-error-if-no-draft t))
227 (mh-send (or to "") "" (or subject ""))))
228
229 ;;;###autoload
230 (define-mail-user-agent 'mh-e-user-agent
231 'mh-user-agent-compose 'mh-send-letter 'mh-fully-kill-draft
232 'mh-before-send-letter-hook)
233
234 ;;;###autoload
235 (defun mh-user-agent-compose (&optional to subject other-headers continue
236 switch-function yank-action
237 send-actions return-action
238 &rest ignored)
239 "Set up mail composition draft with the MH mail system.
240 This is the `mail-user-agent' entry point to MH-E. This function
241 conforms to the contract specified by `define-mail-user-agent'
242 which means that this function should accept the same arguments
243 as `compose-mail'.
244
245 The optional arguments TO and SUBJECT specify recipients and the
246 initial Subject field, respectively.
247
248 OTHER-HEADERS is an alist specifying additional header fields.
249 Elements look like (HEADER . VALUE) where both HEADER and VALUE
250 are strings.
251
252 CONTINUE, SWITCH-FUNCTION, YANK-ACTION, SEND-ACTIONS, and
253 RETURN-ACTION and any additional arguments are IGNORED."
254 (mh-find-path)
255 (let ((mh-error-if-no-draft t))
256 (mh-send to "" subject)
257 (while other-headers
258 (mh-insert-fields (concat (car (car other-headers)) ":")
259 (cdr (car other-headers)))
260 (setq other-headers (cdr other-headers)))))
261
262 ;; Shush compiler.
263 (mh-do-in-xemacs
264 (defvar sendmail-coding-system))
265
266 ;;;###autoload
267 (defun mh-send-letter (&optional arg)
268 "Save draft and send message.
269
270 When you are all through editing a message, you send it with this
271 command. You can give a prefix argument ARG to monitor the first stage
272 of the delivery\; this output can be found in a buffer called \"*MH-E
273 Mail Delivery*\".
274
275 The hook `mh-before-send-letter-hook' is run at the beginning of
276 this command. For example, if you want to check your spelling in
277 your message before sending, add the function `ispell-message'.
278
279 Unless `mh-insert-auto-fields' had previously been called
280 manually, the function `mh-insert-auto-fields' is called to
281 insert fields based upon the recipients. If fields are added, you
282 are given a chance to see and to confirm these fields before the
283 message is actually sent. You can do away with this confirmation
284 by turning off the option `mh-auto-fields-prompt-flag'.
285
286 In case the MH \"send\" program is installed under a different name,
287 use `mh-send-prog' to tell MH-E the name.
288
289 The hook `mh-annotate-msg-hook' is run after annotating the
290 message and scan line."
291 (interactive "P")
292 (run-hooks 'mh-before-send-letter-hook)
293 (if (and (mh-insert-auto-fields t)
294 mh-auto-fields-prompt-flag
295 (goto-char (point-min)))
296 (if (not (y-or-n-p "Auto fields inserted, send? "))
297 (error "Send aborted")))
298 (cond ((mh-mh-directive-present-p)
299 (mh-mh-to-mime))
300 ((or (mh-mml-tag-present-p) (not (mh-ascii-buffer-p)))
301 (mh-mml-to-mime)))
302 (save-buffer)
303 (message "Sending...")
304 (let ((draft-buffer (current-buffer))
305 (file-name buffer-file-name)
306 (config mh-previous-window-config)
307 (coding-system-for-write
308 (if (and (local-variable-p 'buffer-file-coding-system
309 (current-buffer)) ;XEmacs needs two args
310 ;; We're not sure why, but buffer-file-coding-system
311 ;; tends to get set to undecided-unix.
312 (not (memq buffer-file-coding-system
313 '(undecided undecided-unix undecided-dos))))
314 buffer-file-coding-system
315 (or (and (boundp 'sendmail-coding-system) sendmail-coding-system)
316 (and (default-boundp 'buffer-file-coding-system)
317 (default-value 'buffer-file-coding-system))
318 'iso-latin-1))))
319 ;; Older versions of spost do not support -msgid and -mime.
320 (unless mh-send-uses-spost-flag
321 ;; Adding a Message-ID field looks good, makes it easier to search for
322 ;; message in your +outbox, and best of all doesn't break threading for
323 ;; the recipient if you reply to a message in your +outbox.
324 (setq mh-send-args (concat "-msgid " mh-send-args))
325 ;; The default BCC encapsulation will make a MIME message unreadable.
326 ;; With nmh use the -mime arg to prevent this.
327 (if (and (mh-variant-p 'nmh)
328 (mh-goto-header-field "Bcc:")
329 (mh-goto-header-field "Content-Type:"))
330 (setq mh-send-args (concat "-mime " mh-send-args))))
331 (cond (arg
332 (pop-to-buffer mh-mail-delivery-buffer)
333 (erase-buffer)
334 (mh-exec-cmd-output mh-send-prog t
335 "-nodraftfolder" "-watch" "-nopush"
336 (split-string mh-send-args) file-name)
337 (goto-char (point-max)) ; show the interesting part
338 (recenter -1)
339 (set-buffer draft-buffer)) ; for annotation below
340 (t
341 (mh-exec-cmd-daemon mh-send-prog nil
342 "-nodraftfolder" "-noverbose"
343 (split-string mh-send-args) file-name)))
344 (if mh-annotate-char
345 (mh-annotate-msg mh-sent-from-msg
346 mh-sent-from-folder
347 mh-annotate-char
348 "-component" mh-annotate-field
349 "-text" (format "\"%s %s\""
350 (mh-get-header-field "To:")
351 (mh-get-header-field "Cc:"))))
352
353 (cond ((or (not arg)
354 (y-or-n-p "Kill draft buffer? "))
355 (kill-buffer draft-buffer)
356 (if config
357 (set-window-configuration config))))
358 (if arg
359 (message "Sending...done")
360 (message "Sending...backgrounded"))))
361
362 ;;;###autoload
363 (defun mh-fully-kill-draft ()
364 "Quit editing and delete draft message.
365
366 If for some reason you are not happy with the draft, you can use
367 this command to kill the draft buffer and delete the draft
368 message. Use the command \\[kill-buffer] if you don't want to
369 delete the draft message."
370 (interactive)
371 (if (y-or-n-p "Kill draft message? ")
372 (let ((config mh-previous-window-config))
373 (if (file-exists-p buffer-file-name)
374 (delete-file buffer-file-name))
375 (set-buffer-modified-p nil)
376 (kill-buffer (buffer-name))
377 (message "")
378 (if config
379 (set-window-configuration config)))
380 (error "Message not killed")))
381
382 \f
383
384 ;;; MH-Folder Commands
385
386 ;; Alphabetical.
387
388 ;;;###mh-autoload
389 (defun mh-edit-again (message)
390 "Edit a MESSAGE to send it again.
391
392 If you don't complete a draft for one reason or another, and if
393 the draft buffer is no longer available, you can pick your draft
394 up again with this command. If you don't use a draft folder, your
395 last \"draft\" file will be used. If you use draft folders,
396 you'll need to visit the draft folder with \"\\[mh-visit-folder]
397 drafts <RET>\", use \\[mh-next-undeleted-msg] to move to the
398 appropriate message, and then use \\[mh-edit-again] to prepare
399 the message for editing.
400
401 This command can also be used to take messages that were sent to
402 you and to send them to more people.
403
404 Don't use this command to re-edit a message from a Mailer-Daemon
405 who complained that your mail wasn't posted for some reason or
406 another (see `mh-extract-rejected-mail').
407
408 The default message is the current message.
409
410 See also `mh-send'."
411 (interactive (list (mh-get-msg-num t)))
412 (let* ((from-folder mh-current-folder)
413 (config (current-window-configuration))
414 (draft
415 (cond ((and mh-draft-folder (equal from-folder mh-draft-folder))
416 (pop-to-buffer (find-file-noselect (mh-msg-filename message))
417 t)
418 (rename-buffer (format "draft-%d" message))
419 ;; Make buffer writable...
420 (setq buffer-read-only nil)
421 ;; If buffer was being used to display the message reinsert
422 ;; from file...
423 (when (eq major-mode 'mh-show-mode)
424 (erase-buffer)
425 (insert-file-contents buffer-file-name))
426 (buffer-name))
427 (t
428 (mh-read-draft "clean-up" (mh-msg-filename message) nil)))))
429 (mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil)
430 (mh-insert-header-separator)
431 ;; Merge in components
432 (mh-mapc
433 (function
434 (lambda (header-field)
435 (let ((field (car header-field))
436 (value (cdr header-field))
437 (case-fold-search t))
438 (cond
439 ;; Address field
440 ((string-match field "^To$\\|^Cc$\\|^From$")
441 (cond
442 ((not (mh-goto-header-field (concat field ":")))
443 ;; Header field does not exist, add it
444 (mh-goto-header-end 0)
445 (insert field ": " value "\n"))
446 ((string-equal value "")
447 ;; Header field already exists and no value
448 )
449 (t
450 ;; Header field exists and we have a value
451 (let (address mailbox (alias (mh-alias-expand value)))
452 (and alias
453 (setq address (ietf-drums-parse-address alias))
454 (setq mailbox (car address)))
455 ;; XXX - Need to parse all addresses out of field
456 (if (and
457 (not (mh-regexp-in-field-p
458 (concat "\\b" (regexp-quote value) "\\b") field))
459 mailbox
460 (not (mh-regexp-in-field-p
461 (concat "\\b" (regexp-quote mailbox) "\\b") field)))
462 (insert " " value ","))
463 ))))
464 ((string-match field "^Fcc$")
465 ;; Folder reference
466 (mh-modify-header-field field value))
467 ;; Text field, that's an easy case
468 (t
469 (mh-modify-header-field field value))))))
470 (mh-components-to-list (mh-find-components)))
471 (goto-char (point-min))
472 (save-buffer)
473 (mh-compose-and-send-mail
474 draft "" from-folder nil nil nil nil nil nil config)
475 (mh-letter-mode-message)
476 (mh-letter-adjust-point)))
477
478 (defun mh-extract-header-field ()
479 "Extract field name and field value from the field at point.
480 Returns a list of field name and value (which may be null)."
481 (let ((end (save-excursion (mh-header-field-end)
482 (point))))
483 (if (looking-at mh-letter-header-field-regexp)
484 (save-excursion
485 (goto-char (match-end 1))
486 (forward-char 1)
487 (skip-chars-forward " \t")
488 (cons (match-string-no-properties 1) (buffer-substring-no-properties (point) end))))))
489
490
491 (defun mh-components-to-list (components)
492 "Convert the COMPONENTS file to a list of field names and values."
493 (with-current-buffer (get-buffer-create mh-temp-buffer)
494 (erase-buffer)
495 (insert-file-contents components)
496 (goto-char (point-min))
497 (let
498 ((header-fields nil))
499 (while (mh-in-header-p)
500 (setq header-fields (append header-fields (list (mh-extract-header-field))))
501 (mh-header-field-end)
502 (forward-char 1)
503 )
504 header-fields)))
505
506 ;;;###mh-autoload
507 (defun mh-extract-rejected-mail (message)
508 "Edit a MESSAGE that was returned by the mail system.
509
510 This command prepares the message for editing by removing the
511 Mailer-Daemon envelope and unneeded header fields. Fix whatever
512 addressing problem you had, and send the message again with
513 \\[mh-send-letter].
514
515 The default message is the current message.
516
517 See also `mh-send'."
518 (interactive (list (mh-get-msg-num t)))
519 (let ((from-folder mh-current-folder)
520 (config (current-window-configuration))
521 (draft (mh-read-draft "extraction" (mh-msg-filename message) nil)))
522 (goto-char (point-min))
523 (cond ((re-search-forward mh-rejected-letter-start nil t)
524 (skip-chars-forward " \t\n")
525 (delete-region (point-min) (point))
526 (mh-clean-msg-header (point-min) mh-new-draft-cleaned-headers nil))
527 (t
528 (message "Does not appear to be a rejected letter")))
529 (mh-insert-header-separator)
530 (goto-char (point-min))
531 (save-buffer)
532 (mh-compose-and-send-mail draft "" from-folder message
533 (mh-get-header-field "To:")
534 (mh-get-header-field "From:")
535 (mh-get-header-field "Cc:")
536 nil nil config)
537 (mh-letter-mode-message)))
538
539 ;;;###mh-autoload
540 (defun mh-forward (to cc &optional range)
541 "Forward message.
542
543 You are prompted for the TO and CC recipients. You are given a
544 draft to edit that looks like it would if you had run the MH
545 command \"forw\". You can then add some text.
546
547 You can forward several messages by using a RANGE. All of the
548 messages in the range are inserted into your draft. Check the
549 documentation of `mh-interactive-range' to see how RANGE is read
550 in interactive use.
551
552 The hook `mh-forward-hook' is called on the draft.
553
554 See also `mh-compose-forward-as-mime-flag',
555 `mh-forward-subject-format', and `mh-send'."
556 (interactive (list (mh-interactive-read-address "To: ")
557 (mh-interactive-read-address "Cc: ")
558 (mh-interactive-range "Forward")))
559 (let* ((folder mh-current-folder)
560 (msgs (mh-range-to-msg-list range))
561 (config (current-window-configuration))
562 (fwd-msg-file (mh-msg-filename (car msgs) folder))
563 ;; forw always leaves file in "draft" since it doesn't have -draft
564 (draft-name (expand-file-name "draft" mh-user-path))
565 (draft (cond ((or (not (file-exists-p draft-name))
566 (y-or-n-p "The file draft exists; discard it? "))
567 (mh-exec-cmd "forw" "-build"
568 (if (and (mh-variant-p 'nmh)
569 mh-compose-forward-as-mime-flag)
570 "-mime")
571 mh-current-folder
572 (mh-coalesce-msg-list msgs))
573 (prog1
574 (mh-read-draft "" draft-name t)
575 (mh-insert-fields "To:" to "Cc:" cc)
576 (save-buffer)))
577 (t
578 (mh-read-draft "" draft-name nil)))))
579 (let (orig-from
580 orig-subject)
581 (with-current-buffer (get-buffer-create mh-temp-buffer)
582 (erase-buffer)
583 (insert-file-contents fwd-msg-file)
584 (setq orig-from (mh-get-header-field "From:"))
585 (setq orig-subject (mh-get-header-field "Subject:")))
586 (let ((forw-subject
587 (mh-forwarded-letter-subject orig-from orig-subject)))
588 (mh-insert-fields "Subject:" forw-subject)
589 (goto-char (point-min))
590 ;; If using MML, translate MH-style directive
591 (if (equal mh-compose-insertion 'mml)
592 (save-excursion
593 (goto-char (mh-mail-header-end))
594 (while
595 (re-search-forward
596 "^#forw \\[\\([^]]+\\)\\] \\(+\\S-+\\) \\(.*\\)$"
597 (point-max) t)
598 (let ((description (if (equal (match-string 1)
599 "forwarded messages")
600 "forwarded message %d"
601 (match-string 1)))
602 (msgs (split-string (match-string 3)))
603 (i 0))
604 (beginning-of-line)
605 (delete-region (point) (progn (forward-line 1) (point)))
606 (dolist (msg msgs)
607 (setq i (1+ i))
608 (mh-mml-forward-message (format description i)
609 folder msg)
610 ;; Was inserted before us, move to end of file to preserve order
611 (goto-char (point-max)))))))
612 ;; Position just before forwarded message.
613 (if (re-search-forward "^------- Forwarded Message" nil t)
614 (forward-line -1)
615 (goto-char (mh-mail-header-end))
616 (forward-line 1))
617 (delete-other-windows)
618 (mh-add-msgs-to-seq msgs 'forwarded t)
619 (mh-compose-and-send-mail draft "" folder msgs
620 to forw-subject cc
621 mh-note-forw "Forwarded:"
622 config)
623 (mh-letter-mode-message)
624 (mh-letter-adjust-point)
625 (run-hooks 'mh-forward-hook)))))
626
627 (defun mh-forwarded-letter-subject (from subject)
628 "Return a Subject suitable for a forwarded message.
629 Original message has headers FROM and SUBJECT."
630 (let ((addr-start (string-match "<" from))
631 (comment (string-match "(" from)))
632 (cond ((and addr-start (> addr-start 0))
633 ;; Full Name <luser@host>
634 (setq from (substring from 0 (1- addr-start))))
635 (comment
636 ;; luser@host (Full Name)
637 (setq from (substring from (1+ comment) (1- (length from)))))))
638 (format mh-forward-subject-format from subject))
639
640 ;;;###mh-autoload
641 (defun mh-redistribute (to cc &optional message)
642 "Redistribute a message.
643
644 This command is similar in function to forwarding mail, but it
645 does not allow you to edit the message, nor does it add your name
646 to the \"From\" header field. It appears to the recipient as if
647 the message had come from the original sender. When you run this
648 command, you are prompted for the TO and CC recipients. The
649 default MESSAGE is the current message.
650
651 Also investigate the command \\[mh-edit-again] for another way to
652 redistribute messages.
653
654 See also `mh-redist-full-contents-flag'.
655
656 The hook `mh-annotate-msg-hook' is run after annotating the
657 message and scan line."
658 (interactive (list (mh-read-address "Redist-To: ")
659 (mh-read-address "Redist-Cc: ")
660 (mh-get-msg-num t)))
661 (or message
662 (setq message (mh-get-msg-num t)))
663 (save-window-excursion
664 (let ((folder mh-current-folder)
665 (draft (mh-read-draft "redistribution"
666 (if mh-redist-full-contents-flag
667 (mh-msg-filename message)
668 nil)
669 nil)))
670 (mh-goto-header-end 0)
671 (insert "Resent-To: " to "\n")
672 (if (not (equal cc "")) (insert "Resent-cc: " cc "\n"))
673 (mh-clean-msg-header
674 (point-min)
675 "^Message-Id:\\|^Received:\\|^Return-Path:\\|^Sender:\\|^Date:\\|^From:"
676 nil)
677 (save-buffer)
678 (message "Redistributing...")
679 (let ((env "mhdist=1"))
680 ;; Setup environment...
681 (setq env (concat env " mhaltmsg="
682 (if mh-redist-full-contents-flag
683 buffer-file-name
684 (mh-msg-filename message folder))))
685 (unless mh-redist-full-contents-flag
686 (setq env (concat env " mhannotate=1")))
687 ;; Redistribute...
688 (if mh-redist-background
689 (mh-exec-cmd-env-daemon env mh-send-prog nil buffer-file-name)
690 (mh-exec-cmd-error env mh-send-prog "-push" buffer-file-name))
691 ;; Annotate...
692 (mh-annotate-msg message folder mh-note-dist
693 "-component" "Resent:"
694 "-text" (format "\"%s %s\"" to cc)))
695 (kill-buffer draft)
696 (message "Redistributing...done"))))
697
698 ;;;###mh-autoload
699 (defun mh-reply (message &optional reply-to includep)
700 "Reply to a MESSAGE.
701
702 When you reply to a message, you are first prompted with \"Reply
703 to whom?\" (unless the optional argument REPLY-TO is provided).
704 You have several choices here.
705
706 Response Reply Goes To
707
708 from The person who sent the message. This is the
709 default, so <RET> is sufficient.
710
711 to Replies to the sender, plus all recipients in the
712 \"To:\" header field.
713
714 all cc Forms a reply to the addresses in the
715 \"Mail-Followup-To:\" header field if one
716 exists; otherwise forms a reply to the sender,
717 plus all recipients.
718
719 Depending on your answer, \"repl\" is given a different argument
720 to form your reply. Specifically, a choice of \"from\" or none at
721 all runs \"repl -nocc all\", and a choice of \"to\" runs \"repl
722 -cc to\". Finally, either \"cc\" or \"all\" runs \"repl -cc all
723 -nocc me\".
724
725 Two windows are then created. One window contains the message to
726 which you are replying in an MH-Show buffer. Your draft, in
727 MH-Letter mode (*note `mh-letter-mode'), is in the other window.
728 If the reply draft was not one that you expected, check the
729 things that affect the behavior of \"repl\" which include the
730 \"repl:\" profile component and the \"replcomps\" and
731 \"replgroupcomps\" files.
732
733 If you supply a prefix argument INCLUDEP, the message you are
734 replying to is inserted in your reply after having first been run
735 through \"mhl\" with the format file \"mhl.reply\".
736
737 Alternatively, you can customize the option `mh-yank-behavior'
738 and choose one of its \"Automatically\" variants to do the same
739 thing. If you do so, the prefix argument has no effect.
740
741 Another way to include the message automatically in your draft is
742 to use \"repl: -filter repl.filter\" in your MH profile.
743
744 If you wish to customize the header or other parts of the reply
745 draft, please see \"repl\" and \"mh-format\".
746
747 See also `mh-reply-show-message-flag',
748 `mh-reply-default-reply-to', and `mh-send'."
749 (interactive (list
750 (mh-get-msg-num t)
751 (let ((minibuffer-help-form
752 "from => Sender only\nto => Sender and primary recipients\ncc or all => Sender and all recipients"))
753 (or mh-reply-default-reply-to
754 (completing-read "Reply to whom (default from): "
755 '(("from") ("to") ("cc") ("all"))
756 nil
757 t)))
758 current-prefix-arg))
759 (let* ((folder mh-current-folder)
760 (show-buffer mh-show-buffer)
761 (config (current-window-configuration))
762 (group-reply (or (equal reply-to "cc") (equal reply-to "all")))
763 (form-file (cond ((and (mh-variant-p 'nmh 'gnu-mh) group-reply
764 (stringp mh-repl-group-formfile))
765 mh-repl-group-formfile)
766 ((stringp mh-repl-formfile) mh-repl-formfile)
767 (t nil))))
768 (message "Composing a reply...")
769 (mh-exec-cmd "repl" "-build" "-noquery" "-nodraftfolder"
770 (if form-file
771 (list "-form" form-file))
772 mh-current-folder message
773 (cond ((or (equal reply-to "from") (equal reply-to ""))
774 '("-nocc" "all"))
775 ((equal reply-to "to")
776 '("-cc" "to"))
777 (group-reply (if (mh-variant-p 'nmh 'gnu-mh)
778 '("-group" "-nocc" "me")
779 '("-cc" "all" "-nocc" "me"))))
780 (cond ((or (eq mh-yank-behavior 'autosupercite)
781 (eq mh-yank-behavior 'autoattrib))
782 '("-noformat"))
783 (includep '("-filter" "mhl.reply"))
784 (t '())))
785 (let ((draft (mh-read-draft "reply"
786 (expand-file-name "reply" mh-user-path)
787 t)))
788 (delete-other-windows)
789 (save-buffer)
790
791 (let ((to (mh-get-header-field "To:"))
792 (subject (mh-get-header-field "Subject:"))
793 (cc (mh-get-header-field "Cc:")))
794 (goto-char (point-min))
795 (mh-goto-header-end 1)
796 (or includep
797 (not mh-reply-show-message-flag)
798 (mh-in-show-buffer (show-buffer)
799 (mh-display-msg message folder)))
800 (mh-add-msgs-to-seq message 'answered t)
801 (message "Composing a reply...done")
802 (mh-compose-and-send-mail draft "" folder message to subject cc
803 mh-note-repl "Replied:" config))
804 (when (and (or (eq 'autosupercite mh-yank-behavior)
805 (eq 'autoattrib mh-yank-behavior))
806 (eq (mh-show-buffer-message-number) mh-sent-from-msg))
807 (undo-boundary)
808 (mh-yank-cur-msg))
809 (mh-letter-mode-message))))
810
811 ;;;###mh-autoload
812 (defun mh-send (to cc subject)
813 "Compose a message.
814
815 Your letter appears in an Emacs buffer whose mode is
816 MH-Letter (see `mh-letter-mode').
817
818 The arguments TO, CC, and SUBJECT can be used to prefill the
819 draft fields or suppress the prompts if `mh-compose-prompt-flag'
820 is on. They are also passed to the function set in the option
821 `mh-compose-letter-function'.
822
823 See also `mh-insert-x-mailer-flag' and `mh-letter-mode-hook'.
824
825 Outside of an MH-Folder buffer (`mh-folder-mode'), you must call
826 either \\[mh-smail] or \\[mh-smail-other-window] to compose a new
827 message."
828 (interactive (list
829 (mh-interactive-read-address "To: ")
830 (mh-interactive-read-address "Cc: ")
831 (mh-interactive-read-string "Subject: ")))
832 (let ((config (current-window-configuration)))
833 (delete-other-windows)
834 (mh-send-sub to cc subject config)))
835
836 \f
837
838 ;;; Support Routines
839
840 (defun mh-interactive-read-address (prompt)
841 "Read an address.
842 If `mh-compose-prompt-flag' is non-nil, then read an address with
843 PROMPT.
844 Otherwise return the empty string."
845 (if mh-compose-prompt-flag (mh-read-address prompt) ""))
846
847 (defun mh-interactive-read-string (prompt)
848 "Read a string.
849 If `mh-compose-prompt-flag' is non-nil, then read a string with
850 PROMPT.
851 Otherwise return the empty string."
852 (if mh-compose-prompt-flag (read-string prompt) ""))
853
854 ;;;###mh-autoload
855 (defun mh-show-buffer-message-number (&optional buffer)
856 "Message number of displayed message in corresponding show buffer.
857
858 Return nil if show buffer not displayed.
859 If in `mh-letter-mode', don't display the message number being replied
860 to, but rather the message number of the show buffer associated with
861 our originating folder buffer.
862 Optional argument BUFFER can be used to specify the buffer."
863 (save-excursion
864 (if buffer
865 (set-buffer buffer))
866 (cond ((eq major-mode 'mh-show-mode)
867 (let ((number-start (mh-search-from-end ?/ buffer-file-name)))
868 (string-to-number (substring buffer-file-name
869 (1+ number-start)))))
870 ((and (eq major-mode 'mh-folder-mode)
871 mh-show-buffer
872 (get-buffer mh-show-buffer))
873 (mh-show-buffer-message-number mh-show-buffer))
874 ((and (eq major-mode 'mh-letter-mode)
875 mh-sent-from-folder
876 (get-buffer mh-sent-from-folder))
877 (mh-show-buffer-message-number mh-sent-from-folder))
878 (t
879 nil))))
880
881 (defun mh-find-components ()
882 "Return the path to the components file."
883 (let (components)
884 (cond
885 ((file-exists-p
886 (setq components
887 (expand-file-name mh-comp-formfile mh-user-path)))
888 components)
889 ((file-exists-p
890 (setq components
891 (expand-file-name mh-comp-formfile mh-lib)))
892 components)
893 (t
894 (error "Can't find %s in %s or %s"
895 mh-comp-formfile mh-user-path mh-lib)))))
896
897 (defun mh-send-sub (to cc subject config)
898 "Do the real work of composing and sending a letter.
899 Expects the TO, CC, and SUBJECT fields as arguments.
900 CONFIG is the window configuration before sending mail."
901 (let ((folder mh-current-folder)
902 (msg-num (mh-get-msg-num nil)))
903 (message "Composing a message...")
904 (let ((draft (mh-read-draft
905 "message"
906 (mh-find-components)
907 nil)))
908 (mh-insert-fields "To:" to "Subject:" subject "Cc:" cc)
909 (goto-char (point-max))
910 (mh-compose-and-send-mail draft "" folder msg-num
911 to subject cc
912 nil nil config)
913 (mh-letter-mode-message)
914 (mh-letter-adjust-point))))
915
916 (defun mh-read-draft (use initial-contents delete-contents-file)
917 "Read draft file into a draft buffer and make that buffer the current one.
918
919 USE is a message used for prompting about the intended use of the
920 message.
921 INITIAL-CONTENTS is filename that is read into an empty buffer, or nil
922 if buffer should not be modified. Delete the initial-contents file if
923 DELETE-CONTENTS-FILE flag is set.
924 Returns the draft folder's name.
925 If the draft folder facility is enabled in ~/.mh_profile, a new buffer
926 is used each time and saved in the draft folder. The draft file can
927 then be reused."
928 (cond (mh-draft-folder
929 (let ((orig-default-dir default-directory)
930 (draft-file-name (mh-new-draft-name)))
931 (pop-to-buffer (generate-new-buffer
932 (format "draft-%s"
933 (file-name-nondirectory draft-file-name))))
934 (condition-case ()
935 (insert-file-contents draft-file-name t)
936 (file-error))
937 (setq default-directory orig-default-dir)))
938 (t
939 (let ((draft-name (expand-file-name "draft" mh-user-path)))
940 (pop-to-buffer "draft") ; Create if necessary
941 (if (buffer-modified-p)
942 (if (y-or-n-p "Draft has been modified; kill anyway? ")
943 (set-buffer-modified-p nil)
944 (error "Draft preserved")))
945 (setq buffer-file-name draft-name)
946 (clear-visited-file-modtime)
947 (unlock-buffer)
948 (cond ((and (file-exists-p draft-name)
949 (not (equal draft-name initial-contents)))
950 (insert-file-contents draft-name)
951 (delete-file draft-name))))))
952 (cond ((and initial-contents
953 (or (zerop (buffer-size))
954 (if (y-or-n-p
955 (format "A draft exists. Use for %s? " use))
956 (if mh-error-if-no-draft
957 (error "A prior draft exists"))
958 t)))
959 (erase-buffer)
960 (insert-file-contents initial-contents)
961 (if delete-contents-file (delete-file initial-contents))))
962 (auto-save-mode 1)
963 (if mh-draft-folder
964 (save-buffer)) ; Do not reuse draft name
965 (buffer-name))
966
967 (defun mh-new-draft-name ()
968 "Return the pathname of folder for draft messages."
969 (save-excursion
970 (mh-exec-cmd-quiet t "mhpath" mh-draft-folder "new")
971 (buffer-substring (point-min) (1- (point-max)))))
972
973 (defun mh-insert-fields (&rest name-values)
974 "Insert the NAME-VALUES pairs in the current buffer.
975 If the field exists, append the value to it.
976 Do not insert any pairs whose value is the empty string."
977 (let ((case-fold-search t))
978 (while name-values
979 (let ((field-name (car name-values))
980 (value (car (cdr name-values))))
981 (if (not (string-match "^.*:$" field-name))
982 (setq field-name (concat field-name ":")))
983 (cond ((or (null value)
984 (equal value ""))
985 nil)
986 ((mh-position-on-field field-name)
987 (insert " " (or value "")))
988 (t
989 (insert field-name " " value "\n")))
990 (setq name-values (cdr (cdr name-values)))))))
991
992 (defun mh-compose-and-send-mail (draft send-args
993 sent-from-folder sent-from-msg
994 to subject cc
995 annotate-char annotate-field
996 config)
997 "Edit and compose a draft message in buffer DRAFT and send or save it.
998 SEND-ARGS is the argument passed to the send command.
999 SENT-FROM-FOLDER is buffer containing scan listing of current folder,
1000 or nil if none exists.
1001 SENT-FROM-MSG is the message number or sequence name or nil.
1002 The TO, SUBJECT, and CC fields are passed to the
1003 `mh-compose-letter-function'.
1004 If ANNOTATE-CHAR is non-null, it is used to notate the scan listing of
1005 the message. In that case, the ANNOTATE-FIELD is used to build a
1006 string for `mh-annotate-msg'.
1007 CONFIG is the window configuration to restore after sending the
1008 letter."
1009 (pop-to-buffer draft)
1010 (mh-letter-mode)
1011
1012 ;; Insert identity.
1013 (mh-insert-identity mh-identity-default t)
1014 (mh-identity-make-menu)
1015 (mh-identity-add-menu)
1016
1017 ;; Cleanup possibly RFC2047 encoded subject header
1018 (mh-decode-message-subject)
1019
1020 ;; Insert extra fields.
1021 (mh-insert-x-mailer)
1022 (mh-insert-x-face)
1023
1024 (mh-letter-hide-all-skipped-fields)
1025
1026 (setq mh-sent-from-folder sent-from-folder)
1027 (setq mh-sent-from-msg sent-from-msg)
1028 (setq mh-send-args send-args)
1029 (setq mh-annotate-char annotate-char)
1030 (setq mh-annotate-field annotate-field)
1031 (setq mh-previous-window-config config)
1032 (setq mode-line-buffer-identification (list " {%b}"))
1033 (mh-logo-display)
1034 (mh-make-local-hook 'kill-buffer-hook)
1035 (add-hook 'kill-buffer-hook 'mh-tidy-draft-buffer nil t)
1036 (run-hook-with-args 'mh-compose-letter-function to subject cc))
1037
1038 (defun mh-insert-x-mailer ()
1039 "Append an X-Mailer field to the header.
1040 The versions of MH-E, Emacs, and MH are shown."
1041 ;; Lazily initialize mh-x-mailer-string.
1042 (when (and mh-insert-x-mailer-flag (null mh-x-mailer-string))
1043 (setq mh-x-mailer-string
1044 (format "MH-E %s; %s; %sEmacs %s"
1045 mh-version mh-variant-in-use
1046 (if (featurep 'xemacs) "X" "GNU ")
1047 (cond ((not (featurep 'xemacs))
1048 (string-match "[0-9]+\\.[0-9]+\\(\\.[0-9]+\\)?"
1049 emacs-version)
1050 (match-string 0 emacs-version))
1051 ((string-match "[0-9.]*\\( +\([ a-z]+[0-9]+\)\\)?"
1052 emacs-version)
1053 (match-string 0 emacs-version))
1054 (t (format "%s.%s" emacs-major-version
1055 emacs-minor-version))))))
1056 ;; Insert X-Mailer, but only if it doesn't already exist.
1057 (save-excursion
1058 (when (and mh-insert-x-mailer-flag
1059 (null (mh-goto-header-field "X-Mailer")))
1060 (mh-insert-fields "X-Mailer:" mh-x-mailer-string))))
1061
1062 (defun mh-insert-x-face ()
1063 "Append X-Face, Face or X-Image-URL field to header.
1064 If the field already exists, this function does nothing."
1065 (when (and (file-exists-p mh-x-face-file)
1066 (file-readable-p mh-x-face-file))
1067 (save-excursion
1068 (unless (or (mh-position-on-field "X-Face")
1069 (mh-position-on-field "Face")
1070 (mh-position-on-field "X-Image-URL"))
1071 (save-excursion
1072 (goto-char (+ (point) (cadr (insert-file-contents mh-x-face-file))))
1073 (if (not (looking-at "^"))
1074 (insert "\n")))
1075 (unless (looking-at "\\(X-Face\\|Face\\|X-Image-URL\\): ")
1076 (insert "X-Face: "))))))
1077
1078 (defun mh-tidy-draft-buffer ()
1079 "Run when a draft buffer is destroyed."
1080 (let ((buffer (get-buffer mh-recipients-buffer)))
1081 (if buffer
1082 (kill-buffer buffer))))
1083
1084 (defun mh-letter-mode-message ()
1085 "Display a help message for users of `mh-letter-mode'.
1086 This should be the last function called when composing the draft."
1087 (message "%s" (substitute-command-keys
1088 (concat "Type \\[mh-send-letter] to send message, "
1089 "\\[mh-help] for help"))))
1090
1091 (defun mh-letter-adjust-point ()
1092 "Move cursor to first header field if are using the no prompt mode."
1093 (unless mh-compose-prompt-flag
1094 (goto-char (point-max))
1095 (mh-letter-next-header-field)))
1096
1097 (defun mh-annotate-msg (msg folder note &rest args)
1098 "Mark MSG in FOLDER with character NOTE and annotate message with ARGS.
1099 MSG can be a message number, a list of message numbers, or a sequence.
1100 The hook `mh-annotate-msg-hook' is run after annotating; see its
1101 documentation for variables it can use."
1102 (apply 'mh-exec-cmd "anno" folder
1103 (if (listp msg) (append msg args) (cons msg args)))
1104 (save-excursion
1105 (cond ((get-buffer folder) ; Buffer may be deleted
1106 (set-buffer folder)
1107 (mh-iterate-on-range nil msg
1108 (mh-notate nil note
1109 (+ mh-cmd-note mh-scan-field-destination-offset))))))
1110 (let ((mh-current-folder folder)
1111 ;; mh-annotate-list is a sequence name or a list of message numbers
1112 (mh-annotate-list (if (numberp msg) (list msg) msg)))
1113 (run-hooks 'mh-annotate-msg-hook)))
1114
1115 (defun mh-insert-header-separator ()
1116 "Insert `mh-mail-header-separator', if absent."
1117 (save-excursion
1118 (goto-char (point-min))
1119 (rfc822-goto-eoh)
1120 (if (looking-at "$")
1121 (insert mh-mail-header-separator))))
1122
1123 ;;;###mh-autoload
1124 (defun mh-insert-auto-fields (&optional non-interactive)
1125 "Insert custom fields if recipient is found in `mh-auto-fields-list'.
1126
1127 Once the header contains one or more recipients, you may run this
1128 command to insert these fields manually. However, if you use this
1129 command, the automatic insertion when the message is sent is
1130 disabled.
1131
1132 In a program, set buffer-local `mh-insert-auto-fields-done-local'
1133 if header fields were added. If NON-INTERACTIVE is non-nil,
1134 perform actions quietly and only if
1135 `mh-insert-auto-fields-done-local' is nil. Return t if fields
1136 added; otherwise return nil."
1137 (interactive)
1138 (when (or (not non-interactive)
1139 (not mh-insert-auto-fields-done-local))
1140 (save-excursion
1141 (when (and (or (mh-goto-header-field "To:")
1142 (mh-goto-header-field "cc:")))
1143 (let ((list mh-auto-fields-list)
1144 (fields-inserted nil))
1145 (while list
1146 (let ((regexp (nth 0 (car list)))
1147 (entries (nth 1 (car list))))
1148 (when (mh-regexp-in-field-p regexp "To:" "cc:")
1149 (setq mh-insert-auto-fields-done-local t)
1150 (setq fields-inserted t)
1151 (if (not non-interactive)
1152 (message "Fields for %s added" regexp))
1153 (let ((entry-list entries))
1154 (while entry-list
1155 (let ((field (caar entry-list))
1156 (value (cdar entry-list)))
1157 (cond
1158 ((equal ":identity" field)
1159 (when
1160 ;;(and (not mh-identity-local)
1161 ;; Bug 1204506. But do we need to be able
1162 ;; to set an identity manually that won't be
1163 ;; overridden by mh-insert-auto-fields?
1164 (assoc value mh-identity-list)
1165 ;;)
1166 (mh-insert-identity value)))
1167 (t
1168 (mh-modify-header-field field value
1169 (equal field "From")))))
1170 (setq entry-list (cdr entry-list))))))
1171 (setq list (cdr list)))
1172 fields-inserted)))))
1173
1174 (defun mh-modify-header-field (field value &optional overwrite-flag)
1175 "To header FIELD add VALUE.
1176 If OVERWRITE-FLAG is non-nil then the old value, if present, is
1177 discarded."
1178 (cond ((and overwrite-flag
1179 (mh-goto-header-field (concat field ":")))
1180 (insert " " value)
1181 (delete-region (point) (mh-line-end-position)))
1182 ((and (not overwrite-flag)
1183 (mh-regexp-in-field-p (concat "\\b" (regexp-quote value) "\\b") field))
1184 ;; Already there, do nothing.
1185 )
1186 ((and (not overwrite-flag)
1187 (mh-goto-header-field (concat field ":")))
1188 (insert " " value ","))
1189 (t
1190 (mh-goto-header-end 0)
1191 (insert field ": " value "\n"))))
1192
1193 (defun mh-regexp-in-field-p (regexp &rest fields)
1194 "Non-nil means REGEXP was found in FIELDS."
1195 (let ((old-syntax-table (syntax-table)))
1196 (unwind-protect
1197 (save-excursion
1198 (let ((search-result nil))
1199 (while fields
1200 (let ((field (car fields))
1201 (syntax-table mh-regexp-in-field-syntax-table))
1202 (if (null syntax-table)
1203 (let ((case-fold-search t))
1204 (cond
1205 ((string-match field "^To$\\|^[BD]?cc$\\|^From$")
1206 (setq syntax-table mh-addr-syntax-table))
1207 ((string-match field "^Fcc$")
1208 (setq syntax-table mh-fcc-syntax-table))
1209 (t
1210 (setq syntax-table (syntax-table)))
1211 )))
1212 (if (and (mh-goto-header-field field)
1213 (set-syntax-table syntax-table)
1214 (re-search-forward
1215 regexp (save-excursion (mh-header-field-end)(point)) t))
1216 (setq fields nil
1217 search-result t)
1218 (setq fields (cdr fields)))
1219 (set-syntax-table old-syntax-table)))
1220 search-result))
1221 (set-syntax-table old-syntax-table))))
1222
1223 (defun mh-ascii-buffer-p ()
1224 "Check if current buffer is entirely composed of ASCII.
1225 The function doesn't work for XEmacs since `find-charset-region'
1226 doesn't exist there."
1227 (loop for charset in (mh-funcall-if-exists
1228 find-charset-region (point-min) (point-max))
1229 unless (eq charset 'ascii) return nil
1230 finally return t))
1231
1232 (provide 'mh-comp)
1233
1234 ;; Local Variables:
1235 ;; indent-tabs-mode: nil
1236 ;; sentence-end-double-space: nil
1237 ;; End:
1238
1239 ;;; mh-comp.el ends here