1 ;;; mm-decode.el --- Functions for decoding MIME things
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006 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 ;; Mutt still uses this even though it has already been withdrawn.
285 "List of media types that are to be displayed inline.
286 See also `mm-inline-media-tests', which says how to display a media
288 :type '(repeat regexp)
289 :group 'mime-display)
291 (defcustom mm-keep-viewer-alive-types
292 '("application/postscript" "application/msword" "application/vnd.ms-excel"
293 "application/pdf" "application/x-dvi")
294 "List of media types for which the external viewer will not be killed
295 when selecting a different article."
297 :type '(repeat regexp)
298 :group 'mime-display)
300 (defcustom mm-automatic-display
301 '("text/plain" "text/enriched" "text/richtext" "text/html" "text/x-verbatim"
302 "text/x-vcard" "image/.*" "message/delivery-status" "multipart/.*"
303 "message/rfc822" "text/x-patch" "text/dns" "application/pgp-signature"
304 "application/emacs-lisp" "application/x-emacs-lisp"
305 "application/x-pkcs7-signature"
306 "application/pkcs7-signature" "application/x-pkcs7-mime"
307 "application/pkcs7-mime"
308 ;; Mutt still uses this even though it has already been withdrawn.
310 "A list of MIME types to be displayed automatically."
311 :type '(repeat regexp)
312 :group 'mime-display)
314 (defcustom mm-attachment-override-types '("text/x-vcard"
315 "application/pkcs7-mime"
316 "application/x-pkcs7-mime"
317 "application/pkcs7-signature"
318 "application/x-pkcs7-signature")
319 "Types to have \"attachment\" ignored if they can be displayed inline."
320 :type '(repeat regexp)
321 :group 'mime-display)
323 (defcustom mm-inline-override-types nil
324 "Types to be treated as attachments even if they can be displayed inline."
325 :type '(repeat regexp)
326 :group 'mime-display)
328 (defcustom mm-automatic-external-display nil
329 "List of MIME type regexps that will be displayed externally automatically."
330 :type '(repeat regexp)
331 :group 'mime-display)
333 (defcustom mm-discouraged-alternatives nil
334 "List of MIME types that are discouraged when viewing multipart/alternative.
335 Viewing agents are supposed to view the last possible part of a message,
336 as that is supposed to be the richest. However, users may prefer other
337 types instead, and this list says what types are most unwanted. If,
338 for instance, text/html parts are very unwanted, and text/richtext are
339 somewhat unwanted, then the value of this variable should be set
342 (\"text/html\" \"text/richtext\")
344 Adding \"image/.*\" might also be useful. Spammers use it as the
345 prefered part of multipart/alternative messages. See also
346 `gnus-buttonized-mime-types', to which adding \"multipart/alternative\"
347 enables you to choose manually one of two types those mails include."
348 :type '(repeat regexp) ;; See `mm-preferred-alternative-precedence'.
349 :group 'mime-display)
351 (defcustom mm-tmp-directory
352 (if (fboundp 'temp-directory)
354 (if (boundp 'temporary-file-directory)
355 temporary-file-directory
357 "Where mm will store its temporary files."
359 :group 'mime-display)
361 (defcustom mm-inline-large-images nil
362 "If non-nil, then all images fit in the buffer."
364 :group 'mime-display)
366 (defvar mm-file-name-rewrite-functions
367 '(mm-file-name-delete-control mm-file-name-delete-gotchas)
368 "*List of functions used for rewriting file names of MIME parts.
369 Each function takes a file name as input and returns a file name.
371 Ready-made functions include
372 `mm-file-name-delete-control'
373 `mm-file-name-delete-gotchas'
374 `mm-file-name-delete-whitespace',
375 `mm-file-name-trim-whitespace',
376 `mm-file-name-collapse-whitespace',
377 `mm-file-name-replace-whitespace',
378 `capitalize', `downcase', `upcase', and
381 (defvar mm-path-name-rewrite-functions nil
382 "*List of functions for rewriting the full file names of MIME parts.
383 This is used when viewing parts externally, and is meant for
384 transforming the absolute name so that non-compliant programs can find
385 the file where it's saved.
387 Each function takes a file name as input and returns a file name.")
389 (defvar mm-file-name-replace-whitespace nil
390 "String used for replacing whitespace characters; default is `\"_\"'.")
392 (defcustom mm-default-directory nil
393 "The default directory where mm will save files.
394 If not set, `default-directory' will be used."
395 :type '(choice directory (const :tag "Default" nil))
396 :group 'mime-display)
398 (defcustom mm-attachment-file-modes 384
399 "Set the mode bits of saved attachments to this integer."
402 :group 'mime-display)
404 (defcustom mm-external-terminal-program "xterm"
405 "The program to start an external terminal."
408 :group 'mime-display)
410 ;;; Internal variables.
412 (defvar mm-last-shell-command "")
413 (defvar mm-content-id-alist nil)
414 (defvar mm-postponed-undisplay-list nil)
416 ;; According to RFC2046, in particular, in a digest, the default
417 ;; Content-Type value for a body part is changed from "text/plain" to
419 (defvar mm-dissect-default-type "text/plain")
421 (autoload 'mml2015-verify "mml2015")
422 (autoload 'mml2015-verify-test "mml2015")
423 (autoload 'mml-smime-verify "mml-smime")
424 (autoload 'mml-smime-verify-test "mml-smime")
426 (defvar mm-verify-function-alist
427 '(("application/pgp-signature" mml2015-verify "PGP" mml2015-verify-test)
428 ("application/x-gnus-pgp-signature" mm-uu-pgp-signed-extract-1 "PGP"
429 mm-uu-pgp-signed-test)
430 ("application/pkcs7-signature" mml-smime-verify "S/MIME"
431 mml-smime-verify-test)
432 ("application/x-pkcs7-signature" mml-smime-verify "S/MIME"
433 mml-smime-verify-test)))
435 (defcustom mm-verify-option 'never
436 "Option of verifying signed parts.
437 `never', not verify; `always', always verify;
438 `known', only verify known protocols. Otherwise, ask user."
440 :type '(choice (item always)
442 (item :tag "only known protocols" known)
443 (item :tag "ask" nil))
444 :group 'mime-security)
446 (autoload 'mml2015-decrypt "mml2015")
447 (autoload 'mml2015-decrypt-test "mml2015")
449 (defvar mm-decrypt-function-alist
450 '(("application/pgp-encrypted" mml2015-decrypt "PGP" mml2015-decrypt-test)
451 ("application/x-gnus-pgp-encrypted" mm-uu-pgp-encrypted-extract-1 "PGP"
452 mm-uu-pgp-encrypted-test)))
454 (defcustom mm-decrypt-option nil
455 "Option of decrypting encrypted parts.
456 `never', not decrypt; `always', always decrypt;
457 `known', only decrypt known protocols. Otherwise, ask user."
459 :type '(choice (item always)
461 (item :tag "only known protocols" known)
462 (item :tag "ask" nil))
463 :group 'mime-security)
465 (defvar mm-viewer-completion-map
466 (let ((map (make-sparse-keymap 'mm-viewer-completion-map)))
467 (set-keymap-parent map minibuffer-local-completion-map)
468 ;; Should we bind other key to minibuffer-complete-word?
469 (define-key map " " 'self-insert-command)
471 "Keymap for input viewer with completion.")
473 (defvar mm-viewer-completion-map
474 (let ((map (make-sparse-keymap 'mm-viewer-completion-map)))
475 (set-keymap-parent map minibuffer-local-completion-map)
476 ;; Should we bind other key to minibuffer-complete-word?
477 (define-key map " " 'self-insert-command)
479 "Keymap for input viewer with completion.")
483 (defun mm-alist-to-plist (alist)
484 "Convert association list ALIST into the equivalent property-list form.
485 The plist is returned. This converts from
487 \((a . 1) (b . 2) (c . 3))
493 The original alist is not modified. See also `destructive-alist-to-plist'."
496 (let ((el (car alist)))
497 (setq plist (cons (cdr el) (cons (car el) plist))))
498 (setq alist (cdr alist)))
501 (defun mm-keep-viewer-alive-p (handle)
502 "Say whether external viewer for HANDLE should stay alive."
503 (let ((types mm-keep-viewer-alive-types)
504 (type (mm-handle-media-type handle))
507 (while (setq ty (pop types))
508 (when (string-match ty type)
509 (throw 'found t))))))
511 (defun mm-handle-set-external-undisplayer (handle function)
512 "Set the undisplayer for HANDLE to FUNCTION.
513 Postpone undisplaying of viewers for types in
514 `mm-keep-viewer-alive-types'."
515 (if (mm-keep-viewer-alive-p handle)
516 (let ((new-handle (copy-sequence handle)))
517 (mm-handle-set-undisplayer new-handle function)
518 (mm-handle-set-undisplayer handle nil)
519 (push new-handle mm-postponed-undisplay-list))
520 (mm-handle-set-undisplayer handle function)))
522 (defun mm-destroy-postponed-undisplay-list ()
523 (when mm-postponed-undisplay-list
524 (message "Destroying external MIME viewers")
525 (mm-destroy-parts mm-postponed-undisplay-list)))
527 (defun mm-dissect-buffer (&optional no-strict-mime loose-mime from)
528 "Dissect the current buffer and return a list of MIME handles."
530 (let (ct ctl type subtype cte cd description id result)
532 (mail-narrow-to-head)
533 (when (or no-strict-mime
535 (mail-fetch-field "mime-version"))
536 (setq ct (mail-fetch-field "content-type")
537 ctl (and ct (mail-header-parse-content-type ct))
538 cte (mail-fetch-field "content-transfer-encoding")
539 cd (mail-fetch-field "content-disposition")
540 description (mail-fetch-field "content-description")
541 id (mail-fetch-field "content-id"))
543 (setq from (mail-fetch-field "from")))
544 ;; FIXME: In some circumstances, this code is running within
545 ;; an unibyte macro. mail-extract-address-components
546 ;; creates unibyte buffers. This `if', though not a perfect
547 ;; solution, avoids most of them.
549 (setq from (cadr (mail-extract-address-components from))))))
551 (not (string-match "/" (car ctl))))
552 (mm-dissect-singlepart
553 (list mm-dissect-default-type)
554 (and cte (intern (downcase (mail-header-strip cte))))
556 (and cd (mail-header-parse-content-disposition cd))
558 (setq type (split-string (car ctl) "/"))
559 (setq subtype (cadr type)
564 ((equal type "multipart")
565 (let ((mm-dissect-default-type (if (equal subtype "digest")
568 (start (cdr (assq 'start (cdr ctl)))))
569 (add-text-properties 0 (length (car ctl))
570 (mm-alist-to-plist (cdr ctl)) (car ctl))
572 ;; what really needs to be done here is a way to link a
573 ;; MIME handle back to it's parent MIME handle (in a multilevel
574 ;; MIME article). That would probably require changing
575 ;; the mm-handle API so we simply store the multipart buffer
576 ;; name as a text property of the "multipart/whatever" string.
577 (add-text-properties 0 (length (car ctl))
578 (list 'buffer (mm-copy-to-buffer)
582 (cons (car ctl) (mm-dissect-multipart ctl from))))
584 (mm-possibly-verify-or-decrypt
585 (mm-dissect-singlepart
587 (and cte (intern (downcase (mail-header-strip cte))))
589 (and cd (mail-header-parse-content-disposition cd))
593 (when (string-match " *<\\(.*\\)> *" id)
594 (setq id (match-string 1 id)))
595 (push (cons id result) mm-content-id-alist))
598 (defun mm-dissect-singlepart (ctl cte &optional force cdl description id)
600 (if (equal "text/plain" (car ctl))
604 (mm-copy-to-buffer) ctl cte nil cdl description nil id)))
606 (defun mm-dissect-multipart (ctl from)
607 (goto-char (point-min))
608 (let* ((boundary (concat "\n--" (mail-content-type-get ctl 'boundary)))
609 (close-delimiter (concat (regexp-quote boundary) "--[ \t]*$"))
612 (goto-char (point-max))
613 (if (re-search-backward close-delimiter nil t)
616 (setq boundary (concat (regexp-quote boundary) "[ \t]*$"))
617 (while (and (< (point) end) (re-search-forward boundary end t))
618 (goto-char (match-beginning 0))
622 (narrow-to-region start (point))
623 (setq parts (nconc (list (mm-dissect-buffer t nil from)) parts)))))
625 (or (looking-at boundary)
627 (setq start (point)))
628 (when (and start (< start end))
631 (narrow-to-region start end)
632 (setq parts (nconc (list (mm-dissect-buffer t nil from)) parts)))))
633 (mm-possibly-verify-or-decrypt (nreverse parts) ctl)))
635 (defun mm-copy-to-buffer ()
636 "Copy the contents of the current buffer to a fresh buffer."
638 (let ((obuf (current-buffer))
640 (goto-char (point-min))
641 (search-forward-regexp "^\n" nil t)
644 ;; Preserve the data's unibyteness (for url-insert-file-contents).
645 (let ((default-enable-multibyte-characters (mm-multibyte-p)))
646 (generate-new-buffer " *mm*")))
647 (insert-buffer-substring obuf beg)
650 (defun mm-display-parts (handle &optional no-default)
651 (if (stringp (car handle))
652 (mapcar 'mm-display-parts (cdr handle))
653 (if (bufferp (car handle))
655 (narrow-to-region (point) (point))
656 (mm-display-part handle)
657 (goto-char (point-max)))
658 (mapcar 'mm-display-parts handle))))
660 (defun mm-display-part (handle &optional no-default)
661 "Display the MIME part represented by HANDLE.
662 Returns nil if the part is removed; inline if displayed inline;
663 external if displayed external."
665 (mailcap-parse-mailcaps)
666 (if (mm-handle-displayed-p handle)
667 (mm-remove-part handle)
668 (let* ((type (mm-handle-media-type handle))
669 (method (mailcap-mime-info type))
670 (filename (or (mail-content-type-get
671 (mm-handle-disposition handle) 'filename)
672 (mail-content-type-get
673 (mm-handle-type handle) 'name)
675 (external mm-enable-external))
676 (if (and (mm-inlinable-p handle)
677 (mm-inlined-p handle))
680 (mm-display-inline handle)
684 (if (and (not method)
685 (equal "text" (car (split-string type))))
688 (mm-insert-inline handle (mm-get-part handle))
690 (if (and method ;; If nil, we always use "save".
691 (stringp method) ;; 'mailcap-save-binary-file
692 (or (eq mm-enable-external t)
693 (and (eq mm-enable-external 'ask)
696 "Display part (" type
697 ") using external program"
698 ;; Can non-string method ever happen?
701 " \"" (format method filename) "\"")
708 handle (or method 'mailcap-save-binary-file))
710 handle 'mailcap-save-binary-file)))))))))
712 (defun mm-display-external (handle method)
713 "Display HANDLE using METHOD."
714 (let ((outbuf (current-buffer)))
715 (mm-with-unibyte-buffer
716 (if (functionp method)
717 (let ((cur (current-buffer)))
718 (if (eq method 'mailcap-save-binary-file)
720 (set-buffer (generate-new-buffer " *mm*"))
722 (mm-insert-part handle)
723 (let ((win (get-buffer-window cur t)))
725 (select-window win)))
726 (switch-to-buffer (generate-new-buffer " *mm*")))
727 (buffer-disable-undo)
728 (mm-set-buffer-file-coding-system mm-binary-coding-system)
729 (insert-buffer-substring cur)
730 (goto-char (point-min))
732 (message "Viewing with %s" method))
733 (let ((mm (current-buffer))
734 (non-viewer (assq 'non-viewer
736 (mm-handle-media-type handle) t))))
740 (mm-save-part handle))
741 (when (and (not non-viewer)
743 (mm-handle-set-undisplayer handle mm)))))
744 ;; The function is a string to be executed.
745 (mm-insert-part handle)
746 (let* ((dir (mm-make-temp-file
747 (expand-file-name "emm." mm-tmp-directory) 'dir))
749 (mail-content-type-get
750 (mm-handle-disposition handle) 'filename)
751 (mail-content-type-get
752 (mm-handle-type handle) 'name)))
753 (mime-info (mailcap-mime-info
754 (mm-handle-media-type handle) t))
755 (needsterm (or (assoc "needsterm" mime-info)
756 (assoc "needsterminal" mime-info)))
757 (copiousoutput (assoc "copiousoutput" mime-info))
759 ;; We create a private sub-directory where we store our files.
760 (set-file-modes dir 448)
762 (setq file (expand-file-name
763 (gnus-map-function mm-file-name-rewrite-functions
764 (file-name-nondirectory filename))
766 (setq file (mm-make-temp-file (expand-file-name "mm." dir)))
768 ;; Use nametemplate (defined in RFC1524) if it is
769 ;; specified in mailcap.
770 (if (assoc "nametemplate" mime-info)
771 (format (cdr (assoc "nametemplate" mime-info)) file)
772 ;; Add a suffix according to `mailcap-mime-extensions'.
773 (concat file (car (rassoc (mm-handle-media-type handle)
774 mailcap-mime-extensions))))))
775 (unless (string-equal file newname)
776 (when (file-exists-p file)
777 (rename-file file newname))
778 (setq file newname))))
779 (let ((coding-system-for-write mm-binary-coding-system))
780 (write-region (point-min) (point-max) file nil 'nomesg))
781 (message "Viewing with %s" method)
784 (let ((command (mm-mailcap-command
785 method file (mm-handle-type handle))))
788 (start-process "*display*" nil
789 mm-external-terminal-program
791 shell-command-switch command)
799 shell-command-switch command)))
802 (set-process-sentinel
803 (get-buffer-process buffer)
804 `(lambda (process state)
805 (if (eq 'exit (process-status process))
806 (gnus-configure-windows
807 ',gnus-current-window-configuration))))
808 (gnus-configure-windows 'display-term))
809 (mm-handle-set-external-undisplayer handle (cons file buffer)))
810 (message "Displaying %s..." command))
813 (with-current-buffer outbuf
819 (call-process shell-file-name nil
821 (generate-new-buffer " *mm*"))
825 method file (mm-handle-type handle)))
826 (if (buffer-live-p buffer)
827 (with-current-buffer buffer
830 (ignore-errors (delete-file file))
831 (ignore-errors (delete-directory
832 (file-name-directory file)))
833 (ignore-errors (kill-buffer buffer))))))
836 ;; Deleting the temp file should be postponed for some wrappers,
837 ;; shell scripts, and so on, which might exit right after having
838 ;; started a viewer command as a background job.
839 (let ((command (mm-mailcap-command
840 method file (mm-handle-type handle))))
843 (start-process "*display*"
845 (generate-new-buffer " *mm*"))
847 shell-command-switch command)
848 (set-process-sentinel
849 (get-buffer-process buffer)
850 (lexical-let ;; Don't use `let'.
851 ;; Function used to remove temp file and directory.
853 ;; Don't use `ignore-errors'.
859 ,(file-name-directory file))
861 ;; Form uses to kill the process buffer and
862 ;; remove the undisplayer.
864 (kill-buffer ,buffer)
866 (list 'mm-handle-set-undisplayer
869 ;; Message to be issued when the process exits.
870 (done (format "Displaying %s...done" command))
871 ;; In particular, the timer object (which is
872 ;; a vector in Emacs but is a list in XEmacs)
873 ;; requires that it is lexically scoped.
874 (timer (run-at-time 2.0 nil 'ignore)))
875 (lambda (process state)
876 (when (eq 'exit (process-status process))
877 (if (memq timer timer-list)
878 (timer-set-function timer fn)
880 (ignore-errors (eval fm))
881 (message "%s" done))))))
882 (mm-handle-set-external-undisplayer
883 handle (cons file buffer)))
884 (message "Displaying %s..." command))
887 (defun mm-mailcap-command (method file type-list)
888 (let ((ctl (cdr type-list))
892 (while (string-match "%{\\([^}]+\\)}\\|'%s'\\|\"%s\"\\|%s\\|%t\\|%%"
894 (push (substring method beg (match-beginning 0)) out)
895 (setq beg (match-end 0)
896 total (match-string 0 method)
897 sub (match-string 1 method))
899 ((string= total "%%")
901 ((or (string= total "%s")
902 ;; We do our own quoting.
903 (string= total "'%s'")
904 (string= total "\"%s\""))
905 (setq uses-stdin nil)
906 (push (shell-quote-argument
907 (gnus-map-function mm-path-name-rewrite-functions file)) out))
908 ((string= total "%t")
909 (push (shell-quote-argument (car type-list)) out))
911 (push (shell-quote-argument (or (cdr (assq (intern sub) ctl)) "")) out))))
912 (push (substring method beg (length method)) out)
915 (push (shell-quote-argument
916 (gnus-map-function mm-path-name-rewrite-functions file))
918 (mapconcat 'identity (nreverse out) "")))
920 (defun mm-remove-parts (handles)
921 "Remove the displayed MIME parts represented by HANDLES."
922 (if (and (listp handles)
923 (bufferp (car handles)))
924 (mm-remove-part handles)
926 (while (setq handle (pop handles))
929 (when (buffer-live-p (get-text-property 0 'buffer handle))
930 (kill-buffer (get-text-property 0 'buffer handle))))
932 (stringp (car handle)))
933 (mm-remove-parts (cdr handle)))
935 (mm-remove-part handle)))))))
937 (defun mm-destroy-parts (handles)
938 "Remove the displayed MIME parts represented by HANDLES."
939 (if (and (listp handles)
940 (bufferp (car handles)))
941 (mm-destroy-part handles)
943 (while (setq handle (pop handles))
946 (when (buffer-live-p (get-text-property 0 'buffer handle))
947 (kill-buffer (get-text-property 0 'buffer handle))))
949 (stringp (car handle)))
950 (mm-destroy-parts handle))
952 (mm-destroy-part handle)))))))
954 (defun mm-remove-part (handle)
955 "Remove the displayed MIME part represented by HANDLE."
957 (let ((object (mm-handle-undisplayer handle)))
960 ;; Internally displayed part.
961 ((mm-annotationp object)
962 (delete-annotation object))
963 ((or (functionp object)
965 (eq (car object) 'lambda)))
967 ;; Externally displayed part.
970 (while (get-buffer-process (cdr object))
971 (interrupt-process (get-buffer-process (cdr object)))
972 (message "Waiting for external displayer to die...")
976 (ignore-errors (and (cdr object) (kill-buffer (cdr object))))
977 (message "Waiting for external displayer to die...done")
978 (ignore-errors (delete-file (car object)))
979 (ignore-errors (delete-directory (file-name-directory
982 (when (buffer-live-p object)
983 (kill-buffer object)))))
984 (mm-handle-set-undisplayer handle nil))))
986 (defun mm-display-inline (handle)
987 (let* ((type (mm-handle-media-type handle))
988 (function (cadr (mm-assoc-string-match mm-inline-media-tests type))))
989 (funcall function handle)
990 (goto-char (point-min))))
992 (defun mm-assoc-string-match (alist type)
994 (when (string-match (car elem) type)
997 (defun mm-automatic-display-p (handle)
998 "Say whether the user wants HANDLE to be displayed automatically."
999 (let ((methods mm-automatic-display)
1000 (type (mm-handle-media-type handle))
1002 (while (setq method (pop methods))
1003 (when (and (not (mm-inline-override-p handle))
1004 (string-match method type))
1009 (defun mm-inlinable-p (handle)
1010 "Say whether HANDLE can be displayed inline."
1011 (let ((alist mm-inline-media-tests)
1012 (type (mm-handle-media-type handle))
1015 (when (string-match (caar alist) type)
1016 (setq test (caddar alist)
1018 (setq test (funcall test handle)))
1022 (defun mm-inlined-p (handle)
1023 "Say whether the user wants HANDLE to be displayed inline."
1024 (let ((methods mm-inlined-types)
1025 (type (mm-handle-media-type handle))
1027 (while (setq method (pop methods))
1028 (when (and (not (mm-inline-override-p handle))
1029 (string-match method type))
1034 (defun mm-attachment-override-p (handle)
1035 "Say whether HANDLE should have attachment behavior overridden."
1036 (let ((types mm-attachment-override-types)
1037 (type (mm-handle-media-type handle))
1040 (while (setq ty (pop types))
1041 (when (and (string-match ty type)
1042 (mm-inlinable-p handle))
1043 (throw 'found t))))))
1045 (defun mm-inline-override-p (handle)
1046 "Say whether HANDLE should have inline behavior overridden."
1047 (let ((types mm-inline-override-types)
1048 (type (mm-handle-media-type handle))
1051 (while (setq ty (pop types))
1052 (when (string-match ty type)
1053 (throw 'found t))))))
1055 (defun mm-automatic-external-display-p (type)
1056 "Return the user-defined method for TYPE."
1057 (let ((methods mm-automatic-external-display)
1059 (while (setq method (pop methods))
1060 (when (string-match method type)
1065 (defun mm-destroy-part (handle)
1066 "Destroy the data structures connected to HANDLE."
1067 (when (listp handle)
1068 (mm-remove-part handle)
1069 (when (buffer-live-p (mm-handle-buffer handle))
1070 (kill-buffer (mm-handle-buffer handle)))))
1072 (defun mm-handle-displayed-p (handle)
1073 "Say whether HANDLE is displayed or not."
1074 (mm-handle-undisplayer handle))
1077 ;;; Functions for outputting parts
1080 (defun mm-get-part (handle)
1081 "Return the contents of HANDLE as a string."
1082 (mm-with-unibyte-buffer
1083 (insert (with-current-buffer (mm-handle-buffer handle)
1084 (mm-with-unibyte-current-buffer
1086 (mm-decode-content-transfer-encoding
1087 (mm-handle-encoding handle)
1088 (mm-handle-media-type handle))
1091 (defun mm-insert-part (handle)
1092 "Insert the contents of HANDLE in the current buffer."
1095 (cond ((eq (mail-content-type-get (mm-handle-type handle) 'charset)
1097 (with-current-buffer (mm-handle-buffer handle)
1100 (mm-string-as-multibyte (mm-get-part handle)))
1102 (mm-get-part handle))))))
1104 (defun mm-file-name-delete-whitespace (file-name)
1105 "Remove all whitespace characters from FILE-NAME."
1106 (while (string-match "\\s-+" file-name)
1107 (setq file-name (replace-match "" t t file-name)))
1110 (defun mm-file-name-trim-whitespace (file-name)
1111 "Remove leading and trailing whitespace characters from FILE-NAME."
1112 (when (string-match "\\`\\s-+" file-name)
1113 (setq file-name (substring file-name (match-end 0))))
1114 (when (string-match "\\s-+\\'" file-name)
1115 (setq file-name (substring file-name 0 (match-beginning 0))))
1118 (defun mm-file-name-collapse-whitespace (file-name)
1119 "Collapse multiple whitespace characters in FILE-NAME."
1120 (while (string-match "\\s-\\s-+" file-name)
1121 (setq file-name (replace-match " " t t file-name)))
1124 (defun mm-file-name-replace-whitespace (file-name)
1125 "Replace whitespace characters in FILE-NAME with underscores.
1126 Set the option `mm-file-name-replace-whitespace' to any other
1127 string if you do not like underscores."
1128 (let ((s (or mm-file-name-replace-whitespace "_")))
1129 (while (string-match "\\s-" file-name)
1130 (setq file-name (replace-match s t t file-name))))
1133 (defun mm-file-name-delete-control (filename)
1134 "Delete control characters from FILENAME."
1135 (gnus-replace-in-string filename "[\x00-\x1f\x7f]" ""))
1137 (defun mm-file-name-delete-gotchas (filename)
1138 "Delete shell gotchas from FILENAME."
1139 (setq filename (gnus-replace-in-string filename "[<>|]" ""))
1140 (gnus-replace-in-string filename "^[.-]+" ""))
1142 (defun mm-save-part (handle &optional prompt)
1143 "Write HANDLE to a file.
1144 PROMPT overrides the default one used to ask user for a file name."
1145 (let* ((name (mail-content-type-get (mm-handle-type handle) 'name))
1146 (filename (mail-content-type-get
1147 (mm-handle-disposition handle) 'filename))
1150 (setq filename (gnus-map-function mm-file-name-rewrite-functions
1151 (file-name-nondirectory filename))))
1154 (read-file-name (or prompt "Save MIME part to: ")
1155 (or mm-default-directory default-directory)
1156 nil nil (or filename name ""))))
1157 (setq mm-default-directory (file-name-directory file))
1158 (and (or (not (file-exists-p file))
1159 (yes-or-no-p (format "File %s already exists; overwrite? "
1162 (mm-save-part-to-file handle file)
1165 (defun mm-save-part-to-file (handle file)
1166 (mm-with-unibyte-buffer
1167 (mm-insert-part handle)
1168 (let ((coding-system-for-write 'binary)
1169 (current-file-modes (default-file-modes))
1170 ;; Don't re-compress .gz & al. Arguably we should make
1171 ;; `file-name-handler-alist' nil, but that would chop
1172 ;; ange-ftp, which is reasonable to use here.
1173 (inhibit-file-name-operation 'write-region)
1174 (inhibit-file-name-handlers
1175 (cons 'jka-compr-handler inhibit-file-name-handlers)))
1176 (set-default-file-modes mm-attachment-file-modes)
1178 (write-region (point-min) (point-max) file)
1179 (set-default-file-modes current-file-modes)))))
1181 (defun mm-pipe-part (handle)
1182 "Pipe HANDLE to a process."
1183 (let* ((name (mail-content-type-get (mm-handle-type handle) 'name))
1185 (read-string "Shell command on MIME part: " mm-last-shell-command)))
1186 (mm-with-unibyte-buffer
1187 (mm-insert-part handle)
1188 (let ((coding-system-for-write 'binary))
1189 (shell-command-on-region (point-min) (point-max) command nil)))))
1191 (defun mm-interactively-view-part (handle)
1192 "Display HANDLE using METHOD."
1193 (let* ((type (mm-handle-media-type handle))
1195 (mapcar (lambda (i) (list (cdr (assoc 'viewer i))))
1196 (mailcap-mime-info type 'all)))
1197 (method (let ((minibuffer-local-completion-map
1198 mm-viewer-completion-map))
1199 (completing-read "Viewer: " methods))))
1200 (when (string= method "")
1201 (error "No method given"))
1202 (if (string-match "^[^% \t]+$" method)
1203 (setq method (concat method " %s")))
1204 (mm-display-external handle method)))
1206 (defun mm-preferred-alternative (handles &optional preferred)
1207 "Say which of HANDLES are preferred."
1208 (let ((prec (if preferred (list preferred)
1209 (mm-preferred-alternative-precedence handles)))
1210 p h result type handle)
1211 (while (setq p (pop prec))
1214 (setq handle (car h))
1215 (setq type (mm-handle-media-type handle))
1216 (when (and (equal p type)
1217 (mm-automatic-display-p handle)
1218 (or (stringp (car handle))
1219 (not (mm-handle-disposition handle))
1220 (equal (car (mm-handle-disposition handle))
1228 (defun mm-preferred-alternative-precedence (handles)
1229 "Return the precedence based on HANDLES and `mm-discouraged-alternatives'."
1230 (let ((seq (nreverse (mapcar #'mm-handle-media-type
1232 (dolist (disc (reverse mm-discouraged-alternatives))
1233 (dolist (elem (copy-sequence seq))
1234 (when (string-match disc elem)
1235 (setq seq (nconc (delete elem seq) (list elem))))))
1238 (defun mm-get-content-id (id)
1239 "Return the handle(s) referred to by ID."
1240 (cdr (assoc id mm-content-id-alist)))
1242 (defconst mm-image-type-regexps
1243 '(("/\\*.*XPM.\\*/" . xpm)
1247 ("\211PNG\r\n" . png)
1249 ("\\(MM\0\\*\\)\\|\\(II\\*\0\\)" . tiff)
1250 ("%!PS" . postscript))
1251 "Alist of (REGEXP . IMAGE-TYPE) pairs used to auto-detect image types.
1252 When the first bytes of an image file match REGEXP, it is assumed to
1253 be of image type IMAGE-TYPE.")
1255 ;; Steal from image.el. image-type-from-data suffers multi-line matching bug.
1256 (defun mm-image-type-from-buffer ()
1257 "Determine the image type from data in the current buffer.
1258 Value is a symbol specifying the image type or nil if type cannot
1260 (let ((types mm-image-type-regexps)
1262 (goto-char (point-min))
1263 (while (and types (null type))
1264 (let ((regexp (car (car types)))
1265 (image-type (cdr (car types))))
1266 (when (looking-at regexp)
1267 (setq type image-type))
1268 (setq types (cdr types))))
1271 (defun mm-get-image (handle)
1272 "Return an image instance based on HANDLE."
1273 (let ((type (mm-handle-media-subtype handle))
1275 ;; Allow some common translations.
1278 ((equal type "x-pixmap")
1280 ((equal type "x-xbitmap")
1282 ((equal type "x-portable-bitmap")
1285 (or (mm-handle-cache handle)
1286 (mm-with-unibyte-buffer
1287 (mm-insert-part handle)
1291 ;; Avoid testing `make-glyph' since W3 may define
1292 ;; a bogus version of it.
1293 (if (fboundp 'create-image)
1294 (create-image (buffer-string)
1295 (or (mm-image-type-from-buffer)
1298 (mm-create-image-xemacs type))))
1299 (mm-handle-set-cache handle spec))))))
1301 (defun mm-create-image-xemacs (type)
1304 ;; xbm images require special handling, since
1305 ;; the only way to create glyphs from these
1306 ;; (without a ton of work) is to write them
1307 ;; out to a file, and then create a file
1309 (let ((file (mm-make-temp-file
1310 (expand-file-name "emm.xbm"
1311 mm-tmp-directory))))
1314 (write-region (point-min) (point-max) file)
1315 (make-glyph (list (cons 'x file))))
1317 (delete-file file)))))
1321 (or (mm-image-type-from-buffer)
1323 :data (buffer-string))))))
1325 (defun mm-image-fit-p (handle)
1326 "Say whether the image in HANDLE will fit the current window."
1327 (let ((image (mm-get-image handle)))
1328 (if (fboundp 'glyph-width)
1329 ;; XEmacs' glyphs can actually tell us about their width, so
1330 ;; lets be nice and smart about them.
1331 (or mm-inline-large-images
1332 (and (< (glyph-width image) (window-pixel-width))
1333 (< (glyph-height image) (window-pixel-height))))
1334 (let* ((size (image-size image))
1337 (or mm-inline-large-images
1338 (and (< h (1- (window-height))) ; Don't include mode line.
1339 (< w (window-width))))))))
1341 (defun mm-valid-image-format-p (format)
1342 "Say whether FORMAT can be displayed natively by Emacs."
1345 ((fboundp 'valid-image-instantiator-format-p)
1346 (valid-image-instantiator-format-p format))
1348 ((fboundp 'image-type-available-p)
1349 (and (display-graphic-p)
1350 (image-type-available-p format)))
1351 ;; Nobody else can do images yet.
1355 (defun mm-valid-and-fit-image-p (format handle)
1356 "Say whether FORMAT can be displayed natively and HANDLE fits the window."
1357 (and (mm-valid-image-format-p format)
1358 (mm-image-fit-p handle)))
1360 (defun mm-find-part-by-type (handles type &optional notp recursive)
1361 "Search in HANDLES for part with TYPE.
1362 If NOTP, returns first non-matching part.
1363 If RECURSIVE, search recursively."
1366 (if (and recursive (stringp (caar handles)))
1367 (if (setq handle (mm-find-part-by-type (cdar handles) type
1371 (not (equal (mm-handle-media-type (car handles)) type))
1372 (equal (mm-handle-media-type (car handles)) type))
1373 (setq handle (car handles)
1375 (setq handles (cdr handles)))
1378 (defun mm-find-raw-part-by-type (ctl type &optional notp)
1379 (goto-char (point-min))
1380 (let* ((boundary (concat "--" (mm-handle-multipart-ctl-parameter ctl
1382 (close-delimiter (concat "^" (regexp-quote boundary) "--[ \t]*$"))
1384 (end (save-excursion
1385 (goto-char (point-max))
1386 (if (re-search-backward close-delimiter nil t)
1390 (setq boundary (concat "^" (regexp-quote boundary) "[ \t]*$"))
1391 (while (and (not result)
1392 (re-search-forward boundary end t))
1393 (goto-char (match-beginning 0))
1397 (narrow-to-region start (1- (point)))
1398 (when (let* ((ct (mail-fetch-field "content-type"))
1399 (ctl (and ct (mail-header-parse-content-type ct))))
1401 (not (equal (car ctl) type))
1402 (equal (car ctl) type)))
1403 (setq result (buffer-string))))))
1405 (setq start (point)))
1406 (when (and (not result) start)
1409 (narrow-to-region start end)
1410 (when (let* ((ct (mail-fetch-field "content-type"))
1411 (ctl (and ct (mail-header-parse-content-type ct))))
1413 (not (equal (car ctl) type))
1414 (equal (car ctl) type)))
1415 (setq result (buffer-string))))))
1418 (defvar mm-security-handle nil)
1420 (defsubst mm-set-handle-multipart-parameter (handle parameter value)
1421 ;; HANDLE could be a CTL.
1423 (put-text-property 0 (length (car handle)) parameter value
1426 (defun mm-possibly-verify-or-decrypt (parts ctl)
1427 (let ((type (car ctl))
1428 (subtype (cadr (split-string (car ctl) "/")))
1429 (mm-security-handle ctl) ;; (car CTL) is the type.
1430 protocol func functest)
1432 ((or (equal type "application/x-pkcs7-mime")
1433 (equal type "application/pkcs7-mime"))
1436 ((eq mm-decrypt-option 'never) nil)
1437 ((eq mm-decrypt-option 'always) t)
1438 ((eq mm-decrypt-option 'known) t)
1440 (format "Decrypt (S/MIME) part? "))))
1441 (mm-view-pkcs7 parts))
1442 (setq parts (mm-dissect-buffer t)))))
1443 ((equal subtype "signed")
1444 (unless (and (setq protocol
1445 (mm-handle-multipart-ctl-parameter ctl 'protocol))
1446 (not (equal protocol "multipart/mixed")))
1447 ;; The message is broken or draft-ietf-openpgp-multsig-01.
1448 (let ((protocols mm-verify-function-alist))
1450 (if (and (or (not (setq functest (nth 3 (car protocols))))
1451 (funcall functest parts ctl))
1452 (mm-find-part-by-type parts (caar protocols) nil t))
1453 (setq protocol (caar protocols)
1455 (setq protocols (cdr protocols))))))
1456 (setq func (nth 1 (assoc protocol mm-verify-function-alist)))
1458 ((eq mm-verify-option 'never) nil)
1459 ((eq mm-verify-option 'always) t)
1460 ((eq mm-verify-option 'known)
1462 (or (not (setq functest
1463 (nth 3 (assoc protocol
1464 mm-verify-function-alist))))
1465 (funcall functest parts ctl))))
1468 (format "Verify signed (%s) part? "
1469 (or (nth 2 (assoc protocol mm-verify-function-alist))
1470 (format "protocol=%s" protocol))))))
1473 (funcall func parts ctl)
1474 (mm-set-handle-multipart-parameter
1475 mm-security-handle 'gnus-details
1476 (format "Unknown sign protocol (%s)" protocol))))))
1477 ((equal subtype "encrypted")
1478 (unless (setq protocol
1479 (mm-handle-multipart-ctl-parameter ctl 'protocol))
1480 ;; The message is broken.
1481 (let ((parts parts))
1483 (if (assoc (mm-handle-media-type (car parts))
1484 mm-decrypt-function-alist)
1485 (setq protocol (mm-handle-media-type (car parts))
1487 (setq parts (cdr parts))))))
1488 (setq func (nth 1 (assoc protocol mm-decrypt-function-alist)))
1490 ((eq mm-decrypt-option 'never) nil)
1491 ((eq mm-decrypt-option 'always) t)
1492 ((eq mm-decrypt-option 'known)
1494 (or (not (setq functest
1495 (nth 3 (assoc protocol
1496 mm-decrypt-function-alist))))
1497 (funcall functest parts ctl))))
1500 (format "Decrypt (%s) part? "
1501 (or (nth 2 (assoc protocol mm-decrypt-function-alist))
1502 (format "protocol=%s" protocol))))))
1505 (setq parts (funcall func parts ctl))
1506 (mm-set-handle-multipart-parameter
1507 mm-security-handle 'gnus-details
1508 (format "Unknown encrypt protocol (%s)" protocol))))))
1512 (defun mm-multiple-handles (handles)
1513 (and (listp handles)
1514 (> (length handles) 1)
1515 (or (listp (car handles))
1516 (stringp (car handles)))))
1518 (defun mm-complicated-handles (handles)
1519 (and (listp (car handles))
1520 (> (length handles) 1)))
1522 (defun mm-merge-handles (handles1 handles2)
1524 (if (listp (car handles1))
1527 (if (listp (car handles2))
1531 (defun mm-readable-p (handle)
1532 "Say whether the content of HANDLE is readable."
1533 (and (< (with-current-buffer (mm-handle-buffer handle)
1534 (buffer-size)) 10000)
1535 (mm-with-unibyte-buffer
1536 (mm-insert-part handle)
1537 (and (eq (mm-body-7-or-8) '7bit)
1538 (not (mm-long-lines-p 76))))))
1540 (provide 'mm-decode)
1542 ;;; mm-decode.el ends here