1 ;;; mm-decode.el --- Functions for decoding MIME things
3 ;; Copyright (C) 1998-2012 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; For Emacs <22.2 and XEmacs.
28 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
32 (eval-when-compile (require 'cl)
35 (autoload 'gnus-map-function "gnus-util")
36 (autoload 'gnus-replace-in-string "gnus-util")
37 (autoload 'gnus-read-shell-command "gnus-util")
39 (autoload 'mm-inline-partial "mm-partial")
40 (autoload 'mm-inline-external-body "mm-extern")
41 (autoload 'mm-extern-cache-contents "mm-extern")
42 (autoload 'mm-insert-inline "mm-view")
44 (autoload 'mm-archive-decoders "mm-archive")
45 (autoload 'mm-archive-dissect-and-inline "mm-archive")
46 (autoload 'mm-dissect-archive "mm-archive")
48 (defvar gnus-current-window-configuration)
50 (add-hook 'gnus-exit-gnus-hook 'mm-destroy-postponed-undisplay-list)
52 (defgroup mime-display ()
53 "Display of MIME in mail and news articles."
54 :link '(custom-manual "(emacs-mime)Display Customization")
60 (defgroup mime-security ()
61 "MIME security in mail and news articles."
62 :link '(custom-manual "(emacs-mime)Display Customization")
67 ;;; Convenience macros.
69 (defmacro mm-handle-buffer (handle)
71 (defmacro mm-handle-type (handle)
73 (defsubst mm-handle-media-type (handle)
74 (if (stringp (car handle))
76 (car (mm-handle-type handle))))
77 (defsubst mm-handle-media-supertype (handle)
78 (car (split-string (mm-handle-media-type handle) "/")))
79 (defsubst mm-handle-media-subtype (handle)
80 (cadr (split-string (mm-handle-media-type handle) "/")))
81 (defmacro mm-handle-encoding (handle)
83 (defmacro mm-handle-undisplayer (handle)
85 (defmacro mm-handle-set-undisplayer (handle function)
86 `(setcar (nthcdr 3 ,handle) ,function))
87 (defmacro mm-handle-disposition (handle)
89 (defmacro mm-handle-description (handle)
91 (defmacro mm-handle-cache (handle)
93 (defmacro mm-handle-set-cache (handle contents)
94 `(setcar (nthcdr 6 ,handle) ,contents))
95 (defmacro mm-handle-id (handle)
97 (defmacro mm-handle-multipart-original-buffer (handle)
98 `(get-text-property 0 'buffer (car ,handle)))
99 (defmacro mm-handle-multipart-from (handle)
100 `(get-text-property 0 'from (car ,handle)))
101 (defmacro mm-handle-multipart-ctl-parameter (handle parameter)
102 `(get-text-property 0 ,parameter (car ,handle)))
104 (defmacro mm-make-handle (&optional buffer type encoding undisplayer
105 disposition description cache
107 `(list ,buffer ,type ,encoding ,undisplayer
108 ,disposition ,description ,cache ,id))
110 (defcustom mm-text-html-renderer
111 (cond ((fboundp 'libxml-parse-html-region) 'shr)
112 ((executable-find "w3m") 'gnus-w3m)
113 ((executable-find "links") 'links)
114 ((executable-find "lynx") 'lynx)
115 ((locate-library "w3") 'w3)
116 ((locate-library "html2text") 'html2text)
118 "Render of HTML contents.
119 It is one of defined renderer types, or a rendering function.
120 The defined renderer types are:
121 `shr': use the built-in Gnus HTML renderer;
122 `gnus-w3m': use Gnus renderer based on w3m;
123 `w3m': use emacs-w3m;
124 `w3m-standalone': use plain w3m;
128 `html2text': use html2text;
129 nil : use external viewer (default web browser)."
131 :type '(choice (const shr)
134 (const w3m :tag "emacs-w3m")
135 (const w3m-standalone :tag "standalone w3m" )
139 (const nil :tag "External viewer")
141 :group 'mime-display)
143 (defcustom mm-inline-text-html-with-images nil
144 "If non-nil, Gnus will allow retrieving images in HTML contents with
145 the <img> tags. It has no effect on Emacs/w3. See also the
146 documentation for the `mm-w3m-safe-url-regexp' variable."
149 :group 'mime-display)
151 (defcustom mm-w3m-safe-url-regexp "\\`cid:"
152 "Regexp matching URLs which are considered to be safe.
153 Some HTML mails might contain a nasty trick used by spammers, using
154 the <img> tag which is far more evil than the [Click Here!] button.
155 It is most likely intended to check whether the ominous spam mail has
156 reached your eyes or not, in which case the spammer knows for sure
157 that your email address is valid. It is done by embedding an
158 identifier string into a URL that you might automatically retrieve
159 when displaying the image. The default value is \"\\\\`cid:\" which only
160 matches parts embedded to the Multipart/Related type MIME contents and
161 Gnus will never connect to the spammer's site arbitrarily. You may
162 set this variable to nil if you consider all urls to be safe."
164 :type '(choice (regexp :tag "Regexp")
165 (const :tag "All URLs are safe" nil))
166 :group 'mime-display)
168 (defcustom mm-inline-text-html-with-w3m-keymap t
169 "If non-nil, use emacs-w3m command keys in the article buffer."
172 :group 'mime-display)
174 (defcustom mm-enable-external t
175 "Indicate whether external MIME handlers should be used.
177 If t, all defined external MIME handlers are used. If nil, files are saved by
178 `mailcap-save-binary-file'. If it is the symbol `ask', you are prompted
179 before the external MIME handler is invoked."
181 :type '(choice (const :tag "Always" t)
182 (const :tag "Never" nil)
183 (const :tag "Ask" ask))
184 :group 'mime-display)
186 (defcustom mm-inline-media-tests
190 (mm-valid-and-fit-image-p 'jpeg handle)))
194 (mm-valid-and-fit-image-p 'png handle)))
198 (mm-valid-and-fit-image-p 'gif handle)))
202 (mm-valid-and-fit-image-p 'tiff handle)))
206 (mm-valid-and-fit-image-p 'xbm handle)))
210 (mm-valid-and-fit-image-p 'xbm handle)))
214 (mm-valid-and-fit-image-p 'xpm handle)))
218 (mm-valid-and-fit-image-p 'xpm handle)))
222 (mm-valid-and-fit-image-p 'bmp handle)))
223 ("image/x-portable-bitmap"
226 (mm-valid-and-fit-image-p 'pbm handle)))
227 ("text/plain" mm-inline-text identity)
228 ("text/enriched" mm-inline-text identity)
229 ("text/richtext" mm-inline-text identity)
230 ("text/x-patch" mm-display-patch-inline identity)
231 ;; In case mime.types uses x-diff (as does Debian's mime-support-3.40).
232 ("text/x-diff" mm-display-patch-inline identity)
233 ("application/emacs-lisp" mm-display-elisp-inline identity)
234 ("application/x-emacs-lisp" mm-display-elisp-inline identity)
235 ("application/x-shellscript" mm-display-shell-script-inline identity)
236 ("application/x-sh" mm-display-shell-script-inline identity)
237 ("text/x-sh" mm-display-shell-script-inline identity)
238 ("application/javascript" mm-display-javascript-inline identity)
239 ("text/dns" mm-display-dns-inline identity)
240 ("text/x-org" mm-display-org-inline identity)
244 mm-text-html-renderer))
248 (or (featurep 'vcard)
249 (locate-library "vcard"))))
250 ("message/delivery-status" mm-inline-text identity)
251 ("message/rfc822" mm-inline-message identity)
252 ("message/partial" mm-inline-partial identity)
253 ("message/external-body" mm-inline-external-body identity)
254 ("text/.*" mm-inline-text identity)
255 ("application/x-.?tar\\(-.*\\)?" mm-archive-dissect-and-inline identity)
256 ("application/zip" mm-archive-dissect-and-inline identity)
257 ("audio/wav" mm-inline-audio
259 (and (or (featurep 'nas-sound) (featurep 'native-sound))
260 (device-sound-enabled-p))))
264 (and (or (featurep 'nas-sound) (featurep 'native-sound))
265 (device-sound-enabled-p))))
266 ("application/pgp-signature" ignore identity)
267 ("application/x-pkcs7-signature" ignore identity)
268 ("application/pkcs7-signature" ignore identity)
269 ("application/x-pkcs7-mime" ignore identity)
270 ("application/pkcs7-mime" ignore identity)
271 ("multipart/alternative" ignore identity)
272 ("multipart/mixed" ignore identity)
273 ("multipart/related" ignore identity)
277 (and (mm-valid-image-format-p 'imagemagick)
278 (mm-with-unibyte-buffer
279 (mm-insert-part handle)
282 (if (fboundp 'create-image)
283 (create-image (buffer-string) 'imagemagick 'data-p)
284 (mm-create-image-xemacs
285 (mm-handle-media-subtype handle))))))
287 (setcar (cdr handle) (list "image/imagemagick"))
288 (mm-image-fit-p handle)))))))
289 ;; Disable audio and image
290 ("audio/.*" ignore ignore)
291 ("image/.*" ignore ignore)
292 ;; Default to displaying as text
293 (".*" mm-inline-text mm-readable-p))
294 "Alist of media types/tests saying whether types can be displayed inline."
295 :type '(repeat (list (regexp :tag "MIME type")
296 (function :tag "Display function")
297 (function :tag "Display test")))
298 :group 'mime-display)
300 (defcustom mm-inlined-types
301 '("image/.*" "text/.*" "message/delivery-status" "message/rfc822"
302 "message/partial" "message/external-body" "application/emacs-lisp"
303 "application/x-emacs-lisp"
304 "application/pgp-signature" "application/x-pkcs7-signature"
305 "application/pkcs7-signature" "application/x-pkcs7-mime"
306 "application/pkcs7-mime"
307 "application/x-gtar-compressed"
310 ;; Mutt still uses this even though it has already been withdrawn.
312 "List of media types that are to be displayed inline.
313 See also `mm-inline-media-tests', which says how to display a media
315 :type '(repeat regexp)
316 :group 'mime-display)
318 (defcustom mm-keep-viewer-alive-types
319 '("application/postscript" "application/msword" "application/vnd.ms-excel"
320 "application/pdf" "application/x-dvi")
321 "List of media types for which the external viewer will not be killed
322 when selecting a different article."
324 :type '(repeat regexp)
325 :group 'mime-display)
327 (defcustom mm-automatic-display
328 '("text/plain" "text/enriched" "text/richtext" "text/html" "text/x-verbatim"
329 "text/x-vcard" "image/.*" "message/delivery-status" "multipart/.*"
330 "message/rfc822" "text/x-patch" "text/dns" "application/pgp-signature"
331 "application/emacs-lisp" "application/x-emacs-lisp"
332 "application/x-pkcs7-signature"
333 "application/pkcs7-signature" "application/x-pkcs7-mime"
334 "application/pkcs7-mime"
335 ;; Mutt still uses this even though it has already been withdrawn.
338 "A list of MIME types to be displayed automatically."
339 :type '(repeat regexp)
340 :group 'mime-display)
342 (defcustom mm-attachment-override-types '("text/x-vcard"
343 "application/pkcs7-mime"
344 "application/x-pkcs7-mime"
345 "application/pkcs7-signature"
346 "application/x-pkcs7-signature")
347 "Types to have \"attachment\" ignored if they can be displayed inline."
348 :type '(repeat regexp)
349 :group 'mime-display)
351 (defcustom mm-inline-override-types nil
352 "Types to be treated as attachments even if they can be displayed inline."
353 :type '(repeat regexp)
354 :group 'mime-display)
356 (defcustom mm-automatic-external-display nil
357 "List of MIME type regexps that will be displayed externally automatically."
358 :type '(repeat regexp)
359 :group 'mime-display)
361 (defcustom mm-discouraged-alternatives nil
362 "List of MIME types that are discouraged when viewing multipart/alternative.
363 Viewing agents are supposed to view the last possible part of a message,
364 as that is supposed to be the richest. However, users may prefer other
365 types instead, and this list says what types are most unwanted. If,
366 for instance, text/html parts are very unwanted, and text/richtext are
367 somewhat unwanted, then the value of this variable should be set
370 (\"text/html\" \"text/richtext\")
372 Adding \"image/.*\" might also be useful. Spammers use it as the
373 preferred part of multipart/alternative messages. See also
374 `gnus-buttonized-mime-types', to which adding \"multipart/alternative\"
375 enables you to choose manually one of two types those mails include."
376 :type '(repeat regexp) ;; See `mm-preferred-alternative-precedence'.
377 :group 'mime-display)
379 (defcustom mm-tmp-directory
380 (if (fboundp 'temp-directory)
382 (if (boundp 'temporary-file-directory)
383 temporary-file-directory
385 "Where mm will store its temporary files."
387 :group 'mime-display)
389 (defcustom mm-inline-large-images nil
390 "If t, then all images fit in the buffer.
391 If 'resize, try to resize the images so they fit."
393 (const :tag "Inline large images as they are." t)
394 (const :tag "Resize large images." resize)
395 (const :tag "Do not inline large images." nil))
396 :group 'mime-display)
398 (defcustom mm-file-name-rewrite-functions
399 '(mm-file-name-delete-control mm-file-name-delete-gotchas)
400 "List of functions used for rewriting file names of MIME parts.
401 Each function takes a file name as input and returns a file name.
403 Ready-made functions include `mm-file-name-delete-control',
404 `mm-file-name-delete-gotchas' (you should not remove these two
405 functions), `mm-file-name-delete-whitespace',
406 `mm-file-name-trim-whitespace', `mm-file-name-collapse-whitespace',
407 `mm-file-name-replace-whitespace', `capitalize', `downcase',
408 `upcase', and `upcase-initials'."
409 :type '(list (set :inline t
410 (const mm-file-name-delete-control)
411 (const mm-file-name-delete-gotchas)
412 (const mm-file-name-delete-whitespace)
413 (const mm-file-name-trim-whitespace)
414 (const mm-file-name-collapse-whitespace)
415 (const mm-file-name-replace-whitespace)
419 (const upcase-initials)
423 :version "23.1" ;; No Gnus
424 :group 'mime-display)
427 (defvar mm-path-name-rewrite-functions nil
428 "*List of functions for rewriting the full file names of MIME parts.
429 This is used when viewing parts externally, and is meant for
430 transforming the absolute name so that non-compliant programs can find
431 the file where it's saved.
433 Each function takes a file name as input and returns a file name.")
435 (defvar mm-file-name-replace-whitespace nil
436 "String used for replacing whitespace characters; default is `\"_\"'.")
438 (defcustom mm-default-directory nil
439 "The default directory where mm will save files.
440 If not set, `default-directory' will be used."
441 :type '(choice directory (const :tag "Default" nil))
442 :group 'mime-display)
444 (defcustom mm-attachment-file-modes 384
445 "Set the mode bits of saved attachments to this integer."
448 :group 'mime-display)
450 (defcustom mm-external-terminal-program "xterm"
451 "The program to start an external terminal."
454 :group 'mime-display)
456 ;;; Internal variables.
458 (defvar mm-last-shell-command "")
459 (defvar mm-content-id-alist nil)
460 (defvar mm-postponed-undisplay-list nil)
461 (defvar mm-inhibit-auto-detect-attachment nil)
463 ;; According to RFC2046, in particular, in a digest, the default
464 ;; Content-Type value for a body part is changed from "text/plain" to
466 (defvar mm-dissect-default-type "text/plain")
468 (autoload 'mml2015-verify "mml2015")
469 (autoload 'mml2015-verify-test "mml2015")
470 (autoload 'mml-smime-verify "mml-smime")
471 (autoload 'mml-smime-verify-test "mml-smime")
473 (defvar mm-verify-function-alist
474 '(("application/pgp-signature" mml2015-verify "PGP" mml2015-verify-test)
475 ("application/x-gnus-pgp-signature" mm-uu-pgp-signed-extract-1 "PGP"
476 mm-uu-pgp-signed-test)
477 ("application/pkcs7-signature" mml-smime-verify "S/MIME"
478 mml-smime-verify-test)
479 ("application/x-pkcs7-signature" mml-smime-verify "S/MIME"
480 mml-smime-verify-test)))
482 (defcustom mm-verify-option 'never
483 "Option of verifying signed parts.
484 `never', not verify; `always', always verify;
485 `known', only verify known protocols. Otherwise, ask user.
487 When set to `always' or `known', you should add
488 \"multipart/signed\" to `gnus-buttonized-mime-types' to see
489 result of the verification."
491 :type '(choice (item always)
493 (item :tag "only known protocols" known)
494 (item :tag "ask" nil))
495 :group 'mime-security)
497 (autoload 'mml2015-decrypt "mml2015")
498 (autoload 'mml2015-decrypt-test "mml2015")
500 (defvar mm-decrypt-function-alist
501 '(("application/pgp-encrypted" mml2015-decrypt "PGP" mml2015-decrypt-test)
502 ("application/x-gnus-pgp-encrypted" mm-uu-pgp-encrypted-extract-1 "PGP"
503 mm-uu-pgp-encrypted-test)))
505 (defcustom mm-decrypt-option nil
506 "Option of decrypting encrypted parts.
507 `never', not decrypt; `always', always decrypt;
508 `known', only decrypt known protocols. Otherwise, ask user."
510 :type '(choice (item always)
512 (item :tag "only known protocols" known)
513 (item :tag "ask" nil))
514 :group 'mime-security)
516 (defvar mm-viewer-completion-map
517 (let ((map (make-sparse-keymap 'mm-viewer-completion-map)))
518 (set-keymap-parent map minibuffer-local-completion-map)
519 ;; Should we bind other key to minibuffer-complete-word?
520 (define-key map " " 'self-insert-command)
522 "Keymap for input viewer with completion.")
524 (defvar mm-viewer-completion-map
525 (let ((map (make-sparse-keymap 'mm-viewer-completion-map)))
526 (set-keymap-parent map minibuffer-local-completion-map)
527 ;; Should we bind other key to minibuffer-complete-word?
528 (define-key map " " 'self-insert-command)
530 "Keymap for input viewer with completion.")
534 (defun mm-alist-to-plist (alist)
535 "Convert association list ALIST into the equivalent property-list form.
536 The plist is returned. This converts from
538 \((a . 1) (b . 2) (c . 3))
544 The original alist is not modified. See also `destructive-alist-to-plist'."
547 (let ((el (car alist)))
548 (setq plist (cons (cdr el) (cons (car el) plist))))
549 (setq alist (cdr alist)))
552 (defun mm-keep-viewer-alive-p (handle)
553 "Say whether external viewer for HANDLE should stay alive."
554 (let ((types mm-keep-viewer-alive-types)
555 (type (mm-handle-media-type handle))
558 (while (setq ty (pop types))
559 (when (string-match ty type)
560 (throw 'found t))))))
562 (defun mm-handle-set-external-undisplayer (handle function)
563 "Set the undisplayer for HANDLE to FUNCTION.
564 Postpone undisplaying of viewers for types in
565 `mm-keep-viewer-alive-types'."
566 (if (mm-keep-viewer-alive-p handle)
567 (let ((new-handle (copy-sequence handle)))
568 (mm-handle-set-undisplayer new-handle function)
569 (mm-handle-set-undisplayer handle nil)
570 (push new-handle mm-postponed-undisplay-list))
571 (mm-handle-set-undisplayer handle function)))
573 (defun mm-destroy-postponed-undisplay-list ()
574 (when mm-postponed-undisplay-list
575 (message "Destroying external MIME viewers")
576 (mm-destroy-parts mm-postponed-undisplay-list)))
578 (autoload 'message-fetch-field "message")
580 (defun mm-dissect-buffer (&optional no-strict-mime loose-mime from)
581 "Dissect the current buffer and return a list of MIME handles.
582 If NO-STRICT-MIME, don't require the message to have a
583 MIME-Version header before proceeding."
585 (let (ct ctl type subtype cte cd description id result)
587 (mail-narrow-to-head)
588 (when (or no-strict-mime
590 (mail-fetch-field "mime-version"))
591 (setq ct (mail-fetch-field "content-type")
592 ctl (and ct (mail-header-parse-content-type ct))
593 cte (mail-fetch-field "content-transfer-encoding")
594 cd (or (mail-fetch-field "content-disposition")
597 (cadr (mm-assoc-string-match
598 mm-inline-media-tests
601 ;; Newlines in description should be stripped so as
602 ;; not to break the MIME tag into two or more lines.
603 description (message-fetch-field "content-description")
604 id (mail-fetch-field "content-id"))
606 (setq from (mail-fetch-field "from")))
607 ;; FIXME: In some circumstances, this code is running within
608 ;; an unibyte macro. mail-extract-address-components
609 ;; creates unibyte buffers. This `if', though not a perfect
610 ;; solution, avoids most of them.
612 (setq from (cadr (mail-extract-address-components from))))
614 (setq description (mail-decode-encoded-word-string
617 (not (string-match "/" (car ctl))))
618 (mm-dissect-singlepart
619 (list mm-dissect-default-type)
620 (and cte (intern (downcase (mail-header-strip cte))))
622 (and cd (mail-header-parse-content-disposition cd))
624 (setq type (split-string (car ctl) "/"))
625 (setq subtype (cadr type)
630 ((equal type "multipart")
631 (let ((mm-dissect-default-type (if (equal subtype "digest")
634 (start (cdr (assq 'start (cdr ctl)))))
635 (add-text-properties 0 (length (car ctl))
636 (mm-alist-to-plist (cdr ctl)) (car ctl))
638 ;; what really needs to be done here is a way to link a
639 ;; MIME handle back to it's parent MIME handle (in a multilevel
640 ;; MIME article). That would probably require changing
641 ;; the mm-handle API so we simply store the multipart buffer
642 ;; name as a text property of the "multipart/whatever" string.
643 (add-text-properties 0 (length (car ctl))
644 (list 'buffer (mm-copy-to-buffer)
648 (cons (car ctl) (mm-dissect-multipart ctl from))))
650 (mm-possibly-verify-or-decrypt
651 (mm-dissect-singlepart
653 (and cte (intern (downcase (mail-header-strip cte))))
655 (and cd (mail-header-parse-content-disposition cd))
659 (when (string-match " *<\\(.*\\)> *" id)
660 (setq id (match-string 1 id)))
661 (push (cons id result) mm-content-id-alist))
664 (defun mm-dissect-singlepart (ctl cte &optional force cdl description id)
666 (if (equal "text/plain" (car ctl))
669 ;; Guess what the type of application/octet-stream parts should
671 (let ((filename (cdr (assq 'filename (cdr cdl)))))
672 (when (and (not mm-inhibit-auto-detect-attachment)
673 (equal (car ctl) "application/octet-stream")
675 (string-match "\\.\\([^.]+\\)$" filename))
676 (let ((new-type (mailcap-extension-to-mime (match-string 1 filename))))
678 (setcar ctl new-type)))))
681 (mm-copy-to-buffer) ctl cte nil cdl description nil id))
682 (decoder (assoc (car ctl) (mm-archive-decoders))))
684 ;; Do automatic decoding
686 (executable-find (caddr decoder)))
687 (mm-dissect-archive handle)
690 (defun mm-dissect-multipart (ctl from)
691 (goto-char (point-min))
692 (let* ((boundary (concat "\n--" (mail-content-type-get ctl 'boundary)))
693 (close-delimiter (concat (regexp-quote boundary) "--[ \t]*$"))
696 (goto-char (point-max))
697 (if (re-search-backward close-delimiter nil t)
700 (mm-inhibit-auto-detect-attachment
701 (equal (car ctl) "multipart/encrypted")))
702 (setq boundary (concat (regexp-quote boundary) "[ \t]*$"))
703 (while (and (< (point) end) (re-search-forward boundary end t))
704 (goto-char (match-beginning 0))
708 (narrow-to-region start (point))
709 (setq parts (nconc (list (mm-dissect-buffer t nil from)) parts)))))
711 (or (looking-at boundary)
713 (setq start (point)))
714 (when (and start (< start end))
717 (narrow-to-region start end)
718 (setq parts (nconc (list (mm-dissect-buffer t nil from)) parts)))))
719 (mm-possibly-verify-or-decrypt (nreverse parts) ctl from)))
721 (defun mm-copy-to-buffer ()
722 "Copy the contents of the current buffer to a fresh buffer."
723 (let ((obuf (current-buffer))
724 (mb (mm-multibyte-p))
726 (goto-char (point-min))
727 (search-forward-regexp "^\n" nil t)
730 (generate-new-buffer " *mm*")
731 ;; Preserve the data's unibyteness (for url-insert-file-contents).
732 (mm-set-buffer-multibyte mb)
733 (insert-buffer-substring obuf beg)
736 (defun mm-display-parts (handle &optional no-default)
737 (if (stringp (car handle))
738 (mapcar 'mm-display-parts (cdr handle))
739 (if (bufferp (car handle))
741 (narrow-to-region (point) (point))
742 (mm-display-part handle)
743 (goto-char (point-max)))
744 (mapcar 'mm-display-parts handle))))
746 (autoload 'mailcap-parse-mailcaps "mailcap")
747 (autoload 'mailcap-mime-info "mailcap")
749 (defun mm-display-part (handle &optional no-default force)
750 "Display the MIME part represented by HANDLE.
751 Returns nil if the part is removed; inline if displayed inline;
752 external if displayed external."
754 (mailcap-parse-mailcaps)
756 (mm-handle-displayed-p handle))
757 (mm-remove-part handle)
758 (let* ((ehandle (if (equal (mm-handle-media-type handle)
759 "message/external-body")
761 (unless (mm-handle-cache handle)
762 (mm-extern-cache-contents handle))
763 (mm-handle-cache handle))
765 (type (mm-handle-media-type ehandle))
766 (method (mailcap-mime-info type))
767 (filename (or (mail-content-type-get
768 (mm-handle-disposition handle) 'filename)
769 (mail-content-type-get
770 (mm-handle-type handle) 'name)
772 (external mm-enable-external))
773 (if (and (mm-inlinable-p ehandle)
774 (mm-inlined-p ehandle))
777 (mm-display-inline handle)
781 (if (and (not method)
782 (equal "text" (car (split-string type "/"))))
785 (mm-insert-inline handle (mm-get-part handle))
788 (and method ;; If nil, we always use "save".
789 (stringp method) ;; 'mailcap-save-binary-file
790 (or (eq mm-enable-external t)
791 (and (eq mm-enable-external 'ask)
794 "Display part (" type
795 ") using external program"
796 ;; Can non-string method ever happen?
799 " \"" (format method filename) "\"")
804 handle (or method 'mailcap-save-binary-file))