Document reserved keys
[emacs.git] / lisp / mh-e / mh-mime.el
blobe2c682a3996ac6dcef82c347d0980174fcae3f42
1 ;;; mh-mime.el --- MH-E MIME support
3 ;; Copyright (C) 1993, 1995, 2001-2018 Free Software Foundation, Inc.
5 ;; Author: Bill Wohler <wohler@newt.com>
6 ;; Maintainer: Bill Wohler <wohler@newt.com>
7 ;; Keywords: mail
8 ;; See: mh-e.el
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; Message composition of MIME message is done with either MH-style
28 ;; directives for mhn or mhbuild (MH 6.8 or later) or MML (MIME Meta
29 ;; Language) tags.
31 ;; TODO:
32 ;; Paragraph code should not fill # lines if MIME enabled.
33 ;; Implement mh-auto-mh-to-mime (if non-nil, \\[mh-send-letter]
34 ;; invokes mh-mh-to-mime automatically before sending.)
35 ;; Actually, instead of mh-auto-mh-to-mime,
36 ;; should read automhnproc from profile.
37 ;; MIME option to mh-forward command to move to content-description
38 ;; insertion point.
40 ;;; Change Log:
42 ;;; Code:
44 (require 'mh-e)
45 (require 'mh-gnus) ;needed because mh-gnus.el not compiled
47 (require 'font-lock)
48 (require 'gnus-util)
49 (require 'mailcap)
50 (require 'mm-decode)
51 (require 'mm-view)
52 (require 'mml)
54 (autoload 'article-emphasize "gnus-art")
55 (autoload 'gnus-eval-format "gnus-spec")
56 (autoload 'mail-content-type-get "mail-parse")
57 (autoload 'mail-decode-encoded-word-string "mail-parse")
58 (autoload 'mail-header-parse-content-type "mail-parse")
59 (autoload 'mail-header-strip-cte "mail-parse")
60 (autoload 'mail-strip-quoted-names "mail-utils")
61 (autoload 'message-options-get "message")
62 (autoload 'message-options-set "message")
63 (autoload 'message-options-set-recipient "message")
64 (autoload 'mm-decode-body "mm-bodies")
65 (autoload 'mm-uu-dissect "mm-uu")
66 (autoload 'mml-unsecure-message "mml-sec")
67 (autoload 'rfc2047-decode-region "rfc2047")
68 (autoload 'widget-convert-button "wid-edit")
72 ;;; Variables
74 ;; This has to be a macro, since we do: (setf (mh-buffer-data) ...)
75 ;;;###mh-autoload
76 (defmacro mh-buffer-data ()
77 "Convenience macro to get the MIME data structures of the current buffer."
78 `(gethash (current-buffer) mh-globals-hash))
80 ;; Structure to keep track of MIME handles on a per buffer basis.
81 (mh-defstruct (mh-buffer-data (:conc-name mh-mime-)
82 (:constructor mh-make-buffer-data))
83 (handles ()) ; List of MIME handles
84 (handles-cache (make-hash-table)) ; Cache to avoid multiple decodes of
85 ; nested messages
86 (parts-count 0) ; The button number is generated from
87 ; this number
88 (part-index-hash (make-hash-table))) ; Avoid incrementing the part number
89 ; for nested messages
91 (defvar mh-mm-inline-media-tests
92 `(("image/jpeg"
93 mm-inline-image
94 (lambda (handle)
95 (mm-valid-and-fit-image-p 'jpeg handle)))
96 ("image/png"
97 mm-inline-image
98 (lambda (handle)
99 (mm-valid-and-fit-image-p 'png handle)))
100 ("image/gif"
101 mm-inline-image
102 (lambda (handle)
103 (mm-valid-and-fit-image-p 'gif handle)))
104 ("image/tiff"
105 mm-inline-image
106 (lambda (handle)
107 (mm-valid-and-fit-image-p 'tiff handle)) )
108 ("image/xbm"
109 mm-inline-image
110 (lambda (handle)
111 (mm-valid-and-fit-image-p 'xbm handle)))
112 ("image/x-xbitmap"
113 mm-inline-image
114 (lambda (handle)
115 (mm-valid-and-fit-image-p 'xbm handle)))
116 ("image/xpm"
117 mm-inline-image
118 (lambda (handle)
119 (mm-valid-and-fit-image-p 'xpm handle)))
120 ("image/x-pixmap"
121 mm-inline-image
122 (lambda (handle)
123 (mm-valid-and-fit-image-p 'xpm handle)))
124 ("image/bmp"
125 mm-inline-image
126 (lambda (handle)
127 (mm-valid-and-fit-image-p 'bmp handle)))
128 ("image/x-portable-bitmap"
129 mm-inline-image
130 (lambda (handle)
131 (mm-valid-and-fit-image-p 'pbm handle)))
132 ("text/plain" mm-inline-text identity)
133 ("text/enriched" mm-inline-text identity)
134 ("text/richtext" mm-inline-text identity)
135 ("text/x-patch" mm-display-patch-inline
136 (lambda (handle)
137 (locate-library "diff-mode")))
138 ("application/emacs-lisp" mm-display-elisp-inline identity)
139 ("application/x-emacs-lisp" mm-display-elisp-inline identity)
140 ("text/html"
141 ,(if (fboundp 'mm-inline-text-html) 'mm-inline-text-html 'mm-inline-text)
142 (lambda (handle)
143 (or (and (boundp 'mm-inline-text-html-renderer)
144 mm-inline-text-html-renderer)
145 (and (boundp 'mm-text-html-renderer) mm-text-html-renderer))))
146 ("text/x-vcard"
147 mh-mm-inline-text-vcard
148 (lambda (handle)
149 (or (featurep 'vcard)
150 (locate-library "vcard"))))
151 ("message/delivery-status" mm-inline-text identity)
152 ("message/rfc822" mh-mm-inline-message identity)
153 ;;("message/partial" mm-inline-partial identity)
154 ;;("message/external-body" mm-inline-external-body identity)
155 ("text/.*" mm-inline-text identity)
156 ("audio/wav" mm-inline-audio
157 (lambda (handle)
158 (and (or (featurep 'nas-sound) (featurep 'native-sound))
159 (device-sound-enabled-p))))
160 ("audio/au"
161 mm-inline-audio
162 (lambda (handle)
163 (and (or (featurep 'nas-sound) (featurep 'native-sound))
164 (device-sound-enabled-p))))
165 ("application/pgp-signature" ignore identity)
166 ("application/x-pkcs7-signature" ignore identity)
167 ("application/pkcs7-signature" ignore identity)
168 ("application/x-pkcs7-mime" ignore identity)
169 ("application/pkcs7-mime" ignore identity)
170 ("multipart/alternative" ignore identity)
171 ("multipart/mixed" ignore identity)
172 ("multipart/related" ignore identity)
173 ;; Disable audio and image
174 ("audio/.*" ignore ignore)
175 ("image/.*" ignore ignore)
176 ;; Default to displaying as text
177 (".*" mm-inline-text mh-mm-readable-p))
178 "Alist of media types/tests saying whether types can be displayed inline.")
180 (defvar mh-mime-save-parts-directory nil
181 "Default to use for `mh-mime-save-parts-default-directory'.
182 Set from last use.")
184 ;; Copied from gnus-art.el (should be checked for other cool things that can
185 ;; be added to the buttons)
186 (defvar mh-mime-button-commands
187 '((mh-press-button "\r" "Toggle Display")))
188 (defvar mh-mime-button-map
189 (let ((map (make-sparse-keymap)))
190 (unless (>= (string-to-number emacs-version) 21)
191 ;; XEmacs doesn't care.
192 (set-keymap-parent map mh-show-mode-map))
193 (mh-do-in-gnu-emacs
194 (define-key map [mouse-2] 'mh-push-button))
195 (mh-do-in-xemacs
196 (define-key map '(button2) 'mh-push-button))
197 (dolist (c mh-mime-button-commands)
198 (define-key map (cadr c) (car c)))
199 map))
200 (defvar mh-mime-button-line-format-alist
201 '((?T long-type ?s)
202 (?d description ?s)
203 (?p index ?s)
204 (?e dots ?s)))
205 (defvar mh-mime-button-line-format "%{%([%p. %d%T]%)%}%e\n")
206 (defvar mh-mime-security-button-pressed nil)
207 (defvar mh-mime-security-button-line-format "%{%([[%t:%i]%D]%)%}\n")
208 (defvar mh-mime-security-button-end-line-format "%{%([[End of %t]%D]%)%}\n")
209 (defvar mh-mime-security-button-line-format-alist
210 '((?t type ?s)
211 (?i info ?s)
212 (?d details ?s)
213 (?D pressed-details ?s)))
214 (defvar mh-mime-security-button-map
215 (let ((map (make-sparse-keymap)))
216 (unless (>= (string-to-number emacs-version) 21)
217 (set-keymap-parent map mh-show-mode-map))
218 (define-key map "\r" 'mh-press-button)
219 (mh-do-in-gnu-emacs
220 (define-key map [mouse-2] 'mh-push-button))
221 (mh-do-in-xemacs
222 (define-key map '(button2) 'mh-push-button))
223 map))
227 ;;; MH-Folder Commands
229 ;; Alphabetical.
231 ;;;###mh-autoload
232 (defun mh-display-with-external-viewer (part-index)
233 "View attachment externally.
235 If Emacs does not know how to view an attachment, you could save
236 it into a file and then run some program to open it. It is
237 easier, however, to launch the program directly from MH-E with
238 this command. While you'll most likely use this to view
239 spreadsheets and documents, it is also useful to use your browser
240 to view HTML attachments with higher fidelity than what Emacs can
241 provide.
243 This command displays the attachment associated with the button
244 under the cursor. If the cursor is not located over a button,
245 then the cursor first moves to the next button, wrapping to the
246 beginning of the message if necessary. You can provide a numeric
247 prefix argument PART-INDEX to view the attachment labeled with
248 that number.
250 This command tries to provide a reasonable default for the viewer
251 by calling the Emacs function `mailcap-mime-info'. This function
252 usually reads the file \"/etc/mailcap\"."
253 (interactive "P")
254 (when (consp part-index) (setq part-index (car part-index)))
255 (mh-folder-mime-action
256 part-index
257 #'(lambda ()
258 (let* ((part (get-text-property (point) 'mh-data))
259 (type (mm-handle-media-type part))
260 (methods (mapcar (lambda (x) (list (cdr (assoc 'viewer x))))
261 (mailcap-mime-info type 'all)))
262 (def (caar methods))
263 (prompt (format "Viewer%s: " (if def
264 (format " (default %s)" def)
265 "")))
266 (method (completing-read prompt methods nil nil nil nil def))
267 (folder mh-show-folder-buffer)
268 (buffer-read-only nil))
269 (when (string-match "^[^% \t]+$" method)
270 (setq method (concat method " %s")))
271 (mh-flet
272 ((mm-handle-set-external-undisplayer
273 (handle function)
274 (mh-handle-set-external-undisplayer folder handle function)))
275 (unwind-protect (mm-display-external part method)
276 (set-buffer-modified-p nil)))))
277 nil))
279 ;;;###mh-autoload
280 (defun mh-folder-inline-mime-part (part-index)
281 "Show attachment verbatim.
283 You can view the raw contents of an attachment with this command.
284 This command displays (or hides) the contents of the attachment
285 associated with the button under the cursor verbatim. If the
286 cursor is not located over a button, then the cursor first moves
287 to the next button, wrapping to the beginning of the message if
288 necessary.
290 You can also provide a numeric prefix argument PART-INDEX to view
291 the attachment labeled with that number."
292 (interactive "P")
293 (when (consp part-index) (setq part-index (car part-index)))
294 (mh-folder-mime-action part-index #'mh-mime-inline-part nil))
296 (defun mh-mime-inline-part ()
297 "Toggle display of the raw MIME part."
298 (interactive)
299 (let* ((buffer-read-only nil)
300 (data (get-text-property (point) 'mh-data))
301 (inserted-flag (get-text-property (point) 'mh-mime-inserted))
302 (displayed-flag (mm-handle-displayed-p data))
303 (point (point))
304 start end)
305 (cond ((and data (not inserted-flag) (not displayed-flag))
306 (let ((contents (mm-get-part data)))
307 (add-text-properties (mh-line-beginning-position)
308 (mh-line-end-position) '(mh-mime-inserted t))
309 (setq start (point-marker))
310 (forward-line 1)
311 (mm-insert-inline data contents)
312 (setq end (point-marker))
313 (add-text-properties
314 start (progn (goto-char start) (mh-line-end-position))
315 `(mh-region (,start . ,end)))))
316 ((and data (or inserted-flag displayed-flag))
317 (mh-press-button)
318 (message "MIME part already inserted")))
319 (goto-char point)
320 (set-buffer-modified-p nil)))
322 ;;;###mh-autoload
323 (defun mh-folder-save-mime-part (part-index)
324 "Save (output) attachment.
326 This command saves the attachment associated with the button under the
327 cursor. If the cursor is not located over a button, then the cursor
328 first moves to the next button, wrapping to the beginning of the
329 message if necessary.
331 You can also provide a numeric prefix argument PART-INDEX to save the
332 attachment labeled with that number.
334 This command prompts you for a filename and suggests a specific name
335 if it is available."
336 (interactive "P")
337 (when (consp part-index) (setq part-index (car part-index)))
338 (mh-folder-mime-action part-index #'mh-mime-save-part nil))
340 (defun mh-mime-save-part ()
341 "Save MIME part at point."
342 (interactive)
343 (let ((data (get-text-property (point) 'mh-data)))
344 (when data
345 (let ((mm-default-directory
346 (file-name-as-directory (or mh-mime-save-parts-directory
347 default-directory))))
348 (mh-mm-save-part data)
349 (setq mh-mime-save-parts-directory mm-default-directory)))))
351 ;;;###mh-autoload
352 (defun mh-folder-toggle-mime-part (part-index)
353 "View attachment.
355 This command displays (or hides) the attachment associated with
356 the button under the cursor. If the cursor is not located over a
357 button, then the cursor first moves to the next button, wrapping
358 to the beginning of the message if necessary. This command has
359 the advantage over related commands of working from the MH-Folder
360 buffer.
362 You can also provide a numeric prefix argument PART-INDEX to view
363 the attachment labeled with that number. If Emacs does not know
364 how to display the attachment, then Emacs offers to save the
365 attachment in a file."
366 (interactive "P")
367 (when (consp part-index) (setq part-index (car part-index)))
368 (mh-folder-mime-action part-index #'mh-press-button t))
370 ;;;###mh-autoload
371 (defun mh-mime-save-parts (prompt)
372 "Save attachments.
374 You can save all of the attachments at once with this command.
375 The attachments are saved in the directory specified by the
376 option `mh-mime-save-parts-default-directory' unless you use a
377 prefix argument PROMPT in which case you are prompted for the
378 directory. These directories may be superseded by MH profile
379 components, since this function calls on \"mhstore\" (\"mhn\") to
380 do the work."
381 (interactive "P")
382 (let ((msg (if (eq major-mode 'mh-show-mode)
383 (mh-show-buffer-message-number)
384 (mh-get-msg-num t)))
385 (folder (if (eq major-mode 'mh-show-mode)
386 mh-show-folder-buffer
387 mh-current-folder))
388 (command (if (mh-variant-p 'nmh) "mhstore" "mhn"))
389 (directory
390 (cond
391 ((and (or prompt
392 (equal nil mh-mime-save-parts-default-directory)
393 (equal t mh-mime-save-parts-default-directory))
394 (not mh-mime-save-parts-directory))
395 (read-directory-name "Store in directory: " nil nil t))
396 ((and (or prompt
397 (equal t mh-mime-save-parts-default-directory))
398 mh-mime-save-parts-directory)
399 (read-directory-name (format
400 "Store in directory (default %s): "
401 mh-mime-save-parts-directory)
402 "" mh-mime-save-parts-directory t ""))
403 ((stringp mh-mime-save-parts-default-directory)
404 mh-mime-save-parts-default-directory)
406 mh-mime-save-parts-directory))))
407 (if (and (equal directory "") mh-mime-save-parts-directory)
408 (setq directory mh-mime-save-parts-directory))
409 (if (not (file-directory-p directory))
410 (message "No directory specified")
411 (if (equal nil mh-mime-save-parts-default-directory)
412 (setq mh-mime-save-parts-directory directory))
413 (with-current-buffer (get-buffer-create mh-log-buffer)
414 (cd directory)
415 (setq mh-mime-save-parts-directory directory)
416 (let ((initial-size (mh-truncate-log-buffer)))
417 (apply 'call-process
418 (expand-file-name command mh-progs) nil t nil
419 (mh-list-to-string (list folder msg "-auto"
420 (if (not (mh-variant-p 'nmh))
421 "-store"))))
422 (if (> (buffer-size) initial-size)
423 (save-window-excursion
424 (switch-to-buffer-other-window mh-log-buffer)
425 (sit-for 3))))))))
427 ;;;###mh-autoload
428 (defun mh-toggle-mh-decode-mime-flag ()
429 "Toggle the value of `mh-decode-mime-flag'."
430 (interactive)
431 (setq mh-decode-mime-flag (not mh-decode-mime-flag))
432 (mh-show nil t)
433 (message "%s" (if mh-decode-mime-flag
434 "Processing attachments normally"
435 "Displaying raw message")))
437 ;;;###mh-autoload
438 (defun mh-toggle-mime-buttons ()
439 "Toggle option `mh-display-buttons-for-inline-parts-flag'."
440 (interactive)
441 (setq mh-display-buttons-for-inline-parts-flag
442 (not mh-display-buttons-for-inline-parts-flag))
443 (mh-show nil t))
447 ;;; MIME Display Routines
449 (defun mh-mm-inline-message (handle)
450 "Display message, HANDLE.
451 The function decodes the message and displays it. It avoids
452 decoding the same message multiple times."
453 (let ((b (point))
454 (clean-message-header mh-clean-message-header-flag)
455 (invisible-headers mh-invisible-header-fields-compiled)
456 (visible-headers nil))
457 (save-excursion
458 (save-restriction
459 (narrow-to-region b b)
460 (mm-insert-part handle)
461 (mh-mime-display
462 (or (gethash handle (mh-mime-handles-cache (mh-buffer-data)))
463 (setf (gethash handle (mh-mime-handles-cache (mh-buffer-data)))
464 (let ((handles (mm-dissect-buffer nil)))
465 (if handles
466 (mh-mm-uu-dissect-text-parts handles)
467 (setq handles (mm-uu-dissect)))
468 (setf (mh-mime-handles (mh-buffer-data))
469 (mh-mm-merge-handles
470 handles (mh-mime-handles (mh-buffer-data))))
471 handles))))
473 (goto-char (point-min))
474 (mh-show-xface)
475 (cond (clean-message-header
476 (mh-clean-msg-header (point-min)
477 invisible-headers
478 visible-headers)
479 (goto-char (point-min)))
481 (mh-start-of-uncleaned-message)))
482 (mh-decode-message-header)
483 (mh-show-addr)
484 ;; The other highlighting types don't need anything special
485 (when (eq mh-highlight-citation-style 'gnus)
486 (mh-gnus-article-highlight-citation))
487 (goto-char (point-min))
488 (insert "\n------- Forwarded Message\n\n")
489 (mh-display-smileys)
490 (mh-display-emphasis)
491 (mm-handle-set-undisplayer
492 handle
493 `(lambda ()
494 (let (buffer-read-only)
495 (if (fboundp 'remove-specifier)
496 ;; This is only valid on XEmacs.
497 (mapcar (lambda (prop)
498 (remove-specifier
499 (face-property 'default prop) (current-buffer)))
500 '(background background-pixmap foreground)))
501 (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
503 ;;;###mh-autoload
504 (defun mh-decode-message-header ()
505 "Decode RFC2047 encoded message header fields."
506 (when mh-decode-mime-flag
507 (let ((buffer-read-only nil))
508 (rfc2047-decode-region (point-min) (mh-mail-header-end)))))
510 ;;;###mh-autoload
511 (defun mh-decode-message-subject ()
512 "Decode RFC2047 encoded message header fields."
513 (when mh-decode-mime-flag
514 (save-excursion
515 (let ((buffer-read-only nil))
516 (rfc2047-decode-region (progn (mh-goto-header-field "Subject:") (point))
517 (progn (mh-header-field-end) (point)))))))
519 ;;;###mh-autoload
520 (defun mh-mime-display (&optional pre-dissected-handles)
521 "Display (and possibly decode) MIME handles.
522 Optional argument, PRE-DISSECTED-HANDLES is a list of MIME
523 handles. If present they are displayed otherwise the buffer is
524 parsed and then displayed."
525 (let ((handles ())
526 (folder mh-show-folder-buffer)
527 (raw-message-data (buffer-string)))
528 (mh-flet
529 ((mm-handle-set-external-undisplayer
530 (handle function)
531 (mh-handle-set-external-undisplayer folder handle function)))
532 (goto-char (point-min))
533 (unless (search-forward "\n\n" nil t)
534 (goto-char (point-max))
535 (insert "\n\n"))
537 (condition-case err
538 (progn
539 ;; If needed dissect the current buffer
540 (if pre-dissected-handles
541 (setq handles pre-dissected-handles)
542 (if (setq handles (mm-dissect-buffer nil))
543 (mh-mm-uu-dissect-text-parts handles)
544 (setq handles (mm-uu-dissect)))
545 (setf (mh-mime-handles (mh-buffer-data))
546 (mh-mm-merge-handles handles
547 (mh-mime-handles (mh-buffer-data))))
548 (unless handles
549 (mh-decode-message-body)))
551 (cond ((and handles
552 (or (not (stringp (car handles)))
553 (cdr handles)))
554 ;; Go to start of message body
555 (goto-char (point-min))
556 (or (search-forward "\n\n" nil t)
557 (goto-char (point-max)))
559 ;; Delete the body
560 (delete-region (point) (point-max))
562 ;; Display the MIME handles
563 (mh-mime-display-part handles))
565 (mh-signature-highlight))))
566 (error
567 (message "Could not display body: %s" (error-message-string err))
568 (delete-region (point-min) (point-max))
569 (insert raw-message-data))))))
571 (defun mh-decode-message-body ()
572 "Decode message based on charset.
573 If message has been encoded for transfer take that into account."
574 (let (ct charset cte)
575 (goto-char (point-min))
576 (re-search-forward "\n\n" nil t)
577 (save-restriction
578 (narrow-to-region (point-min) (point))
579 (setq ct (ignore-errors (mail-header-parse-content-type
580 (message-fetch-field "Content-Type" t)))
581 charset (mail-content-type-get ct 'charset)
582 cte (message-fetch-field "Content-Transfer-Encoding")))
583 (when (stringp cte) (setq cte (mail-header-strip-cte cte)))
584 (when (or (not ct) (equal (car ct) "text/plain"))
585 (save-restriction
586 (narrow-to-region (min (1+ (mh-mail-header-end)) (point-max))
587 (point-max))
588 (mm-decode-body charset
589 (and cte (intern (downcase cte)))
590 (car ct))))))
592 (defun mh-mime-display-part (handle)
593 "Decides the viewer to call based on the type of HANDLE."
594 (cond ((null handle)
595 nil)
596 ((not (stringp (car handle)))
597 (mh-mime-display-single handle))
598 ((equal (car handle) "multipart/alternative")
599 (mh-mime-display-alternative (cdr handle)))
600 ((and mh-pgp-support-flag
601 (or (equal (car handle) "multipart/signed")
602 (equal (car handle) "multipart/encrypted")))
603 (mh-mime-display-security handle))
605 (mh-mime-display-mixed (cdr handle)))))
607 (defun mh-mime-display-mixed (handles)
608 "Display the list of MIME parts, HANDLES recursively."
609 (mapcar #'mh-mime-display-part handles))
611 (defun mh-mime-display-alternative (handles)
612 "Choose among the alternatives, HANDLES the part that will be displayed.
613 If no part is preferred then all the parts are displayed."
614 (let* ((preferred (mm-preferred-alternative handles))
615 (others (loop for x in handles unless (eq x preferred) collect x)))
616 (cond ((and preferred
617 (stringp (car preferred)))
618 (mh-mime-display-part preferred)
619 (mh-mime-maybe-display-alternatives others))
620 (preferred
621 (save-restriction
622 (narrow-to-region (point) (if (eobp) (point) (1+ (point))))
623 (mh-mime-display-single preferred)
624 (mh-mime-maybe-display-alternatives others)
625 (goto-char (point-max))))
627 (mh-mime-display-mixed handles)))))
629 (defun mh-mime-maybe-display-alternatives (alternatives)
630 "Show buttons for ALTERNATIVES.
631 If `mh-mime-display-alternatives-flag' is non-nil then display
632 buttons for alternative parts that are usually suppressed."
633 (when (and mh-display-buttons-for-alternatives-flag alternatives)
634 (insert "\n----------------------------------------------------\n")
635 (insert "Alternatives:\n")
636 (dolist (x alternatives)
637 (insert "\n")
638 (mh-insert-mime-button x (mh-mime-part-index x) nil))
639 (insert "\n----------------------------------------------------\n")))
641 (defun mh-mime-display-security (handle)
642 "Display PGP encrypted/signed message, HANDLE."
643 (save-restriction
644 (narrow-to-region (point) (point))
645 (insert "\n")
646 (mh-insert-mime-security-button handle)
647 (mh-mime-display-mixed (cdr handle))
648 (insert "\n")
649 (let ((mh-mime-security-button-line-format
650 mh-mime-security-button-end-line-format))
651 (mh-insert-mime-security-button handle))
652 (mh-mm-set-handle-multipart-parameter
653 handle 'mh-region (cons (point-min-marker) (point-max-marker)))))
655 (defun mh-mime-display-single (handle)
656 "Display a leaf node, HANDLE in the MIME tree."
657 (let* ((type (mm-handle-media-type handle))
658 (small-image-flag (mh-small-image-p handle))
659 (attachmentp (equal (car (mm-handle-disposition handle))
660 "attachment"))
661 (inlinep (and (equal (car (mm-handle-disposition handle)) "inline")
662 (mm-automatic-display-p handle)
663 (mm-inlinable-p handle)
664 (mm-inlined-p handle)))
665 (displayp (or inlinep ; show if inline OR
666 (mh-inline-vcard-p handle); inline vcard OR
667 (and (not attachmentp) ; if not an attachment
668 (or small-image-flag ; and small image
669 ; and user wants inline
670 (and (not (equal
671 (mm-handle-media-supertype handle)
672 "image"))
673 (mm-automatic-display-p handle)
674 (mm-inlinable-p handle)
675 (mm-inlined-p handle)))))))
676 (save-restriction
677 (narrow-to-region (point) (if (eobp) (point) (1+ (point))))
678 (cond ((and mh-pgp-support-flag
679 (equal type "application/pgp-signature"))
680 nil) ; skip signatures as they are already handled...
681 ((not displayp)
682 (insert "\n")
683 (mh-insert-mime-button handle (mh-mime-part-index handle) nil))
684 ((and displayp
685 (not mh-display-buttons-for-inline-parts-flag))
686 (or (mm-display-part handle)
687 (mm-display-part handle))
688 (mh-signature-highlight handle))
689 ((and displayp
690 mh-display-buttons-for-inline-parts-flag)
691 (insert "\n")
692 (mh-insert-mime-button handle (mh-mime-part-index handle) nil)
693 (forward-line -1)
694 (mh-mm-display-part handle)))
695 (goto-char (point-max)))))
697 ;; There is a bug in Gnus inline image display due to which an extra line
698 ;; gets inserted every time it is viewed. To work around that problem we are
699 ;; using an extra property 'mh-region to remember the region that is added
700 ;; when the button is clicked. The region is then deleted to make sure that
701 ;; no extra lines get inserted.
702 (defun mh-mm-display-part (handle)
703 "Toggle display of button for MIME part, HANDLE."
704 (beginning-of-line)
705 (let ((id (get-text-property (point) 'mh-part))
706 (point (point))
707 (window (selected-window))
708 (mail-parse-charset 'nil)
709 (mail-parse-ignored-charsets nil)
710 region buffer-read-only)
711 (save-excursion
712 (unwind-protect
713 (let ((win (get-buffer-window (current-buffer) t)))
714 (when win
715 (select-window win))
716 (goto-char point)
718 (if (mm-handle-displayed-p handle)
719 ;; This will remove the part.
720 (progn
721 ;; Delete the button and displayed part (if any)
722 (let ((region (get-text-property point 'mh-region)))
723 (when region
724 (mh-funcall-if-exists
725 remove-images (car region) (cdr region)))
726 (mm-display-part handle)
727 (when region
728 (delete-region (car region) (cdr region))))
729 ;; Delete button (if it still remains). This happens for
730 ;; externally displayed parts where the previous step does
731 ;; nothing.
732 (unless (eolp)
733 (delete-region (point) (progn (forward-line) (point)))))
734 (save-restriction
735 (delete-region (point) (progn (forward-line 1) (point)))
736 (narrow-to-region (point) (point))
737 ;; Maybe we need another unwind-protect here.
738 (when (equal (mm-handle-media-supertype handle) "image")
739 (insert "\n"))
740 (when (and (not (eq (ignore-errors (mm-display-part handle))
741 'inline))
742 (equal (mm-handle-media-supertype handle)
743 "image"))
744 (goto-char (point-min))
745 (delete-char 1))
746 (when (equal (mm-handle-media-supertype handle) "text")
747 (when (eq mh-highlight-citation-style 'gnus)
748 (mh-gnus-article-highlight-citation))
749 (mh-display-smileys)
750 (mh-display-emphasis)
751 (mh-signature-highlight handle))
752 (setq region (cons (progn (goto-char (point-min))
753 (point-marker))
754 (progn (goto-char (point-max))
755 (point-marker)))))))
756 (when (window-live-p window)
757 (select-window window))
758 (goto-char point)
759 (beginning-of-line)
760 (mh-insert-mime-button handle id (mm-handle-displayed-p handle))
761 (goto-char point)
762 (when region
763 (add-text-properties (mh-line-beginning-position)
764 (mh-line-end-position)
765 `(mh-region ,region)))))))
767 (defun mh-mime-part-index (handle)
768 "Generate the button number for MIME part, HANDLE.
769 Notice that a hash table is used to display the same number when
770 buttons need to be displayed multiple times (for instance when
771 nested messages are opened)."
772 (or (gethash handle (mh-mime-part-index-hash (mh-buffer-data)))
773 (setf (gethash handle (mh-mime-part-index-hash (mh-buffer-data)))
774 (incf (mh-mime-parts-count (mh-buffer-data))))))
776 (defun mh-small-image-p (handle)
777 "Decide whether HANDLE is a \"small\" image that can be displayed inline.
778 This is only useful if a Content-Disposition header is not present."
779 (let ((media-test (caddr (assoc (car (mm-handle-type handle))
780 mh-mm-inline-media-tests)))
781 (mm-inline-large-images t))
782 (and media-test
783 (equal (mm-handle-media-supertype handle) "image")
784 (funcall media-test handle) ; Since mm-inline-large-images is T,
785 ; this only tells us if the image is
786 ; something that emacs can display
787 (let* ((image (mm-get-image handle)))
788 (or (mh-do-in-xemacs
789 (and (mh-funcall-if-exists glyphp image)
790 (< (glyph-width image)
791 (or mh-max-inline-image-width (window-pixel-width)))
792 (< (glyph-height image)
793 (or mh-max-inline-image-height
794 (window-pixel-height)))))
795 (mh-do-in-gnu-emacs
796 (let ((size (mh-funcall-if-exists image-size image)))
797 (and size
798 (< (cdr size) (or mh-max-inline-image-height
799 (1- (window-height))))
800 (< (car size) (or mh-max-inline-image-width
801 (window-width)))))))))))
803 (defun mh-inline-vcard-p (handle)
804 "Decide if HANDLE is a vcard that must be displayed inline."
805 (let ((type (mm-handle-type handle)))
806 (and (or (featurep 'vcard) (fboundp 'vcard-pretty-print))
807 (consp type)
808 (equal (car type) "text/x-vcard")
809 (save-excursion
810 (save-restriction
811 (widen)
812 (goto-char (point-min))
813 (not (mh-signature-separator-p)))))))
815 (defun mh-signature-highlight (&optional handle)
816 "Highlight message signature in HANDLE.
817 The optional argument, HANDLE is a MIME handle if the function is
818 being used to highlight the signature in a MIME part."
819 (let ((regexp
820 (cond ((not handle) "^-- $")
821 ((not (and (equal (mm-handle-media-supertype handle) "text")
822 (equal (mm-handle-media-subtype handle) "html")))
823 "^-- $")
824 ((eq (mh-mm-text-html-renderer) 'lynx) "^ --$")
825 (t "^--$"))))
826 (save-excursion
827 (goto-char (point-max))
828 (when (re-search-backward regexp nil t)
829 (mh-do-in-gnu-emacs
830 (let ((ov (make-overlay (point) (point-max))))
831 (overlay-put ov 'face 'mh-show-signature)
832 (overlay-put ov 'evaporate t)))
833 (mh-do-in-xemacs
834 (set-extent-property (make-extent (point) (point-max))
835 'face 'mh-show-signature))))))
839 ;;; Button Display
841 ;; Shush compiler.
842 (mh-do-in-xemacs
843 (defvar dots)
844 (defvar type)
845 (defvar ov))
847 (defun mh-insert-mime-button (handle index displayed)
848 "Insert MIME button for HANDLE.
849 INDEX is the part number that will be DISPLAYED. It is also used
850 by commands like \"K v\" which operate on individual MIME parts."
851 ;; The button could be displayed by a previous decode. In that case
852 ;; undisplay it if we need a hidden button.
853 (when (and (mm-handle-displayed-p handle) (not displayed))
854 (mm-display-part handle))
855 (let ((name (or (mail-content-type-get (mm-handle-type handle) 'name)
856 (mail-content-type-get (mm-handle-disposition handle)
857 'filename)
858 (mail-content-type-get (mm-handle-type handle) 'url)
859 ""))
860 (type (mm-handle-media-type handle))
861 (description (mail-decode-encoded-word-string
862 (or (mm-handle-description handle) "")))
863 (dots (if (or displayed (mm-handle-displayed-p handle)) " " "..."))
864 long-type begin end)
865 (if (string-match ".*/" name) (setq name (substring name (match-end 0))))
866 (setq long-type (concat type (and (not (equal name ""))
867 (concat "; " name))))
868 (unless (equal description "")
869 (setq long-type (concat " --- " long-type)))
870 (unless (bolp) (insert "\n"))
871 (setq begin (point))
872 (gnus-eval-format
873 mh-mime-button-line-format mh-mime-button-line-format-alist
874 `(,@(mh-gnus-local-map-property mh-mime-button-map)
875 mh-callback mh-mm-display-part
876 mh-part ,index
877 mh-data ,handle))
878 (setq end (point))
879 (widget-convert-button
880 'link begin end
881 :mime-handle handle
882 :action 'mh-widget-press-button
883 :button-keymap mh-mime-button-map
884 :help-echo
885 "Mouse-2 click or press RET (in show buffer) to toggle display")
886 (dolist (ov (mh-funcall-if-exists overlays-in begin end))
887 (mh-funcall-if-exists overlay-put ov 'evaporate t))))
889 ;; Shush compiler.
890 (defvar mm-verify-function-alist) ; < Emacs 22
891 (defvar mm-decrypt-function-alist) ; < Emacs 22
892 (mh-do-in-xemacs
893 (defvar pressed-details))
895 (defun mh-insert-mime-security-button (handle)
896 "Display buttons for PGP message, HANDLE."
897 (let* ((protocol (mh-mm-handle-multipart-ctl-parameter handle 'protocol))
898 (crypto-type (or (nth 2 (assoc protocol mm-verify-function-alist))
899 (nth 2 (assoc protocol mm-decrypt-function-alist))
900 "Unknown"))
901 (type (concat crypto-type
902 (if (equal (car handle) "multipart/signed")
903 " Signed" " Encrypted")
904 " Part"))
905 (info (or (mh-mm-handle-multipart-ctl-parameter handle 'gnus-info)
906 "Undecided"))
907 (details (mh-mm-handle-multipart-ctl-parameter handle 'gnus-details))
908 pressed-details begin end face)
909 (setq details (if details (concat "\n" details) ""))
910 (setq pressed-details (if mh-mime-security-button-pressed details ""))
911 (setq face (mh-mime-security-button-face info))
912 (unless (bolp) (insert "\n"))
913 (setq begin (point))
914 (gnus-eval-format
915 mh-mime-security-button-line-format
916 mh-mime-security-button-line-format-alist
917 `(,@(mh-gnus-local-map-property mh-mime-security-button-map)
918 mh-button-pressed ,mh-mime-security-button-pressed
919 mh-callback mh-mime-security-press-button
920 mh-line-format ,mh-mime-security-button-line-format
921 mh-data ,handle))
922 (setq end (point))
923 (widget-convert-button 'link begin end
924 :mime-handle handle
925 :action 'mh-widget-press-button
926 :button-keymap mh-mime-security-button-map
927 :button-face face
928 :help-echo "Mouse-2 click or press RET (in show buffer) to see security details.")
929 (dolist (ov (mh-funcall-if-exists overlays-in begin end))
930 (mh-funcall-if-exists overlay-put ov 'evaporate t))
931 (when (equal info "Failed")
932 (let* ((type (if (equal (car handle) "multipart/signed")
933 "verification" "decryption"))
934 (warning (if (equal type "decryption")
935 "(passphrase may be incorrect)" "")))
936 (message "%s %s failed %s" crypto-type type warning)))))
938 (defun mh-mime-security-button-face (info)
939 "Return the button face to use for encrypted/signed mail based on INFO."
940 (cond ((string-match "OK" info) ;Decrypted mail
941 'mh-show-pgg-good)
942 ((string-match "Failed" info) ;Decryption failed or signature invalid
943 'mh-show-pgg-bad)
944 ((string-match "Undecided" info);Unprocessed mail
945 'mh-show-pgg-unknown)
946 ((string-match "Untrusted" info);Key not trusted
947 'mh-show-pgg-unknown)
949 'mh-show-pgg-good)))
953 ;;; Button Handlers
955 (defun mh-folder-mime-action (part-index action include-security-flag)
956 "Go to PART-INDEX and carry out ACTION.
958 If PART-INDEX is nil then go to the next part in the buffer. The
959 search for the next buffer wraps around if end of buffer is reached.
960 If argument INCLUDE-SECURITY-FLAG is non-nil then include security
961 info buttons when searching for a suitable parts."
962 (unless mh-showing-mode
963 (mh-show))
964 (mh-in-show-buffer (mh-show-buffer)
965 (let ((criterion
966 (cond (part-index
967 (lambda (p)
968 (let ((part (get-text-property p 'mh-part)))
969 (and (integerp part) (= part part-index)))))
970 (t (lambda (p)
971 (if include-security-flag
972 (get-text-property p 'mh-data)
973 (integerp (get-text-property p 'mh-part)))))))
974 (point (point)))
975 (cond ((and (get-text-property point 'mh-part)
976 (or (null part-index)
977 (= (get-text-property point 'mh-part) part-index)))
978 (funcall action))
979 ((and (get-text-property point 'mh-data)
980 include-security-flag
981 (null part-index))
982 (funcall action))
984 (mh-goto-next-button nil criterion)
985 (if (= (point) point)
986 (message "No matching MIME part found")
987 (funcall action)))))))
989 ;;;###mh-autoload
990 (defun mh-goto-next-button (backward-flag &optional criterion)
991 "Search for next button satisfying criterion.
993 If BACKWARD-FLAG is non-nil search backward in the buffer for a mime
994 button.
995 If CRITERION is a function or a symbol which has a function binding
996 then that function must return non-nil at the button we stop."
997 (unless (or (and (symbolp criterion) (fboundp criterion))
998 (functionp criterion))
999 (setq criterion (lambda (x) t)))
1000 ;; Move to the next button in the buffer satisfying criterion
1001 (goto-char (or (save-excursion
1002 (beginning-of-line)
1003 ;; Find point before current button
1004 (let ((point-before-current-button
1005 (save-excursion
1006 (while (get-text-property (point) 'mh-data)
1007 (unless (= (forward-line
1008 (if backward-flag 1 -1))
1010 (if backward-flag
1011 (goto-char (point-min))
1012 (goto-char (point-max)))))
1013 (point))))
1014 ;; Skip over current button
1015 (while (and (get-text-property (point) 'mh-data)
1016 (not (if backward-flag (bobp) (eobp))))
1017 (forward-line (if backward-flag -1 1)))
1018 ;; Stop at next MIME button if any exists.
1019 (block loop
1020 (while (/= (progn
1021 (unless (= (forward-line
1022 (if backward-flag -1 1))
1024 (if backward-flag
1025 (goto-char (point-max))
1026 (goto-char (point-min)))
1027 (beginning-of-line))
1028 (point))
1029 point-before-current-button)
1030 (when (and (get-text-property (point) 'mh-data)
1031 (funcall criterion (point)))
1032 (return-from loop (point))))
1033 nil)))
1034 (point))))
1036 (defun mh-widget-press-button (widget el)
1037 "Callback for widget, WIDGET.
1038 Parameter EL is unused."
1039 (goto-char (widget-get widget :from))
1040 (mh-press-button))
1042 (defun mh-press-button ()
1043 "View contents of button.
1045 This command is a toggle so if you use it again on the same
1046 attachment, the attachment is hidden."
1047 (interactive)
1048 (let ((mm-inline-media-tests mh-mm-inline-media-tests)
1049 (data (get-text-property (point) 'mh-data))
1050 (function (get-text-property (point) 'mh-callback))
1051 (buffer-read-only nil)
1052 (folder mh-show-folder-buffer))
1053 (mh-flet
1054 ((mm-handle-set-external-undisplayer
1055 (handle function)
1056 (mh-handle-set-external-undisplayer folder handle function)))
1057 (when (and function (eolp))
1058 (backward-char))
1059 (unwind-protect (and function (funcall function data))
1060 (set-buffer-modified-p nil)))))
1062 (defun mh-push-button (event)
1063 "Click MIME button for EVENT.
1065 If the MIME part is visible then it is removed. Otherwise the
1066 part is displayed. This function is called when the mouse is used
1067 to click the MIME button."
1068 (interactive "e")
1069 (mh-do-at-event-location event
1070 (let ((folder mh-show-folder-buffer)
1071 (mm-inline-media-tests mh-mm-inline-media-tests)
1072 (data (get-text-property (point) 'mh-data))
1073 (function (get-text-property (point) 'mh-callback)))
1074 (mh-flet
1075 ((mm-handle-set-external-undisplayer
1076 (handle func)
1077 (mh-handle-set-external-undisplayer folder handle func)))
1078 (and function (funcall function data))))))
1080 (defun mh-handle-set-external-undisplayer (folder handle function)
1081 "Replacement for `mm-handle-set-external-undisplayer'.
1083 This is only called in recent versions of Gnus. The MIME handles
1084 are stored in data structures corresponding to MH-E folder buffer
1085 FOLDER instead of in Gnus (as in the original). The MIME part,
1086 HANDLE is associated with the undisplayer FUNCTION."
1087 (if (mh-mm-keep-viewer-alive-p handle)
1088 (let ((new-handle (copy-sequence handle)))
1089 (mm-handle-set-undisplayer new-handle function)
1090 (mm-handle-set-undisplayer handle nil)
1091 (with-current-buffer folder
1092 (push new-handle (mh-mime-handles (mh-buffer-data)))))
1093 (mm-handle-set-undisplayer handle function)))
1095 (defun mh-mime-security-press-button (handle)
1096 "Callback from security button for part HANDLE."
1097 (if (mh-mm-handle-multipart-ctl-parameter handle 'gnus-info)
1098 (mh-mime-security-show-details handle)
1099 (let ((region (mh-mm-handle-multipart-ctl-parameter handle 'mh-region))
1100 point)
1101 (setq point (point))
1102 (goto-char (car region))
1103 (delete-region (car region) (cdr region))
1104 (with-current-buffer (mh-mm-handle-multipart-ctl-parameter handle 'buffer)
1105 (let* ((mm-verify-option 'known)
1106 (mm-decrypt-option 'known)
1107 (new (mh-mm-possibly-verify-or-decrypt (cdr handle) handle)))
1108 (unless (eq new (cdr handle))
1109 (mh-mm-destroy-parts (cdr handle))
1110 (setcdr handle new))))
1111 (mh-mime-display-security handle)
1112 (goto-char point))))
1114 ;; I rewrote the security part because Gnus doesn't seem to ever minimize
1115 ;; the button. That is once the mime-security button is pressed there seems
1116 ;; to be no way of getting rid of the inserted text.
1117 (defun mh-mime-security-show-details (handle)
1118 "Toggle display of detailed security info for HANDLE."
1119 (let ((details (mh-mm-handle-multipart-ctl-parameter handle 'gnus-details)))
1120 (when details
1121 (let ((mh-mime-security-button-pressed
1122 (not (get-text-property (point) 'mh-button-pressed)))
1123 (mh-mime-security-button-line-format
1124 (get-text-property (point) 'mh-line-format)))
1125 (forward-char -1)
1126 (while (eq (get-text-property (point) 'mh-line-format)
1127 mh-mime-security-button-line-format)
1128 (forward-char -1))
1129 (forward-char)
1130 (save-restriction
1131 (narrow-to-region (point) (point))
1132 (mh-insert-mime-security-button handle))
1133 (delete-region
1134 (point)
1135 (or (text-property-not-all
1136 (point) (point-max)
1137 'mh-line-format mh-mime-security-button-line-format)
1138 (point-max)))
1139 (forward-line -1)))))
1143 ;;; Miscellaneous Article Washing
1145 ;;;###mh-autoload
1146 (defun mh-add-missing-mime-version-header ()
1147 "Some mail programs don't put a MIME-Version header.
1148 I have seen this only in spam, so maybe we shouldn't fix
1149 this ;-)"
1150 (save-excursion
1151 (goto-char (point-min))
1152 (re-search-forward "\n\n" nil t)
1153 (save-restriction
1154 (narrow-to-region (point-min) (point))
1155 (when (and (message-fetch-field "content-type")
1156 (not (message-fetch-field "mime-version")))
1157 (goto-char (point-min))
1158 (insert "MIME-Version: 1.0\n")))))
1160 ;;;###mh-autoload
1161 (defun mh-display-smileys ()
1162 "Display smileys."
1163 (when (and mh-graphical-smileys-flag (mh-small-show-buffer-p))
1164 (mh-funcall-if-exists smiley-region (point-min) (point-max))))
1166 ;;;###mh-autoload
1167 (defun mh-display-emphasis ()
1168 "Display graphical emphasis."
1169 (when (and mh-graphical-emphasis-flag (mh-small-show-buffer-p))
1170 (mh-flet
1171 ((article-goto-body ())) ; shadow this function to do nothing
1172 (save-excursion
1173 (goto-char (point-min))
1174 (article-emphasize)))))
1176 (defun mh-small-show-buffer-p ()
1177 "Check if show buffer is small.
1178 This is used to decide if smileys and graphical emphasis should be
1179 displayed."
1180 (let ((max nil))
1181 (when (and (boundp 'font-lock-maximum-size) font-lock-maximum-size)
1182 (cond ((numberp font-lock-maximum-size)
1183 (setq max font-lock-maximum-size))
1184 ((listp font-lock-maximum-size)
1185 (setq max (cdr (or (assoc 'mh-show-mode font-lock-maximum-size)
1186 (assoc t font-lock-maximum-size)))))))
1187 (or (not (numberp max)) (>= (/ max 8) (buffer-size)))))
1191 ;;; MH-Letter Commands
1193 ;; MH-E commands are alphabetical; specific support routines follow command.
1195 ;;;###mh-autoload
1196 (defun mh-compose-forward (&optional description folder range)
1197 "Add tag to forward a message.
1199 You are prompted for a content DESCRIPTION, the name of the
1200 FOLDER in which the messages to forward are located, and a RANGE
1201 of messages, which defaults to the current message in that
1202 folder. Check the documentation of `mh-interactive-range' to see
1203 how RANGE is read in interactive use.
1205 The option `mh-compose-insertion' controls what type of tags are inserted."
1206 (interactive
1207 (let* ((description
1208 (mml-minibuffer-read-description))
1209 (folder
1210 (mh-prompt-for-folder "Message from"
1211 mh-sent-from-folder nil))
1212 (default
1213 (if (and (equal folder mh-sent-from-folder)
1214 (numberp mh-sent-from-msg))
1215 mh-sent-from-msg
1216 (nth 0 (mh-translate-range folder "cur"))))
1217 (range
1218 (mh-read-range "Forward" folder
1219 (or (and default
1220 (number-to-string default))
1222 t t)))
1223 (list description folder range)))
1224 (let ((messages (mapconcat 'identity (mh-list-to-string range) " ")))
1225 (dolist (message (mh-translate-range folder messages))
1226 (if (equal mh-compose-insertion 'mml)
1227 (mh-mml-forward-message description folder (format "%s" message))
1228 (mh-mh-forward-message description folder (format "%s" message))))))
1230 ;;;###mh-autoload
1231 (defun mh-mml-forward-message (description folder message)
1232 "Forward a message as attachment.
1234 The function will prompt the user for a DESCRIPTION, a FOLDER and
1235 MESSAGE number."
1236 (let ((msg (if (and (equal message "") (numberp mh-sent-from-msg))
1237 mh-sent-from-msg
1238 (string-to-number message))))
1239 (cond ((integerp msg)
1240 (mml-attach-file (format "%s%s/%d"
1241 mh-user-path (substring folder 1) msg)
1242 "message/rfc822"
1243 (if (string= "" description) nil description)
1244 "inline"))
1245 (t (error "The message number, %s, is not an integer" msg)))))
1247 (defun mh-mh-forward-message (&optional description folder messages)
1248 "Add tag to forward a message.
1249 You are prompted for a content DESCRIPTION, the name of the
1250 FOLDER in which the messages to forward are located, and the
1251 MESSAGES' numbers.
1253 See also \\[mh-mh-to-mime]."
1254 (interactive (list
1255 (mml-minibuffer-read-description)
1256 (mh-prompt-for-folder "Message from" mh-sent-from-folder nil)
1257 (read-string (concat "Messages"
1258 (if (numberp mh-sent-from-msg)
1259 (format " (default %d): "
1260 mh-sent-from-msg)
1261 ": ")))))
1262 (beginning-of-line)
1263 (insert "#forw [")
1264 (and description
1265 (not (string= description ""))
1266 (insert description))
1267 (insert "]")
1268 (and folder
1269 (not (string= folder ""))
1270 (insert " " folder))
1271 (if (and messages
1272 (not (string= messages "")))
1273 (let ((start (point)))
1274 (insert " " messages)
1275 (subst-char-in-region start (point) ?, ? ))
1276 (if (numberp mh-sent-from-msg)
1277 (insert " " (int-to-string mh-sent-from-msg))))
1278 (insert "\n"))
1280 ;;;###mh-autoload
1281 (defun mh-compose-insertion (&optional inline)
1282 "Add tag to include a file such as an image or sound.
1284 You are prompted for the filename containing the object, the
1285 media type if it cannot be determined automatically, and a
1286 content description. If you're using MH-style directives, you
1287 will also be prompted for additional attributes.
1289 The option `mh-compose-insertion' controls what type of tags are
1290 inserted. Optional argument INLINE means make it an inline
1291 attachment."
1292 (interactive "P")
1293 (if (equal mh-compose-insertion 'mml)
1294 (if inline
1295 (mh-mml-attach-file "inline")
1296 (mh-mml-attach-file))
1297 (call-interactively 'mh-mh-attach-file)))
1299 (defun mh-mml-attach-file (&optional disposition)
1300 "Add a tag to insert a MIME message part from a file.
1302 You are prompted for the filename containing the object, the
1303 media type if it cannot be determined automatically, a content
1304 description and the DISPOSITION of the attachment.
1306 This is basically `mml-attach-file' from Gnus, modified such that a prefix
1307 argument yields an \"inline\" disposition and Content-Type is determined
1308 automatically."
1309 (let* ((file (mml-minibuffer-read-file "Attach file: "))
1310 (type (mh-minibuffer-read-type file))
1311 (description (mml-minibuffer-read-description))
1312 (dispos (or disposition
1313 (mh-mml-minibuffer-read-disposition type))))
1314 (mml-insert-empty-tag 'part 'type type 'filename file
1315 'disposition dispos 'description description)))
1317 (defun mh-mh-attach-file (filename type description attributes)
1318 "Add a tag to insert a MIME message part from a file.
1319 You are prompted for the FILENAME containing the object, the
1320 media TYPE if it cannot be determined automatically, and a
1321 content DESCRIPTION. In addition, you are also prompted for
1322 additional ATTRIBUTES.
1324 See also \\[mh-mh-to-mime]."
1325 (interactive (let ((filename (mml-minibuffer-read-file "Attach file: ")))
1326 (list
1327 filename
1328 (mh-minibuffer-read-type filename)
1329 (mml-minibuffer-read-description)
1330 (read-string "Attributes: "
1331 (concat "name=\""
1332 (file-name-nondirectory filename)
1333 "\"")))))
1334 (mh-mh-compose-type filename type description attributes))
1336 (defun mh-mh-compose-type (filename type
1337 &optional description attributes comment)
1338 "Insert an MH-style directive to insert a file.
1339 The file specified by FILENAME is encoded as TYPE. An optional
1340 DESCRIPTION is used as the Content-Description field, optional
1341 set of ATTRIBUTES and an optional COMMENT can also be included."
1342 (beginning-of-line)
1343 (insert "#" type)
1344 (and attributes
1345 (insert "; " attributes))
1346 (and comment
1347 (insert " (" comment ")"))
1348 (insert " [")
1349 (and description
1350 (insert description))
1351 (insert "] " (expand-file-name filename))
1352 (insert "\n"))
1354 ;;;###mh-autoload
1355 (defun mh-mh-compose-anon-ftp (host filename type description)
1356 "Add tag to include anonymous ftp reference to a file.
1358 You can have your message initiate an \"ftp\" transfer when the
1359 recipient reads the message. You are prompted for the remote HOST
1360 and FILENAME, the media TYPE, and the content DESCRIPTION.
1362 See also \\[mh-mh-to-mime]."
1363 (interactive (list
1364 (read-string "Remote host: ")
1365 (read-string "Remote filename: ")
1366 (mh-minibuffer-read-type "DUMMY-FILENAME")
1367 (mml-minibuffer-read-description)))
1368 (mh-mh-compose-external-type "anon-ftp" host filename
1369 type description))
1371 ;;;###mh-autoload
1372 (defun mh-mh-compose-external-compressed-tar (host filename description)
1373 "Add tag to include anonymous ftp reference to a compressed tar file.
1375 In addition to retrieving the file via anonymous \"ftp\" as per
1376 the command \\[mh-mh-compose-anon-ftp], the file will also be
1377 uncompressed and untarred. You are prompted for the remote HOST
1378 and FILENAME and the content DESCRIPTION.
1380 See also \\[mh-mh-to-mime]."
1381 (interactive (list
1382 (read-string "Remote host: ")
1383 (read-string "Remote filename: ")
1384 (mml-minibuffer-read-description)))
1385 (mh-mh-compose-external-type "anon-ftp" host filename
1386 "application/octet-stream"
1387 description
1388 "type=tar; conversions=x-compress"
1389 "mode=image"))
1391 ;; RFC 2045 - Multipurpose Internet Mail Extensions (MIME) Part One:
1392 ;; Format of Internet Message Bodies.
1393 ;; RFC 2046 - Multipurpose Internet Mail Extensions (MIME) Part Two:
1394 ;; Media Types.
1395 ;; RFC 2049 - Multipurpose Internet Mail Extensions (MIME) Part Five:
1396 ;; Conformance Criteria and Examples.
1397 ;; RFC 2017 - Definition of the URL MIME External-Body Access-Type
1398 ;; RFC 1738 - Uniform Resource Locators (URL)
1399 (defvar mh-access-types
1400 '(("anon-ftp") ; RFC2046 Anonymous File Transfer Protocol
1401 ("file") ; RFC1738 Host-specific file names
1402 ("ftp") ; RFC2046 File Transfer Protocol
1403 ("gopher") ; RFC1738 The Gopher Protocol
1404 ("http") ; RFC1738 Hypertext Transfer Protocol
1405 ("local-file") ; RFC2046 Local file access
1406 ("mail-server") ; RFC2046 mail-server Electronic mail address
1407 ("mailto") ; RFC1738 Electronic mail address
1408 ("news") ; RFC1738 Usenet news
1409 ("nntp") ; RFC1738 Usenet news using NNTP access
1410 ("prospero") ; RFC1738 Prospero Directory Service
1411 ("telnet") ; RFC1738 Telnet
1412 ("tftp") ; RFC2046 Trivial File Transfer Protocol
1413 ("url") ; RFC2017 URL scheme MIME access-type Protocol
1414 ("wais")) ; RFC1738 Wide Area Information Servers
1415 "Valid MIME access-type values.")
1417 ;;;###mh-autoload
1418 (defun mh-mh-compose-external-type (access-type host filename type
1419 &optional description
1420 attributes parameters
1421 comment)
1422 "Add tag to refer to a remote file.
1424 This command is a general utility for referencing external files.
1425 In fact, all of the other commands that insert directives to
1426 access external files call this command. You are prompted for the
1427 ACCESS-TYPE, remote HOST and FILENAME, and content TYPE. If you
1428 provide a prefix argument, you are also prompted for a content
1429 DESCRIPTION, ATTRIBUTES, PARAMETERS, and a COMMENT.
1431 See also \\[mh-mh-to-mime]."
1432 (interactive (list
1433 (completing-read "Access type: " mh-access-types)
1434 (read-string "Remote host: ")
1435 (read-string "Remote filename: ")
1436 (mh-minibuffer-read-type "DUMMY-FILENAME")
1437 (if current-prefix-arg (mml-minibuffer-read-description))
1438 (if current-prefix-arg (read-string "Attributes: "))
1439 (if current-prefix-arg (read-string "Parameters: "))
1440 (if current-prefix-arg (read-string "Comment: "))))
1441 (beginning-of-line)
1442 (insert "#@" type)
1443 (and attributes
1444 (insert "; " attributes))
1445 (and comment
1446 (insert " (" comment ") "))
1447 (insert " [")
1448 (and description
1449 (insert description))
1450 (insert "] ")
1451 (insert "access-type=" access-type "; ")
1452 (insert "site=" host)
1453 (insert "; name=" (file-name-nondirectory filename))
1454 (let ((directory (file-name-directory filename)))
1455 (and directory
1456 (insert "; directory=\"" directory "\"")))
1457 (and parameters
1458 (insert "; " parameters))
1459 (insert "\n"))
1461 (defvar mh-mh-to-mime-args nil
1462 "Extra arguments for \\[mh-mh-to-mime] to pass to the \"mhbuild\" command.
1463 The arguments are passed to \"mhbuild\" if \\[mh-mh-to-mime] is
1464 given a prefix argument. Normally default arguments to
1465 \"mhbuild\" are specified in the MH profile.")
1467 ;;;###mh-autoload
1468 (defun mh-mh-to-mime (&optional extra-args)
1469 "Compose MIME message from MH-style directives.
1471 Typically, you send a message with attachments just like any other
1472 message. However, you may take a sneak preview of the MIME encoding if
1473 you wish by running this command.
1475 If you wish to pass additional arguments to \"mhbuild\" (\"mhn\")
1476 to affect how it builds your message, use the option
1477 `mh-mh-to-mime-args'. For example, you can build a consistency
1478 check into the message by setting `mh-mh-to-mime-args' to
1479 \"-check\". The recipient of your message can then run \"mhbuild
1480 -check\" on the message--\"mhbuild\" (\"mhn\") will complain if
1481 the message has been corrupted on the way. This command only
1482 consults this option when given a prefix argument EXTRA-ARGS.
1484 The hook `mh-mh-to-mime-hook' is called after the message has been
1485 formatted.
1487 The effects of this command can be undone by running
1488 \\[mh-mh-to-mime-undo]."
1489 (interactive "*P")
1490 (mh-mh-quote-unescaped-sharp)
1491 (save-buffer)
1492 (message "Running %s..." (if (mh-variant-p 'nmh) "mhbuild" "mhn"))
1493 (cond
1494 ((mh-variant-p 'nmh)
1495 (mh-exec-cmd-error nil
1496 "mhbuild"
1497 (if extra-args mh-mh-to-mime-args)
1498 buffer-file-name))
1500 (mh-exec-cmd-error (format "mhdraft=%s" buffer-file-name)
1501 "mhn"
1502 (if extra-args mh-mh-to-mime-args)
1503 buffer-file-name)))
1504 (revert-buffer t t t)
1505 (message "Running %s...done" (if (mh-variant-p 'nmh) "mhbuild" "mhn"))
1506 (run-hooks 'mh-mh-to-mime-hook))
1508 (defun mh-mh-quote-unescaped-sharp ()
1509 "Quote \"#\" characters that haven't been quoted for \"mhbuild\".
1510 If the \"#\" character is present in the first column, but it isn't
1511 part of a MH-style directive then \"mhbuild\" gives an error.
1512 This function will quote all such characters."
1513 (save-excursion
1514 (goto-char (point-min))
1515 (while (re-search-forward "^#" nil t)
1516 (beginning-of-line)
1517 (unless (mh-mh-directive-present-p (point) (mh-line-end-position))
1518 (insert "#"))
1519 (goto-char (mh-line-end-position)))))
1521 ;;;###mh-autoload
1522 (defun mh-mh-to-mime-undo (noconfirm)
1523 "Undo effects of \\[mh-mh-to-mime].
1525 It does this by reverting to a backup file. You are prompted to
1526 confirm this action, but you can avoid the confirmation by adding
1527 a prefix argument NOCONFIRM."
1528 (interactive "*P")
1529 (if (null buffer-file-name)
1530 (error "Buffer does not seem to be associated with any file"))
1531 (let ((backup-strings '("," "#"))
1532 backup-file)
1533 (while (and backup-strings
1534 (not (file-exists-p
1535 (setq backup-file
1536 (concat (file-name-directory buffer-file-name)
1537 (car backup-strings)
1538 (file-name-nondirectory buffer-file-name)
1539 ".orig")))))
1540 (setq backup-strings (cdr backup-strings)))
1541 (or backup-strings
1542 (error "Backup file for %s no longer exists" buffer-file-name))
1543 (or noconfirm
1544 (yes-or-no-p (format "Revert buffer from file %s? "
1545 backup-file))
1546 (error "Revert not confirmed"))
1547 (let ((buffer-read-only nil))
1548 (erase-buffer)
1549 (insert-file-contents backup-file))
1550 (after-find-file nil nil nil nil t)))
1552 ;; Shush compiler.
1553 (defvar mh-identity-pgg-default-user-id)
1555 ;;;###mh-autoload
1556 (defun mh-mml-secure-message-encrypt (method)
1557 "Add tag to encrypt the message.
1559 A proper multipart message is created for you when you send the
1560 message. Use the command \\[mh-mml-unsecure-message] to remove
1561 this tag. Use a prefix argument METHOD to be prompted for one of
1562 the possible security methods (see `mh-mml-method-default')."
1563 (interactive (list (mh-mml-query-cryptographic-method)))
1564 (mh-secure-message method "encrypt" mh-identity-pgg-default-user-id))
1566 ;;;###mh-autoload
1567 (defun mh-mml-secure-message-sign (method)
1568 "Add tag to sign the message.
1570 A proper multipart message is created for you when you send the
1571 message. Use the command \\[mh-mml-unsecure-message] to remove
1572 this tag. Use a prefix argument METHOD to be prompted for one of
1573 the possible security methods (see `mh-mml-method-default')."
1574 (interactive (list (mh-mml-query-cryptographic-method)))
1575 (mh-secure-message method "sign" mh-identity-pgg-default-user-id))
1577 ;;;###mh-autoload
1578 (defun mh-mml-secure-message-signencrypt (method)
1579 "Add tag to encrypt and sign the message.
1581 A proper multipart message is created for you when you send the
1582 message. Use the command \\[mh-mml-unsecure-message] to remove
1583 this tag. Use a prefix argument METHOD to be prompted for one of
1584 the possible security methods (see `mh-mml-method-default')."
1585 (interactive (list (mh-mml-query-cryptographic-method)))
1586 (mh-secure-message method "signencrypt" mh-identity-pgg-default-user-id))
1588 (defvar mh-mml-cryptographic-method-history ())
1590 (defun mh-mml-query-cryptographic-method ()
1591 "Read the cryptographic method to use."
1592 (if current-prefix-arg
1593 (let ((def (or (car mh-mml-cryptographic-method-history)
1594 mh-mml-method-default)))
1595 (completing-read (format "Method (default %s): " def)
1596 '(("pgp") ("pgpmime") ("smime"))
1597 nil t nil 'mh-mml-cryptographic-method-history def))
1598 mh-mml-method-default))
1600 (defun mh-secure-message (method mode &optional identity)
1601 "Add tag to encrypt or sign message.
1603 METHOD should be one of: \"pgpmime\", \"pgp\", \"smime\".
1604 MODE should be one of: \"sign\", \"encrypt\", \"signencrypt\", \"none\".
1605 IDENTITY is optionally the default-user-id to use."
1606 (if (not mh-pgp-support-flag)
1607 (error "Your version of Gnus does not support PGP/GPG")
1608 ;; Check the arguments
1609 (let ((valid-methods (list "pgpmime" "pgp" "smime"))
1610 (valid-modes (list "sign" "encrypt" "signencrypt" "none")))
1611 (if (not (member method valid-methods))
1612 (error "Method %s is invalid" method))
1613 (if (not (member mode valid-modes))
1614 (error "Mode %s is invalid" mode))
1615 (mml-unsecure-message)
1616 (if (not (string= mode "none"))
1617 (save-excursion
1618 (goto-char (point-min))
1619 (mh-goto-header-end 1)
1620 (if mh-identity-pgg-default-user-id
1621 (mml-insert-tag 'secure 'method method 'mode mode
1622 'sender mh-identity-pgg-default-user-id)
1623 (mml-insert-tag 'secure 'method method 'mode mode)))))))
1625 ;;;###mh-autoload
1626 (defun mh-mml-to-mime ()
1627 "Compose MIME message from MML tags.
1629 Typically, you send a message with attachments just like any
1630 other message. However, you may take a sneak preview of the MIME
1631 encoding if you wish by running this command.
1633 This action can be undone by running \\[undo]."
1634 (interactive)
1635 (require 'message)
1636 (when mh-pgp-support-flag
1637 ;; PGP requires actual e-mail addresses, not aliases.
1638 ;; Parse the recipients and sender from the message.
1639 (message-options-set-recipient)
1640 ;; Do an alias lookup on sender (if From field is present).
1641 (when (message-options-get 'message-sender)
1642 (message-options-set 'message-sender
1643 (mail-strip-quoted-names
1644 (mh-alias-expand
1645 (message-options-get 'message-sender)))))
1646 ;; Do an alias lookup on recipients
1647 (message-options-set 'message-recipients
1648 (mapconcat
1649 (lambda (ali)
1650 (mail-strip-quoted-names (mh-alias-expand ali)))
1651 (split-string (message-options-get 'message-recipients) "[, ]+")
1652 ", ")))
1653 (let ((saved-text (buffer-string))
1654 (buffer (current-buffer))
1655 (modified-flag (buffer-modified-p)))
1656 (condition-case err (mml-to-mime)
1657 (error
1658 (with-current-buffer buffer
1659 (delete-region (point-min) (point-max))
1660 (insert saved-text)
1661 (set-buffer-modified-p modified-flag))
1662 (error (error-message-string err))))))
1664 ;;;###mh-autoload
1665 (defun mh-mml-unsecure-message ()
1666 "Remove any secure message tags."
1667 (interactive)
1668 (if (not mh-pgp-support-flag)
1669 (error "Your version of Gnus does not support PGP/GPG")
1670 (mml-unsecure-message)))
1674 ;;; Support Routines for MH-Letter Commands
1676 ;;;###mh-autoload
1677 (defun mh-mml-tag-present-p ()
1678 "Check if the current buffer has text which may be a MML tag."
1679 (save-excursion
1680 (goto-char (point-min))
1681 (re-search-forward
1682 (concat
1683 "\\(<#\\(mml\\|part\\)\\(.\\|\n\\)*>[ \n\t]*<#/\\(mml\\|part\\)>\\|"
1684 "^<#secure.+>$\\)")
1685 nil t)))
1687 (defvar mh-media-type-regexp
1688 (concat (regexp-opt '("text" "image" "audio" "video" "application"
1689 "multipart" "message") t)
1690 "/[-.+a-zA-Z0-9]+")
1691 "Regexp matching valid media types used in MIME attachment compositions.")
1693 ;;;###mh-autoload
1694 (defun mh-mh-directive-present-p (&optional begin end)
1695 "Check if the text between BEGIN and END might be a MH-style directive.
1696 The optional argument BEGIN defaults to the beginning of the
1697 buffer, while END defaults to the end of the buffer."
1698 (unless begin (setq begin (point-min)))
1699 (unless end (setq end (point-max)))
1700 (save-excursion
1701 (block search-for-mh-directive
1702 (goto-char begin)
1703 (while (re-search-forward "^#" end t)
1704 (let ((s (buffer-substring-no-properties
1705 (point) (mh-line-end-position))))
1706 (cond ((equal s ""))
1707 ((string-match "^forw[ \t\n]+" s)
1708 (return-from search-for-mh-directive t))
1709 (t (let ((first-token (car (split-string s "[ \t;@]"))))
1710 (when (and first-token
1711 (string-match mh-media-type-regexp
1712 first-token))
1713 (return-from search-for-mh-directive t)))))))
1714 nil)))
1716 (defun mh-minibuffer-read-type (filename &optional default)
1717 "Return the content type associated with the given FILENAME.
1718 If the \"file\" command exists and recognizes the given file,
1719 then its value is returned; otherwise, the user is prompted for
1720 a type (see `mailcap-mime-types').
1721 Optional argument DEFAULT is returned if a type isn't entered."
1722 (mailcap-parse-mimetypes)
1723 (let* ((default (or default
1724 (mm-default-file-encoding filename)
1725 "application/octet-stream"))
1726 (probed-type (mh-file-mime-type filename))
1727 (type (or (and (not (equal probed-type "application/octet-stream"))
1728 probed-type)
1729 (completing-read
1730 (format "Content type (default %s): " default)
1731 (mapcar 'list (mailcap-mime-types))))))
1732 (if (not (equal type ""))
1733 type
1734 default)))
1736 ;;;###mh-autoload
1737 (defun mh-file-mime-type (filename)
1738 "Return MIME type of FILENAME from file command.
1739 Returns nil if file command not on system."
1740 (cond
1741 ((not (mh-have-file-command))
1742 nil) ;no file command, exit now
1743 ((not (and (file-exists-p filename)
1744 (file-readable-p filename)))
1745 nil) ;no file or not readable, ditto
1747 (let ((tmp-buffer (get-buffer-create mh-temp-buffer)))
1748 (with-current-buffer tmp-buffer
1749 (unwind-protect
1750 (progn
1751 (call-process "file" nil '(t nil) nil "-b" "-i"
1752 (expand-file-name filename))
1753 (goto-char (point-min))
1754 (if (not (re-search-forward mh-media-type-regexp nil t))
1756 (mh-file-mime-type-substitute (match-string 0) filename)))
1757 (kill-buffer tmp-buffer)))))))
1759 (defvar mh-file-mime-type-substitutions
1760 '(("application/msword" "\\.xls" "application/ms-excel")
1761 ("application/msword" "\\.ppt" "application/ms-powerpoint")
1762 ("text/plain" "\\.vcf" "text/x-vcard")
1763 ("text/rtf" "\\.rtf" "application/rtf")
1764 ("application/x-zip" "\\.sxc" "application/vnd.sun.xml.calc")
1765 ("application/x-zip" "\\.sxd" "application/vnd.sun.xml.draw")
1766 ("application/x-zip" "\\.sxi" "application/vnd.sun.xml.impress")
1767 ("application/x-zip" "\\.sxw" "application/vnd.sun.xml.writer")
1768 ("application/x-zip" "\\.odg" "application/vnd.oasis.opendocument.graphics")
1769 ("application/x-zip" "\\.odi" "application/vnd.oasis.opendocument.image")
1770 ("application/x-zip" "\\.odp"
1771 "application/vnd.oasis.opendocument.presentation")
1772 ("application/x-zip" "\\.ods"
1773 "application/vnd.oasis.opendocument.spreadsheet")
1774 ("application/x-zip" "\\.odt" "application/vnd.oasis.opendocument.text"))
1775 "Substitutions to make for Content-Type returned from file command.
1776 The first element is the Content-Type returned by the file command.
1777 The second element is a regexp matching the file name, usually the
1778 extension.
1779 The third element is the Content-Type to replace with.")
1781 (defun mh-file-mime-type-substitute (content-type filename)
1782 "Return possibly changed CONTENT-TYPE on the FILENAME.
1783 Substitutions are made from the `mh-file-mime-type-substitutions'
1784 variable."
1785 (let ((subst mh-file-mime-type-substitutions)
1786 (type) (match) (answer content-type)
1787 (case-fold-search t))
1788 (while subst
1789 (setq type (car (car subst))
1790 match (elt (car subst) 1))
1791 (if (and (string-equal content-type type)
1792 (string-match match filename))
1793 (setq answer (elt (car subst) 2)
1794 subst nil)
1795 (setq subst (cdr subst))))
1796 answer))
1798 (defvar mh-have-file-command 'undefined
1799 "Cached value of function `mh-have-file-command'.
1800 Do not reference this variable directly as it might not have been
1801 initialized. Always use the command `mh-have-file-command'.")
1803 ;;;###mh-autoload
1804 (defun mh-have-file-command ()
1805 "Return t if `file' command is on the system.
1806 'file -i' is used to get MIME type of composition insertion."
1807 (when (eq mh-have-file-command 'undefined)
1808 (setq mh-have-file-command
1809 (and (fboundp 'executable-find)
1810 (executable-find "file") ; file command exists
1811 ; and accepts -i and -b args.
1812 (zerop (call-process "file" nil nil nil "-i" "-b"
1813 (expand-file-name "inc" mh-progs))))))
1814 mh-have-file-command)
1818 ;;; MIME Cleanup
1820 ;;;###mh-autoload
1821 (defun mh-mime-cleanup ()
1822 "Free the decoded MIME parts."
1823 (let ((mime-data (gethash (current-buffer) mh-globals-hash)))
1824 ;; This is for Emacs, what about XEmacs?
1825 (mh-funcall-if-exists remove-images (point-min) (point-max))
1826 (when mime-data
1827 (mh-mm-destroy-parts (mh-mime-handles mime-data))
1828 (remhash (current-buffer) mh-globals-hash))))
1830 ;;;###mh-autoload
1831 (defun mh-destroy-postponed-handles ()
1832 "Free MIME data for externally displayed MIME parts."
1833 (let ((mime-data (mh-buffer-data)))
1834 (when mime-data
1835 (mh-mm-destroy-parts (mh-mime-handles mime-data)))
1836 (remhash (current-buffer) mh-globals-hash)))
1838 (provide 'mh-mime)
1840 ;; Local Variables:
1841 ;; indent-tabs-mode: nil
1842 ;; sentence-end-double-space: nil
1843 ;; End:
1845 ;;; mh-mime.el ends here