1 ;;; mm-decode.el --- Functions for decoding MIME things
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
30 (require 'gnus-mailcap)
32 (eval-when-compile (require 'cl)
36 (autoload 'mm-inline-partial "mm-partial")
37 (autoload 'mm-inline-external-body "mm-extern")
38 (autoload 'mm-insert-inline "mm-view"))
40 (defvar gnus-current-window-configuration)
42 (add-hook 'gnus-exit-gnus-hook 'mm-destroy-postponed-undisplay-list)
44 (defgroup mime-display ()
45 "Display of MIME in mail and news articles."
46 :link '(custom-manual "(emacs-mime)Display Customization")
52 (defgroup mime-security ()
53 "MIME security in mail and news articles."
54 :link '(custom-manual "(emacs-mime)Display Customization")
59 ;;; Convenience macros.
61 (defmacro mm-handle-buffer (handle)
63 (defmacro mm-handle-type (handle)
65 (defsubst mm-handle-media-type (handle)
66 (if (stringp (car handle))
68 (car (mm-handle-type handle))))
69 (defsubst mm-handle-media-supertype (handle)
70 (car (split-string (mm-handle-media-type handle) "/")))
71 (defsubst mm-handle-media-subtype (handle)
72 (cadr (split-string (mm-handle-media-type handle) "/")))
73 (defmacro mm-handle-encoding (handle)
75 (defmacro mm-handle-undisplayer (handle)
77 (defmacro mm-handle-set-undisplayer (handle function)
78 `(setcar (nthcdr 3 ,handle) ,function))
79 (defmacro mm-handle-disposition (handle)
81 (defmacro mm-handle-description (handle)
83 (defmacro mm-handle-cache (handle)
85 (defmacro mm-handle-set-cache (handle contents)
86 `(setcar (nthcdr 6 ,handle) ,contents))
87 (defmacro mm-handle-id (handle)
89 (defmacro mm-handle-multipart-original-buffer (handle)
90 `(get-text-property 0 'buffer (car ,handle)))
91 (defmacro mm-handle-multipart-from (handle)
92 `(get-text-property 0 'from (car ,handle)))
93 (defmacro mm-handle-multipart-ctl-parameter (handle parameter)
94 `(get-text-property 0 ,parameter (car ,handle)))
96 (defmacro mm-make-handle (&optional buffer type encoding undisplayer
97 disposition description cache
99 `(list ,buffer ,type ,encoding ,undisplayer
100 ,disposition ,description ,cache ,id))
102 (defcustom mm-text-html-renderer
103 (cond ((locate-library "w3") 'w3)
104 ((executable-find "w3m") (if (locate-library "w3m")
107 ((executable-find "links") 'links)
108 ((executable-find "lynx") 'lynx)
110 "Render of HTML contents.
111 It is one of defined renderer types, or a rendering function.
112 The defined renderer types are:
114 `w3m' : use emacs-w3m;
115 `w3m-standalone': use w3m;
118 `html2text' : use html2text;
119 nil : use external viewer."
121 :type '(choice (const w3)
123 (const w3m-standalone)
129 :group 'mime-display)
131 (defvar mm-inline-text-html-renderer nil
132 "Function used for rendering inline HTML contents.
133 It is suggested to customize `mm-text-html-renderer' instead.")
135 (defcustom mm-inline-text-html-with-images nil
136 "If non-nil, Gnus will allow retrieving images in HTML contents with
137 the <img> tags. It has no effect on Emacs/w3. See also the
138 documentation for the `mm-w3m-safe-url-regexp' variable."
141 :group 'mime-display)
143 (defcustom mm-w3m-safe-url-regexp "\\`cid:"
144 "Regexp matching URLs which are considered to be safe.
145 Some HTML mails might contain a nasty trick used by spammers, using
146 the <img> tag which is far more evil than the [Click Here!] button.
147 It is most likely intended to check whether the ominous spam mail has
148 reached your eyes or not, in which case the spammer knows for sure
149 that your email address is valid. It is done by embedding an
150 identifier string into a URL that you might automatically retrieve
151 when displaying the image. The default value is \"\\\\`cid:\" which only
152 matches parts embedded to the Multipart/Related type MIME contents and
153 Gnus will never connect to the spammer's site arbitrarily. You may
154 set this variable to nil if you consider all urls to be safe."
156 :type '(choice (regexp :tag "Regexp")
157 (const :tag "All URLs are safe" nil))
158 :group 'mime-display)
160 (defcustom mm-inline-text-html-with-w3m-keymap t
161 "If non-nil, use emacs-w3m command keys in the article buffer."
164 :group 'mime-display)
166 (defcustom mm-enable-external t
167 "Indicate whether external MIME handlers should be used.
169 If t, all defined external MIME handlers are used. If nil, files are saved by
170 `mailcap-save-binary-file'. If it is the symbol `ask', you are prompted
171 before the external MIME handler is invoked."
173 :type '(choice (const :tag "Always" t)
174 (const :tag "Never" nil)
175 (const :tag "Ask" ask))
176 :group 'mime-display)
178 (defcustom mm-inline-media-tests
182 (mm-valid-and-fit-image-p 'jpeg handle)))
186 (mm-valid-and-fit-image-p 'png handle)))
190 (mm-valid-and-fit-image-p 'gif handle)))
194 (mm-valid-and-fit-image-p 'tiff handle)) )
198 (mm-valid-and-fit-image-p 'xbm handle)))
202 (mm-valid-and-fit-image-p 'xbm handle)))
206 (mm-valid-and-fit-image-p 'xpm handle)))
210 (mm-valid-and-fit-image-p 'xpm handle)))
214 (mm-valid-and-fit-image-p 'bmp handle)))
215 ("image/x-portable-bitmap"
218 (mm-valid-and-fit-image-p 'pbm handle)))
219 ("text/plain" mm-inline-text identity)
220 ("text/enriched" mm-inline-text identity)
221 ("text/richtext" mm-inline-text identity)
222 ("text/x-patch" mm-display-patch-inline
224 ;; If the diff-mode.el package is installed, the function is
225 ;; autoloaded. Checking (locate-library "diff-mode") would be trying
226 ;; to cater to broken installations. OTOH checking the function
227 ;; makes it possible to install another package which provides an
228 ;; alternative implementation of diff-mode. --Stef
229 (fboundp 'diff-mode)))
230 ("application/emacs-lisp" mm-display-elisp-inline identity)
231 ("application/x-emacs-lisp" mm-display-elisp-inline identity)
232 ("text/dns" mm-display-dns-inline identity)
236 (or mm-inline-text-html-renderer
237 mm-text-html-renderer)))
241 (or (featurep 'vcard)
242 (locate-library "vcard"))))
243 ("message/delivery-status" mm-inline-text identity)
244 ("message/rfc822" mm-inline-message identity)
245 ("message/partial" mm-inline-partial identity)
246 ("message/external-body" mm-inline-external-body identity)
247 ("text/.*" mm-inline-text identity)
248 ("audio/wav" mm-inline-audio
250 (and (or (featurep 'nas-sound) (featurep 'native-sound))
251 (device-sound-enabled-p))))
255 (and (or (featurep 'nas-sound) (featurep 'native-sound))
256 (device-sound-enabled-p))))
257 ("application/pgp-signature" ignore identity)
258 ("application/x-pkcs7-signature" ignore identity)
259 ("application/pkcs7-signature" ignore identity)
260 ("application/x-pkcs7-mime" ignore identity)
261 ("application/pkcs7-mime" ignore identity)
262 ("multipart/alternative" ignore identity)
263 ("multipart/mixed" ignore identity)
264 ("multipart/related" ignore identity)
265 ;; Disable audio and image
266 ("audio/.*" ignore ignore)
267 ("image/.*" ignore ignore)
268 ;; Default to displaying as text
269 (".*" mm-inline-text mm-readable-p))
270 "Alist of media types/tests saying whether types can be displayed inline."
271 :type '(repeat (list (regexp :tag "MIME type")
272 (function :tag "Display function")
273 (function :tag "Display test")))
274 :group 'mime-display)
276 (defcustom mm-inlined-types
277 '("image/.*" "text/.*" "message/delivery-status" "message/rfc822"
278 "message/partial" "message/external-body" "application/emacs-lisp"
279 "application/x-emacs-lisp"
280 "application/pgp-signature" "application/x-pkcs7-signature"
281 "application/pkcs7-signature" "application/x-pkcs7-mime"
282 "application/pkcs7-mime")
283 "List of media types that are to be displayed inline.
284 See also `mm-inline-media-tests', which says how to display a media
286 :type '(repeat string)
287 :group 'mime-display)
289 (defcustom mm-keep-viewer-alive-types
290 '("application/postscript" "application/msword" "application/vnd.ms-excel"
291 "application/pdf" "application/x-dvi")
292 "List of media types for which the external viewer will not be killed
293 when selecting a different article."
295 :type '(repeat string)
296 :group 'mime-display)
298 (defcustom mm-automatic-display
299 '("text/plain" "text/enriched" "text/richtext" "text/html" "text/x-verbatim"
300 "text/x-vcard" "image/.*" "message/delivery-status" "multipart/.*"
301 "message/rfc822" "text/x-patch" "text/dns" "application/pgp-signature"
302 "application/emacs-lisp" "application/x-emacs-lisp"
303 "application/x-pkcs7-signature"
304 "application/pkcs7-signature" "application/x-pkcs7-mime"
305 "application/pkcs7-mime")
306 "A list of MIME types to be displayed automatically."
307 :type '(repeat string)
308 :group 'mime-display)
310 (defcustom mm-attachment-override-types '("text/x-vcard"
311 "application/pkcs7-mime"
312 "application/x-pkcs7-mime"
313 "application/pkcs7-signature"
314 "application/x-pkcs7-signature")
315 "Types to have \"attachment\" ignored if they can be displayed inline."
316 :type '(repeat string)
317 :group 'mime-display)
319 (defcustom mm-inline-override-types nil
320 "Types to be treated as attachments even if they can be displayed inline."
321 :type '(repeat string)
322 :group 'mime-display)
324 (defcustom mm-automatic-external-display nil
325 "List of MIME type regexps that will be displayed externally automatically."
326 :type '(repeat string)
327 :group 'mime-display)
329 (defcustom mm-discouraged-alternatives nil
330 "List of MIME types that are discouraged when viewing multipart/alternative.
331 Viewing agents are supposed to view the last possible part of a message,
332 as that is supposed to be the richest. However, users may prefer other
333 types instead, and this list says what types are most unwanted. If,
334 for instance, text/html parts are very unwanted, and text/richtext are
335 somewhat unwanted, then the value of this variable should be set
338 (\"text/html\" \"text/richtext\")
340 Adding \"image/.*\" might also be useful. Spammers use it as the
341 prefered part of multipart/alternative messages. See also
342 `gnus-buttonized-mime-types', to which adding \"multipart/alternative\"
343 enables you to choose manually one of two types those mails include."
344 :type '(repeat regexp) ;; See `mm-preferred-alternative-precedence'.
345 :group 'mime-display)
347 (defcustom mm-tmp-directory
348 (if (fboundp 'temp-directory)
350 (if (boundp 'temporary-file-directory)
351 temporary-file-directory
353 "Where mm will store its temporary files."
355 :group 'mime-display)
357 (defcustom mm-inline-large-images nil
358 "If non-nil, then all images fit in the buffer."
360 :group 'mime-display)
362 (defvar mm-file-name-rewrite-functions
363 '(mm-file-name-delete-control mm-file-name-delete-gotchas)
364 "*List of functions used for rewriting file names of MIME parts.
365 Each function takes a file name as input and returns a file name.
367 Ready-made functions include
368 `mm-file-name-delete-control'
369 `mm-file-name-delete-gotchas'
370 `mm-file-name-delete-whitespace',
371 `mm-file-name-trim-whitespace',
372 `mm-file-name-collapse-whitespace',
373 `mm-file-name-replace-whitespace',
374 `capitalize', `downcase', `upcase', and
377 (defvar mm-path-name-rewrite-functions nil
378 "*List of functions for rewriting the full file names of MIME parts.
379 This is used when viewing parts externally, and is meant for
380 transforming the absolute name so that non-compliant programs can find
381 the file where it's saved.
383 Each function takes a file name as input and returns a file name.")
385 (defvar mm-file-name-replace-whitespace nil
386 "String used for replacing whitespace characters; default is `\"_\"'.")
388 (defcustom mm-default-directory nil
389 "The default directory where mm will save files.
390 If not set, `default-directory' will be used."
391 :type '(choice directory (const :tag "Default" nil))
392 :group 'mime-display)
394 (defcustom mm-attachment-file-modes 384
395 "Set the mode bits of saved attachments to this integer."
398 :group 'mime-display)
400 (defcustom mm-external-terminal-program "xterm"
401 "The program to start an external terminal."
404 :group 'mime-display)
406 ;;; Internal variables.
408 (defvar mm-last-shell-command "")
409 (defvar mm-content-id-alist nil)
410 (defvar mm-postponed-undisplay-list nil)
412 ;; According to RFC2046, in particular, in a digest, the default
413 ;; Content-Type value for a body part is changed from "text/plain" to
415 (defvar mm-dissect-default-type "text/plain")
417 (autoload 'mml2015-verify "mml2015")
418 (autoload 'mml2015-verify-test "mml2015")
419 (autoload 'mml-smime-verify "mml-smime")
420 (autoload 'mml-smime-verify-test "mml-smime")
422 (defvar mm-verify-function-alist
423 '(("application/pgp-signature" mml2015-verify "PGP" mml2015-verify-test)
424 ("application/x-gnus-pgp-signature" mm-uu-pgp-signed-extract-1 "PGP"
425 mm-uu-pgp-signed-test)
426 ("application/pkcs7-signature" mml-smime-verify "S/MIME"
427 mml-smime-verify-test)
428 ("application/x-pkcs7-signature" mml-smime-verify "S/MIME"
429 mml-smime-verify-test)))
431 (defcustom mm-verify-option 'never
432 "Option of verifying signed parts.
433 `never', not verify; `always', always verify;
434 `known', only verify known protocols. Otherwise, ask user."
436 :type '(choice (item always)
438 (item :tag "only known protocols" known)
439 (item :tag "ask" nil))
440 :group 'mime-security)
442 (autoload 'mml2015-decrypt "mml2015")
443 (autoload 'mml2015-decrypt-test "mml2015")
445 (defvar mm-decrypt-function-alist
446 '(("application/pgp-encrypted" mml2015-decrypt "PGP" mml2015-decrypt-test)
447 ("application/x-gnus-pgp-encrypted" mm-uu-pgp-encrypted-extract-1 "PGP"
448 mm-uu-pgp-encrypted-test)))
450 (defcustom mm-decrypt-option nil
451 "Option of decrypting encrypted parts.
452 `never', not decrypt; `always', always decrypt;
453 `known', only decrypt known protocols. Otherwise, ask user."
455 :type '(choice (item always)
457 (item :tag "only known protocols" known)
458 (item :tag "ask" nil))
459 :group 'mime-security)
461 (defvar mm-viewer-completion-map
462 (let ((map (make-sparse-keymap 'mm-viewer-completion-map)))
463 (set-keymap-parent map minibuffer-local-completion-map)
464 ;; Should we bind other key to minibuffer-complete-word?
465 (define-key map " " 'self-insert-command)
467 "Keymap for input viewer with completion.")
469 (defvar mm-viewer-completion-map
470 (let ((map (make-sparse-keymap 'mm-viewer-completion-map)))
471 (set-keymap-parent map minibuffer-local-completion-map)
472 ;; Should we bind other key to minibuffer-complete-word?
473 (define-key map " " 'self-insert-command)
475 "Keymap for input viewer with completion.")
479 (defun mm-alist-to-plist (alist)
480 "Convert association list ALIST into the equivalent property-list form.
481 The plist is returned. This converts from
483 \((a . 1) (b . 2) (c . 3))
489 The original alist is not modified. See also `destructive-alist-to-plist'."
492 (let ((el (car alist)))
493 (setq plist (cons (cdr el) (cons (car el) plist))))
494 (setq alist (cdr alist)))
497 (defun mm-keep-viewer-alive-p (handle)
498 "Say whether external viewer for HANDLE should stay alive."
499 (let ((types mm-keep-viewer-alive-types)
500 (type (mm-handle-media-type handle))
503 (while (setq ty (pop types))
504 (when (string-match ty type)
505 (throw 'found t))))))
507 (defun mm-handle-set-external-undisplayer (handle function)
508 "Set the undisplayer for HANDLE to FUNCTION.
509 Postpone undisplaying of viewers for types in
510 `mm-keep-viewer-alive-types'."
511 (if (mm-keep-viewer-alive-p handle)
512 (let ((new-handle (copy-sequence handle)))
513 (mm-handle-set-undisplayer new-handle function)
514 (mm-handle-set-undisplayer handle nil)
515 (push new-handle mm-postponed-undisplay-list))
516 (mm-handle-set-undisplayer handle function)))
518 (defun mm-destroy-postponed-undisplay-list ()
519 (when mm-postponed-undisplay-list
520 (message "Destroying external MIME viewers")
521 (mm-destroy-parts mm-postponed-undisplay-list)))
523 (defun mm-dissect-buffer (&optional no-strict-mime loose-mime from)
524 "Dissect the current buffer and return a list of MIME handles."
526 (let (ct ctl type subtype cte cd description id result)
528 (mail-narrow-to-head)
529 (when (or no-strict-mime
531 (mail-fetch-field "mime-version"))
532 (setq ct (mail-fetch-field "content-type")
533 ctl (ignore-errors (mail-header-parse-content-type ct))
534 cte (mail-fetch-field "content-transfer-encoding")
535 cd (mail-fetch-field "content-disposition")
536 description (mail-fetch-field "content-description")
537 id (mail-fetch-field "content-id"))
539 (setq from (mail-fetch-field "from")))
540 ;; FIXME: In some circumstances, this code is running within
541 ;; an unibyte macro. mail-extract-address-components
542 ;; creates unibyte buffers. This `if', though not a perfect
543 ;; solution, avoids most of them.
545 (setq from (cadr (mail-extract-address-components from))))))
547 (not (string-match "/" (car ctl))))
548 (mm-dissect-singlepart
549 (list mm-dissect-default-type)
550 (and cte (intern (downcase (mail-header-strip cte))))
552 (and cd (ignore-errors (mail-header-parse-content-disposition cd)))
554 (setq type (split-string (car ctl) "/"))
555 (setq subtype (cadr type)
560 ((equal type "multipart")
561 (let ((mm-dissect-default-type (if (equal subtype "digest")
564 (start (cdr (assq 'start (cdr ctl)))))
565 (add-text-properties 0 (length (car ctl))
566 (mm-alist-to-plist (cdr ctl)) (car ctl))
568 ;; what really needs to be done here is a way to link a
569 ;; MIME handle back to it's parent MIME handle (in a multilevel
570 ;; MIME article). That would probably require changing
571 ;; the mm-handle API so we simply store the multipart buffer
572 ;; name as a text property of the "multipart/whatever" string.
573 (add-text-properties 0 (length (car ctl))
574 (list 'buffer (mm-copy-to-buffer)
578 (cons (car ctl) (mm-dissect-multipart ctl from))))
580 (mm-possibly-verify-or-decrypt
581 (mm-dissect-singlepart
583 (and cte (intern (downcase (mail-header-strip cte))))
585 (and cd (ignore-errors
586 (mail-header-parse-content-disposition cd)))
590 (when (string-match " *<\\(.*\\)> *" id)
591 (setq id (match-string 1 id)))
592 (push (cons id result) mm-content-id-alist))
595 (defun mm-dissect-singlepart (ctl cte &optional force cdl description id)
597 (if (equal "text/plain" (car ctl))
601 (mm-copy-to-buffer) ctl cte nil cdl description nil id)))
603 (defun mm-dissect-multipart (ctl from)
604 (goto-char (point-min))
605 (let* ((boundary (concat "\n--" (mail-content-type-get ctl 'boundary)))
606 (close-delimiter (concat (regexp-quote boundary) "--[ \t]*$"))
609 (goto-char (point-max))
610 (if (re-search-backward close-delimiter nil t)
613 (setq boundary (concat (regexp-quote boundary) "[ \t]*$"))
614 (while (and (< (point) end) (re-search-forward boundary end t))
615 (goto-char (match-beginning 0))
619 (narrow-to-region start (point))
620 (setq parts (nconc (list (mm-dissect-buffer t nil from)) parts)))))
622 (or (looking-at boundary)
624 (setq start (point)))
625 (when (and start (< start end))
628 (narrow-to-region start end)
629 (setq parts (nconc (list (mm-dissect-buffer t nil from)) parts)))))
630 (mm-possibly-verify-or-decrypt (nreverse parts) ctl)))
632 (defun mm-copy-to-buffer ()
633 "Copy the contents of the current buffer to a fresh buffer."
635 (let ((obuf (current-buffer))
637 (goto-char (point-min))
638 (search-forward-regexp "^\n" nil t)
641 ;; Preserve the data's unibyteness (for url-insert-file-contents).
642 (let ((default-enable-multibyte-characters (mm-multibyte-p)))
643 (generate-new-buffer " *mm*")))
644 (insert-buffer-substring obuf beg)
647 (defun mm-display-parts (handle &optional no-default)
648 (if (stringp (car handle))
649 (mapcar 'mm-display-parts (cdr handle))
650 (if (bufferp (car handle))
652 (narrow-to-region (point) (point))
653 (mm-display-part handle)
654 (goto-char (point-max)))
655 (mapcar 'mm-display-parts handle))))
657 (defun mm-display-part (handle &optional no-default)
658 "Display the MIME part represented by HANDLE.
659 Returns nil if the part is removed; inline if displayed inline;
660 external if displayed external."
662 (mailcap-parse-mailcaps)
663 (if (mm-handle-displayed-p handle)
664 (mm-remove-part handle)
665 (let* ((type (mm-handle-media-type handle))
666 (method (mailcap-mime-info type))
667 (filename (or (mail-content-type-get
668 (mm-handle-disposition handle) 'filename)
669 (mail-content-type-get
670 (mm-handle-type handle) 'name)
672 (external mm-enable-external))
673 (if (and (mm-inlinable-p handle)
674 (mm-inlined-p handle))
677 (mm-display-inline handle)
681 (if (and (not method)
682 (equal "text" (car (split-string type))))
685 (mm-insert-inline handle (mm-get-part handle))
687 (if (and method ;; If nil, we always use "save".
688 (stringp method) ;; 'mailcap-save-binary-file
689 (or (eq mm-enable-external t)
690 (and (eq mm-enable-external 'ask)
693 "Display part (" type
694 ") using external program"
695 ;; Can non-string method ever happen?
698 " \"" (format method filename) "\"")
705 handle (or method 'mailcap-save-binary-file))
707 handle 'mailcap-save-binary-file)))))))))
709 (defun mm-display-external (handle method)
710 "Display HANDLE using METHOD."
711 (let ((outbuf (current-buffer)))
712 (mm-with-unibyte-buffer
713 (if (functionp method)
714 (let ((cur (current-buffer)))
715 (if (eq method 'mailcap-save-binary-file)
717 (set-buffer (generate-new-buffer " *mm*"))
719 (mm-insert-part handle)
720 (let ((win (get-buffer-window cur t)))
722 (select-window win)))
723 (switch-to-buffer (generate-new-buffer " *mm*")))
724 (buffer-disable-undo)
725 (mm-set-buffer-file-coding-system mm-binary-coding-system)
726 (insert-buffer-substring cur)
727 (goto-char (point-min))
729 (message "Viewing with %s" method))
730 (let ((mm (current-buffer))
731 (non-viewer (assq 'non-viewer
733 (mm-handle-media-type handle) t))))
737 (mm-save-part handle))
738 (when (and (not non-viewer)
740 (mm-handle-set-undisplayer handle mm)))))
741 ;; The function is a string to be executed.
742 (mm-insert-part handle)
743 (let* ((dir (mm-make-temp-file
744 (expand-file-name "emm." mm-tmp-directory) 'dir))
746 (mail-content-type-get
747 (mm-handle-disposition handle) 'filename)
748 (mail-content-type-get
749 (mm-handle-type handle) 'name)))
750 (mime-info (mailcap-mime-info
751 (mm-handle-media-type handle) t))
752 (needsterm (or (assoc "needsterm" mime-info)
753 (assoc "needsterminal" mime-info)))
754 (copiousoutput (assoc "copiousoutput" mime-info))
756 ;; We create a private sub-directory where we store our files.
757 (set-file-modes dir 448)
759 (setq file (expand-file-name
760 (gnus-map-function mm-file-name-rewrite-functions
761 (file-name-nondirectory filename))
763 (setq file (mm-make-temp-file (expand-file-name "mm." dir)))
765 ;; Use nametemplate (defined in RFC1524) if it is
766 ;; specified in mailcap.
767 (if (assoc "nametemplate" mime-info)
768 (format (cdr (assoc "nametemplate" mime-info)) file)
769 ;; Add a suffix according to `mailcap-mime-extensions'.
770 (concat file (car (rassoc (mm-handle-media-type handle)
771 mailcap-mime-extensions))))))
772 (unless (string-equal file newname)
773 (when (file-exists-p file)
774 (rename-file file newname))
775 (setq file newname))))
776 (let ((coding-system-for-write mm-binary-coding-system))
777 (write-region (point-min) (point-max) file nil 'nomesg))
778 (message "Viewing with %s" method)
781 (let ((command (mm-mailcap-command
782 method file (mm-handle-type handle))))
785 (start-process "*display*" nil
786 mm-external-terminal-program
788 shell-command-switch command)
796 shell-command-switch command)))
799 (set-process-sentinel
800 (get-buffer-process buffer)
801 `(lambda (process state)
802 (if (eq 'exit (process-status process))
803 (gnus-configure-windows
804 ',gnus-current-window-configuration))))
805 (gnus-configure-windows 'display-term))
806 (mm-handle-set-external-undisplayer handle (cons file buffer)))
807 (message "Displaying %s..." command))
810 (with-current-buffer outbuf
816 (call-process shell-file-name nil
818 (generate-new-buffer " *mm*"))
822 method file (mm-handle-type handle)))
823 (if (buffer-live-p buffer)
824 (with-current-buffer buffer
827 (ignore-errors (delete-file file))
828 (ignore-errors (delete-directory
829 (file-name-directory file)))
830 (ignore-errors (kill-buffer buffer))))))
833 ;; Deleting the temp file should be postponed for some wrappers,
834 ;; shell scripts, and so on, which might exit right after having
835 ;; started a viewer command as a background job.
836 (let ((command (mm-mailcap-command
837 method file (mm-handle-type handle))))
840 (start-process "*display*"
842 (generate-new-buffer " *mm*"))
844 shell-command-switch command)
845 (set-process-sentinel
846 (get-buffer-process buffer)
847 (lexical-let ;; Don't use `let'.
848 ;; Function used to remove temp file and directory.
850 ;; Don't use `ignore-errors'.
856 ,(file-name-directory file))
858 ;; Form uses to kill the process buffer and
859 ;; remove the undisplayer.
861 (kill-buffer ,buffer)
863 (list 'mm-handle-set-undisplayer
866 ;; Message to be issued when the process exits.
867 (done (format "Displaying %s...done" command))
868 ;; In particular, the timer object (which is
869 ;; a vector in Emacs but is a list in XEmacs)
870 ;; requires that it is lexically scoped.
871 (timer (run-at-time 2.0 nil 'ignore)))
872 (lambda (process state)
873 (when (eq 'exit (process-status process))
874 (if (memq timer timer-list)
875 (timer-set-function timer fn)
877 (ignore-errors (eval fm))
878 (message "%s" done))))))
879 (mm-handle-set-external-undisplayer
880 handle (cons file buffer)))
881 (message "Displaying %s..." command))
884 (defun mm-mailcap-command (method file type-list)
885 (let ((ctl (cdr type-list))
889 (while (string-match "%{\\([^}]+\\)}\\|'%s'\\|\"%s\"\\|%s\\|%t\\|%%"
891 (push (substring method beg (match-beginning 0)) out)
892 (setq beg (match-end 0)
893 total (match-string 0 method)
894 sub (match-string 1 method))
896 ((string= total "%%")
898 ((or (string= total "%s")
899 ;; We do our own quoting.
900 (string= total "'%s'")
901 (string= total "\"%s\""))
902 (setq uses-stdin nil)
903 (push (shell-quote-argument
904 (gnus-map-function mm-path-name-rewrite-functions file)) out))
905 ((string= total "%t")
906 (push (shell-quote-argument (car type-list)) out))
908 (push (shell-quote-argument (or (cdr (assq (intern sub) ctl)) "")) out))))
909 (push (substring method beg (length method)) out)
912 (push (shell-quote-argument
913 (gnus-map-function mm-path-name-rewrite-functions file))
915 (mapconcat 'identity (nreverse out) "")))
917 (defun mm-remove-parts (handles)
918 "Remove the displayed MIME parts represented by HANDLES."
919 (if (and (listp handles)
920 (bufferp (car handles)))
921 (mm-remove-part handles)
923 (while (setq handle (pop handles))
926 (when (buffer-live-p (get-text-property 0 'buffer handle))
927 (kill-buffer (get-text-property 0 'buffer handle))))
929 (stringp (car handle)))
930 (mm-remove-parts (cdr handle)))
932 (mm-remove-part handle)))))))
934 (defun mm-destroy-parts (handles)
935 "Remove the displayed MIME parts represented by HANDLES."
936 (if (and (listp handles)
937 (bufferp (car handles)))
938 (mm-destroy-part handles)
940 (while (setq handle (pop handles))
943 (when (buffer-live-p (get-text-property 0 'buffer handle))
944 (kill-buffer (get-text-property 0 'buffer handle))))
946 (stringp (car handle)))
947 (mm-destroy-parts handle))
949 (mm-destroy-part handle)))))))
951 (defun mm-remove-part (handle)
952 "Remove the displayed MIME part represented by HANDLE."
954 (let ((object (mm-handle-undisplayer handle)))
957 ;; Internally displayed part.
958 ((mm-annotationp object)
959 (delete-annotation object))
960 ((or (functionp object)
962 (eq (car object) 'lambda)))
964 ;; Externally displayed part.
967 (while (get-buffer-process (cdr object))
968 (interrupt-process (get-buffer-process (cdr object)))
969 (message "Waiting for external displayer to die...")
973 (ignore-errors (and (cdr object) (kill-buffer (cdr object))))
974 (message "Waiting for external displayer to die...done")
975 (ignore-errors (delete-file (car object)))
976 (ignore-errors (delete-directory (file-name-directory
979 (when (buffer-live-p object)
980 (kill-buffer object)))))
981 (mm-handle-set-undisplayer handle nil))))
983 (defun mm-display-inline (handle)
984 (let* ((type (mm-handle-media-type handle))
985 (function (cadr (mm-assoc-string-match mm-inline-media-tests type))))
986 (funcall function handle)
987 (goto-char (point-min))))
989 (defun mm-assoc-string-match (alist type)
991 (when (string-match (car elem) type)
994 (defun mm-automatic-display-p (handle)
995 "Say whether the user wants HANDLE to be displayed automatically."
996 (let ((methods mm-automatic-display)
997 (type (mm-handle-media-type handle))
999 (while (setq method (pop methods))
1000 (when (and (not (mm-inline-override-p handle))
1001 (string-match method type))
1006 (defun mm-inlinable-p (handle)
1007 "Say whether HANDLE can be displayed inline."
1008 (let ((alist mm-inline-media-tests)
1009 (type (mm-handle-media-type handle))
1012 (when (string-match (caar alist) type)
1013 (setq test (caddar alist)
1015 (setq test (funcall test handle)))
1019 (defun mm-inlined-p (handle)
1020 "Say whether the user wants HANDLE to be displayed inline."
1021 (let ((methods mm-inlined-types)
1022 (type (mm-handle-media-type handle))
1024 (while (setq method (pop methods))
1025 (when (and (not (mm-inline-override-p handle))
1026 (string-match method type))
1031 (defun mm-attachment-override-p (handle)
1032 "Say whether HANDLE should have attachment behavior overridden."
1033 (let ((types mm-attachment-override-types)
1034 (type (mm-handle-media-type handle))
1037 (while (setq ty (pop types))
1038 (when (and (string-match ty type)
1039 (mm-inlinable-p handle))
1040 (throw 'found t))))))
1042 (defun mm-inline-override-p (handle)
1043 "Say whether HANDLE should have inline behavior overridden."
1044 (let ((types mm-inline-override-types)
1045 (type (mm-handle-media-type handle))
1048 (while (setq ty (pop types))
1049 (when (string-match ty type)
1050 (throw 'found t))))))
1052 (defun mm-automatic-external-display-p (type)
1053 "Return the user-defined method for TYPE."
1054 (let ((methods mm-automatic-external-display)
1056 (while (setq method (pop methods))
1057 (when (string-match method type)
1062 (defun mm-destroy-part (handle)
1063 "Destroy the data structures connected to HANDLE."
1064 (when (listp handle)
1065 (mm-remove-part handle)
1066 (when (buffer-live-p (mm-handle-buffer handle))
1067 (kill-buffer (mm-handle-buffer handle)))))
1069 (defun mm-handle-displayed-p (handle)
1070 "Say whether HANDLE is displayed or not."
1071 (mm-handle-undisplayer handle))
1074 ;;; Functions for outputting parts
1077 (defun mm-get-part (handle)
1078 "Return the contents of HANDLE as a string."
1079 (mm-with-unibyte-buffer
1080 (insert (with-current-buffer (mm-handle-buffer handle)
1081 (mm-with-unibyte-current-buffer
1083 (mm-decode-content-transfer-encoding
1084 (mm-handle-encoding handle)
1085 (mm-handle-media-type handle))
1088 (defun mm-insert-part (handle)
1089 "Insert the contents of HANDLE in the current buffer."
1092 (cond ((eq (mail-content-type-get (mm-handle-type handle) 'charset)
1094 (with-current-buffer (mm-handle-buffer handle)
1097 (mm-string-as-multibyte (mm-get-part handle)))
1099 (mm-get-part handle))))))
1101 (defun mm-file-name-delete-whitespace (file-name)
1102 "Remove all whitespace characters from FILE-NAME."
1103 (while (string-match "\\s-+" file-name)
1104 (setq file-name (replace-match "" t t file-name)))
1107 (defun mm-file-name-trim-whitespace (file-name)
1108 "Remove leading and trailing whitespace characters from FILE-NAME."
1109 (when (string-match "\\`\\s-+" file-name)
1110 (setq file-name (substring file-name (match-end 0))))
1111 (when (string-match "\\s-+\\'" file-name)
1112 (setq file-name (substring file-name 0 (match-beginning 0))))
1115 (defun mm-file-name-collapse-whitespace (file-name)
1116 "Collapse multiple whitespace characters in FILE-NAME."
1117 (while (string-match "\\s-\\s-+" file-name)
1118 (setq file-name (replace-match " " t t file-name)))
1121 (defun mm-file-name-replace-whitespace (file-name)
1122 "Replace whitespace characters in FILE-NAME with underscores.
1123 Set the option `mm-file-name-replace-whitespace' to any other
1124 string if you do not like underscores."
1125 (let ((s (or mm-file-name-replace-whitespace "_")))
1126 (while (string-match "\\s-" file-name)
1127 (setq file-name (replace-match s t t file-name))))
1130 (defun mm-file-name-delete-control (filename)
1131 "Delete control characters from FILENAME."
1132 (gnus-replace-in-string filename "[\x00-\x1f\x7f]" ""))
1134 (defun mm-file-name-delete-gotchas (filename)
1135 "Delete shell gotchas from FILENAME."
1136 (setq filename (gnus-replace-in-string filename "[<>|]" ""))
1137 (gnus-replace-in-string filename "^[.-]+" ""))
1139 (defun mm-save-part (handle &optional prompt)
1140 "Write HANDLE to a file.
1141 PROMPT overrides the default one used to ask user for a file name."
1142 (let* ((name (mail-content-type-get (mm-handle-type handle) 'name))
1143 (filename (mail-content-type-get
1144 (mm-handle-disposition handle) 'filename))
1147 (setq filename (gnus-map-function mm-file-name-rewrite-functions
1148 (file-name-nondirectory filename))))
1151 (read-file-name (or prompt "Save MIME part to: ")
1152 (or mm-default-directory default-directory)
1153 nil nil (or filename name ""))))
1154 (setq mm-default-directory (file-name-directory file))
1155 (and (or (not (file-exists-p file))
1156 (yes-or-no-p (format "File %s already exists; overwrite? "
1159 (mm-save-part-to-file handle file)
1162 (defun mm-save-part-to-file (handle file)
1163 (mm-with-unibyte-buffer
1164 (mm-insert-part handle)
1165 (let ((coding-system-for-write 'binary)
1166 (current-file-modes (default-file-modes))
1167 ;; Don't re-compress .gz & al. Arguably we should make
1168 ;; `file-name-handler-alist' nil, but that would chop
1169 ;; ange-ftp, which is reasonable to use here.
1170 (inhibit-file-name-operation 'write-region)
1171 (inhibit-file-name-handlers
1172 (cons 'jka-compr-handler inhibit-file-name-handlers)))
1173 (set-default-file-modes mm-attachment-file-modes)
1175 (write-region (point-min) (point-max) file)
1176 (set-default-file-modes current-file-modes)))))
1178 (defun mm-pipe-part (handle)
1179 "Pipe HANDLE to a process."
1180 (let* ((name (mail-content-type-get (mm-handle-type handle) 'name))
1182 (read-string "Shell command on MIME part: " mm-last-shell-command)))
1183 (mm-with-unibyte-buffer
1184 (mm-insert-part handle)
1185 (let ((coding-system-for-write 'binary))
1186 (shell-command-on-region (point-min) (point-max) command nil)))))
1188 (defun mm-interactively-view-part (handle)
1189 "Display HANDLE using METHOD."
1190 (let* ((type (mm-handle-media-type handle))
1192 (mapcar (lambda (i) (list (cdr (assoc 'viewer i))))
1193 (mailcap-mime-info type 'all)))
1194 (method (let ((minibuffer-local-completion-map
1195 mm-viewer-completion-map))
1196 (completing-read "Viewer: " methods))))
1197 (when (string= method "")
1198 (error "No method given"))
1199 (if (string-match "^[^% \t]+$" method)
1200 (setq method (concat method " %s")))
1201 (mm-display-external handle method)))
1203 (defun mm-preferred-alternative (handles &optional preferred)
1204 "Say which of HANDLES are preferred."
1205 (let ((prec (if preferred (list preferred)
1206 (mm-preferred-alternative-precedence handles)))
1207 p h result type handle)
1208 (while (setq p (pop prec))
1211 (setq handle (car h))
1212 (setq type (mm-handle-media-type handle))
1213 (when (and (equal p type)
1214 (mm-automatic-display-p handle)
1215 (or (stringp (car handle))
1216 (not (mm-handle-disposition handle))
1217 (equal (car (mm-handle-disposition handle))
1225 (defun mm-preferred-alternative-precedence (handles)
1226 "Return the precedence based on HANDLES and `mm-discouraged-alternatives'."
1227 (let ((seq (nreverse (mapcar #'mm-handle-media-type
1229 (dolist (disc (reverse mm-discouraged-alternatives))
1230 (dolist (elem (copy-sequence seq))
1231 (when (string-match disc elem)
1232 (setq seq (nconc (delete elem seq) (list elem))))))
1235 (defun mm-get-content-id (id)
1236 "Return the handle(s) referred to by ID."
1237 (cdr (assoc id mm-content-id-alist)))
1239 (defconst mm-image-type-regexps
1240 '(("/\\*.*XPM.\\*/" . xpm)
1244 ("\211PNG\r\n" . png)
1246 ("\\(MM\0\\*\\)\\|\\(II\\*\0\\)" . tiff)
1247 ("%!PS" . postscript))
1248 "Alist of (REGEXP . IMAGE-TYPE) pairs used to auto-detect image types.
1249 When the first bytes of an image file match REGEXP, it is assumed to
1250 be of image type IMAGE-TYPE.")
1252 ;; Steal from image.el. image-type-from-data suffers multi-line matching bug.
1253 (defun mm-image-type-from-buffer ()
1254 "Determine the image type from data in the current buffer.
1255 Value is a symbol specifying the image type or nil if type cannot
1257 (let ((types mm-image-type-regexps)
1259 (goto-char (point-min))
1260 (while (and types (null type))
1261 (let ((regexp (car (car types)))
1262 (image-type (cdr (car types))))
1263 (when (looking-at regexp)
1264 (setq type image-type))
1265 (setq types (cdr types))))
1268 (defun mm-get-image (handle)
1269 "Return an image instance based on HANDLE."
1270 (let ((type (mm-handle-media-subtype handle))
1272 ;; Allow some common translations.
1275 ((equal type "x-pixmap")
1277 ((equal type "x-xbitmap")
1279 ((equal type "x-portable-bitmap")
1282 (or (mm-handle-cache handle)
1283 (mm-with-unibyte-buffer
1284 (mm-insert-part handle)
1288 ;; Avoid testing `make-glyph' since W3 may define
1289 ;; a bogus version of it.
1290 (if (fboundp 'create-image)
1291 (create-image (buffer-string)
1292 (or (mm-image-type-from-buffer)
1295 (mm-create-image-xemacs type))))
1296 (mm-handle-set-cache handle spec))))))
1298 (defun mm-create-image-xemacs (type)
1301 ;; xbm images require special handling, since
1302 ;; the only way to create glyphs from these
1303 ;; (without a ton of work) is to write them
1304 ;; out to a file, and then create a file
1306 (let ((file (mm-make-temp-file
1307 (expand-file-name "emm.xbm"
1308 mm-tmp-directory))))
1311 (write-region (point-min) (point-max) file)
1312 (make-glyph (list (cons 'x file))))
1314 (delete-file file)))))
1318 (or (mm-image-type-from-buffer)
1320 :data (buffer-string))))))
1322 (defun mm-image-fit-p (handle)
1323 "Say whether the image in HANDLE will fit the current window."
1324 (let ((image (mm-get-image handle)))
1325 (if (fboundp 'glyph-width)
1326 ;; XEmacs' glyphs can actually tell us about their width, so
1327 ;; lets be nice and smart about them.
1328 (or mm-inline-large-images
1329 (and (< (glyph-width image) (window-pixel-width))
1330 (< (glyph-height image) (window-pixel-height))))
1331 (let* ((size (image-size image))
1334 (or mm-inline-large-images
1335 (and (< h (1- (window-height))) ; Don't include mode line.
1336 (< w (window-width))))))))
1338 (defun mm-valid-image-format-p (format)
1339 "Say whether FORMAT can be displayed natively by Emacs."
1342 ((fboundp 'valid-image-instantiator-format-p)
1343 (valid-image-instantiator-format-p format))
1345 ((fboundp 'image-type-available-p)
1346 (and (display-graphic-p)
1347 (image-type-available-p format)))
1348 ;; Nobody else can do images yet.
1352 (defun mm-valid-and-fit-image-p (format handle)
1353 "Say whether FORMAT can be displayed natively and HANDLE fits the window."
1354 (and (mm-valid-image-format-p format)
1355 (mm-image-fit-p handle)))
1357 (defun mm-find-part-by-type (handles type &optional notp recursive)
1358 "Search in HANDLES for part with TYPE.
1359 If NOTP, returns first non-matching part.
1360 If RECURSIVE, search recursively."
1363 (if (and recursive (stringp (caar handles)))
1364 (if (setq handle (mm-find-part-by-type (cdar handles) type
1368 (not (equal (mm-handle-media-type (car handles)) type))
1369 (equal (mm-handle-media-type (car handles)) type))
1370 (setq handle (car handles)
1372 (setq handles (cdr handles)))
1375 (defun mm-find-raw-part-by-type (ctl type &optional notp)
1376 (goto-char (point-min))
1377 (let* ((boundary (concat "--" (mm-handle-multipart-ctl-parameter ctl
1379 (close-delimiter (concat "^" (regexp-quote boundary) "--[ \t]*$"))
1381 (end (save-excursion
1382 (goto-char (point-max))
1383 (if (re-search-backward close-delimiter nil t)
1387 (setq boundary (concat "^" (regexp-quote boundary) "[ \t]*$"))
1388 (while (and (not result)
1389 (re-search-forward boundary end t))
1390 (goto-char (match-beginning 0))
1394 (narrow-to-region start (1- (point)))
1395 (when (let ((ctl (ignore-errors
1396 (mail-header-parse-content-type
1397 (mail-fetch-field "content-type")))))
1399 (not (equal (car ctl) type))
1400 (equal (car ctl) type)))
1401 (setq result (buffer-string))))))
1403 (setq start (point)))
1404 (when (and (not result) start)
1407 (narrow-to-region start end)
1408 (when (let ((ctl (ignore-errors
1409 (mail-header-parse-content-type
1410 (mail-fetch-field "content-type")))))
1412 (not (equal (car ctl) type))
1413 (equal (car ctl) type)))
1414 (setq result (buffer-string))))))
1417 (defvar mm-security-handle nil)
1419 (defsubst mm-set-handle-multipart-parameter (handle parameter value)
1420 ;; HANDLE could be a CTL.
1422 (put-text-property 0 (length (car handle)) parameter value
1425 (defun mm-possibly-verify-or-decrypt (parts ctl)
1426 (let ((type (car ctl))
1427 (subtype (cadr (split-string (car ctl) "/")))
1428 (mm-security-handle ctl) ;; (car CTL) is the type.
1429 protocol func functest)
1431 ((or (equal type "application/x-pkcs7-mime")
1432 (equal type "application/pkcs7-mime"))
1435 ((eq mm-decrypt-option 'never) nil)
1436 ((eq mm-decrypt-option 'always) t)
1437 ((eq mm-decrypt-option 'known) t)
1439 (format "Decrypt (S/MIME) part? "))))
1440 (mm-view-pkcs7 parts))
1441 (setq parts (mm-dissect-buffer t)))))
1442 ((equal subtype "signed")
1443 (unless (and (setq protocol
1444 (mm-handle-multipart-ctl-parameter ctl 'protocol))
1445 (not (equal protocol "multipart/mixed")))
1446 ;; The message is broken or draft-ietf-openpgp-multsig-01.
1447 (let ((protocols mm-verify-function-alist))
1449 (if (and (or (not (setq functest (nth 3 (car protocols))))
1450 (funcall functest parts ctl))
1451 (mm-find-part-by-type parts (caar protocols) nil t))
1452 (setq protocol (caar protocols)
1454 (setq protocols (cdr protocols))))))
1455 (setq func (nth 1 (assoc protocol mm-verify-function-alist)))
1457 ((eq mm-verify-option 'never) nil)
1458 ((eq mm-verify-option 'always) t)
1459 ((eq mm-verify-option 'known)
1461 (or (not (setq functest
1462 (nth 3 (assoc protocol
1463 mm-verify-function-alist))))
1464 (funcall functest parts ctl))))
1467 (format "Verify signed (%s) part? "
1468 (or (nth 2 (assoc protocol mm-verify-function-alist))
1469 (format "protocol=%s" protocol))))))
1472 (funcall func parts ctl)
1473 (mm-set-handle-multipart-parameter
1474 mm-security-handle 'gnus-details
1475 (format "Unknown sign protocol (%s)" protocol))))))
1476 ((equal subtype "encrypted")
1477 (unless (setq protocol
1478 (mm-handle-multipart-ctl-parameter ctl 'protocol))
1479 ;; The message is broken.
1480 (let ((parts parts))
1482 (if (assoc (mm-handle-media-type (car parts))
1483 mm-decrypt-function-alist)
1484 (setq protocol (mm-handle-media-type (car parts))
1486 (setq parts (cdr parts))))))
1487 (setq func (nth 1 (assoc protocol mm-decrypt-function-alist)))
1489 ((eq mm-decrypt-option 'never) nil)
1490 ((eq mm-decrypt-option 'always) t)
1491 ((eq mm-decrypt-option 'known)
1493 (or (not (setq functest
1494 (nth 3 (assoc protocol
1495 mm-decrypt-function-alist))))
1496 (funcall functest parts ctl))))
1499 (format "Decrypt (%s) part? "
1500 (or (nth 2 (assoc protocol mm-decrypt-function-alist))
1501 (format "protocol=%s" protocol))))))
1504 (setq parts (funcall func parts ctl))
1505 (mm-set-handle-multipart-parameter
1506 mm-security-handle 'gnus-details
1507 (format "Unknown encrypt protocol (%s)" protocol))))))
1511 (defun mm-multiple-handles (handles)
1512 (and (listp handles)
1513 (> (length handles) 1)
1514 (or (listp (car handles))
1515 (stringp (car handles)))))
1517 (defun mm-complicated-handles (handles)
1518 (and (listp (car handles))
1519 (> (length handles) 1)))
1521 (defun mm-merge-handles (handles1 handles2)
1523 (if (listp (car handles1))
1526 (if (listp (car handles2))
1530 (defun mm-readable-p (handle)
1531 "Say whether the content of HANDLE is readable."
1532 (and (< (with-current-buffer (mm-handle-buffer handle)
1533 (buffer-size)) 10000)
1534 (mm-with-unibyte-buffer
1535 (mm-insert-part handle)
1536 (and (eq (mm-body-7-or-8) '7bit)
1537 (not (mm-long-lines-p 76))))))
1539 (provide 'mm-decode)
1541 ;;; mm-decode.el ends here