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.
32 (eval-when-compile (require 'cl
)
36 (autoload 'executable-find
"executable")
37 (autoload 'mm-inline-partial
"mm-partial")
38 (autoload 'mm-inline-external-body
"mm-extern")
39 (autoload 'mm-insert-inline
"mm-view"))
41 (defvar gnus-current-window-configuration
)
43 (add-hook 'gnus-exit-gnus-hook
'mm-destroy-postponed-undisplay-list
)
45 (defgroup mime-display
()
46 "Display of MIME in mail and news articles."
47 :link
'(custom-manual "(emacs-mime)Display Customization")
53 (defgroup mime-security
()
54 "MIME security in mail and news articles."
55 :link
'(custom-manual "(emacs-mime)Display Customization")
60 ;;; Convenience macros.
62 (defmacro mm-handle-buffer
(handle)
64 (defmacro mm-handle-type
(handle)
66 (defsubst mm-handle-media-type
(handle)
67 (if (stringp (car handle
))
69 (car (mm-handle-type handle
))))
70 (defsubst mm-handle-media-supertype
(handle)
71 (car (split-string (mm-handle-media-type handle
) "/")))
72 (defsubst mm-handle-media-subtype
(handle)
73 (cadr (split-string (mm-handle-media-type handle
) "/")))
74 (defmacro mm-handle-encoding
(handle)
76 (defmacro mm-handle-undisplayer
(handle)
78 (defmacro mm-handle-set-undisplayer
(handle function
)
79 `(setcar (nthcdr 3 ,handle
) ,function
))
80 (defmacro mm-handle-disposition
(handle)
82 (defmacro mm-handle-description
(handle)
84 (defmacro mm-handle-cache
(handle)
86 (defmacro mm-handle-set-cache
(handle contents
)
87 `(setcar (nthcdr 6 ,handle
) ,contents
))
88 (defmacro mm-handle-id
(handle)
90 (defmacro mm-handle-multipart-original-buffer
(handle)
91 `(get-text-property 0 'buffer
(car ,handle
)))
92 (defmacro mm-handle-multipart-from
(handle)
93 `(get-text-property 0 'from
(car ,handle
)))
94 (defmacro mm-handle-multipart-ctl-parameter
(handle parameter
)
95 `(get-text-property 0 ,parameter
(car ,handle
)))
97 (defmacro mm-make-handle
(&optional buffer type encoding undisplayer
98 disposition description cache
100 `(list ,buffer
,type
,encoding
,undisplayer
101 ,disposition
,description
,cache
,id
))
103 (defcustom mm-text-html-renderer
104 (cond ((locate-library "w3") 'w3
)
105 ((executable-find "w3m") (if (locate-library "w3m")
108 ((executable-find "links") 'links
)
109 ((executable-find "lynx") 'lynx
)
111 "Render of HTML contents.
112 It is one of defined renderer types, or a rendering function.
113 The defined renderer types are:
115 `w3m' : use emacs-w3m;
116 `w3m-standalone': use w3m;
119 `html2text' : use html2text;
120 nil : use external viewer."
122 :type
'(choice (const w3
)
124 (const w3m-standalone
)
130 :group
'mime-display
)
132 (defvar mm-inline-text-html-renderer nil
133 "Function used for rendering inline HTML contents.
134 It is suggested to customize `mm-text-html-renderer' instead.")
136 (defcustom mm-inline-text-html-with-images nil
137 "If non-nil, Gnus will allow retrieving images in HTML contents with
138 the <img> tags. It has no effect on Emacs/w3. See also the
139 documentation for the `mm-w3m-safe-url-regexp' variable."
142 :group
'mime-display
)
144 (defcustom mm-w3m-safe-url-regexp
"\\`cid:"
145 "Regexp matching URLs which are considered to be safe.
146 Some HTML mails might contain a nasty trick used by spammers, using
147 the <img> tag which is far more evil than the [Click Here!] button.
148 It is most likely intended to check whether the ominous spam mail has
149 reached your eyes or not, in which case the spammer knows for sure
150 that your email address is valid. It is done by embedding an
151 identifier string into a URL that you might automatically retrieve
152 when displaying the image. The default value is \"\\\\`cid:\" which only
153 matches parts embedded to the Multipart/Related type MIME contents and
154 Gnus will never connect to the spammer's site arbitrarily. You may
155 set this variable to nil if you consider all urls to be safe."
157 :type
'(choice (regexp :tag
"Regexp")
158 (const :tag
"All URLs are safe" nil
))
159 :group
'mime-display
)
161 (defcustom mm-inline-text-html-with-w3m-keymap t
162 "If non-nil, use emacs-w3m command keys in the article buffer."
165 :group
'mime-display
)
167 (defcustom mm-enable-external t
168 "Indicate whether external MIME handlers should be used.
170 If t, all defined external MIME handlers are used. If nil, files are saved by
171 `mailcap-save-binary-file'. If it is the symbol `ask', you are prompted
172 before the external MIME handler is invoked."
174 :type
'(choice (const :tag
"Always" t
)
175 (const :tag
"Never" nil
)
176 (const :tag
"Ask" ask
))
177 :group
'mime-display
)
179 (defcustom mm-inline-media-tests
183 (mm-valid-and-fit-image-p 'jpeg handle
)))
187 (mm-valid-and-fit-image-p 'png handle
)))
191 (mm-valid-and-fit-image-p 'gif handle
)))
195 (mm-valid-and-fit-image-p 'tiff handle
)) )
199 (mm-valid-and-fit-image-p 'xbm handle
)))
203 (mm-valid-and-fit-image-p 'xbm handle
)))
207 (mm-valid-and-fit-image-p 'xpm handle
)))
211 (mm-valid-and-fit-image-p 'xpm handle
)))
215 (mm-valid-and-fit-image-p 'bmp handle
)))
216 ("image/x-portable-bitmap"
219 (mm-valid-and-fit-image-p 'pbm handle
)))
220 ("text/plain" mm-inline-text identity
)
221 ("text/enriched" mm-inline-text identity
)
222 ("text/richtext" mm-inline-text identity
)
223 ("text/x-patch" mm-display-patch-inline
225 ;; If the diff-mode.el package is installed, the function is
226 ;; autoloaded. Checking (locate-library "diff-mode") would be trying
227 ;; to cater to broken installations. OTOH checking the function
228 ;; makes it possible to install another package which provides an
229 ;; alternative implementation of diff-mode. --Stef
230 (fboundp 'diff-mode
)))
231 ("application/emacs-lisp" mm-display-elisp-inline identity
)
232 ("application/x-emacs-lisp" mm-display-elisp-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"
300 "text/x-vcard" "image/.*" "message/delivery-status" "multipart/.*"
301 "message/rfc822" "text/x-patch" "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."
342 :type
'(repeat regexp
) ;; See `mm-preferred-alternative-precedence'.
343 :group
'mime-display
)
345 (defcustom mm-tmp-directory
346 (if (fboundp 'temp-directory
)
348 (if (boundp 'temporary-file-directory
)
349 temporary-file-directory
351 "Where mm will store its temporary files."
353 :group
'mime-display
)
355 (defcustom mm-inline-large-images nil
356 "If non-nil, then all images fit in the buffer."
358 :group
'mime-display
)
360 (defvar mm-file-name-rewrite-functions
361 '(mm-file-name-delete-control mm-file-name-delete-gotchas
)
362 "*List of functions used for rewriting file names of MIME parts.
363 Each function takes a file name as input and returns a file name.
365 Ready-made functions include
366 `mm-file-name-delete-control'
367 `mm-file-name-delete-gotchas'
368 `mm-file-name-delete-whitespace',
369 `mm-file-name-trim-whitespace',
370 `mm-file-name-collapse-whitespace',
371 `mm-file-name-replace-whitespace',
372 `capitalize', `downcase', `upcase', and
375 (defvar mm-path-name-rewrite-functions nil
376 "*List of functions for rewriting the full file names of MIME parts.
377 This is used when viewing parts externally, and is meant for
378 transforming the absolute name so that non-compliant programs can find
379 the file where it's saved.
381 Each function takes a file name as input and returns a file name.")
383 (defvar mm-file-name-replace-whitespace nil
384 "String used for replacing whitespace characters; default is `\"_\"'.")
386 (defcustom mm-default-directory nil
387 "The default directory where mm will save files.
388 If not set, `default-directory' will be used."
389 :type
'(choice directory
(const :tag
"Default" nil
))
390 :group
'mime-display
)
392 (defcustom mm-attachment-file-modes
384
393 "Set the mode bits of saved attachments to this integer."
396 :group
'mime-display
)
398 (defcustom mm-external-terminal-program
"xterm"
399 "The program to start an external terminal."
402 :group
'mime-display
)
404 ;;; Internal variables.
406 (defvar mm-last-shell-command
"")
407 (defvar mm-content-id-alist nil
)
408 (defvar mm-postponed-undisplay-list nil
)
410 ;; According to RFC2046, in particular, in a digest, the default
411 ;; Content-Type value for a body part is changed from "text/plain" to
413 (defvar mm-dissect-default-type
"text/plain")
415 (autoload 'mml2015-verify
"mml2015")
416 (autoload 'mml2015-verify-test
"mml2015")
417 (autoload 'mml-smime-verify
"mml-smime")
418 (autoload 'mml-smime-verify-test
"mml-smime")
420 (defvar mm-verify-function-alist
421 '(("application/pgp-signature" mml2015-verify
"PGP" mml2015-verify-test
)
422 ("application/x-gnus-pgp-signature" mm-uu-pgp-signed-extract-1
"PGP"
423 mm-uu-pgp-signed-test
)
424 ("application/pkcs7-signature" mml-smime-verify
"S/MIME"
425 mml-smime-verify-test
)
426 ("application/x-pkcs7-signature" mml-smime-verify
"S/MIME"
427 mml-smime-verify-test
)))
429 (defcustom mm-verify-option
'never
430 "Option of verifying signed parts.
431 `never', not verify; `always', always verify;
432 `known', only verify known protocols. Otherwise, ask user."
434 :type
'(choice (item always
)
436 (item :tag
"only known protocols" known
)
437 (item :tag
"ask" nil
))
438 :group
'mime-security
)
440 (autoload 'mml2015-decrypt
"mml2015")
441 (autoload 'mml2015-decrypt-test
"mml2015")
443 (defvar mm-decrypt-function-alist
444 '(("application/pgp-encrypted" mml2015-decrypt
"PGP" mml2015-decrypt-test
)
445 ("application/x-gnus-pgp-encrypted" mm-uu-pgp-encrypted-extract-1
"PGP"
446 mm-uu-pgp-encrypted-test
)))
448 (defcustom mm-decrypt-option nil
449 "Option of decrypting encrypted parts.
450 `never', not decrypt; `always', always decrypt;
451 `known', only decrypt known protocols. Otherwise, ask user."
453 :type
'(choice (item always
)
455 (item :tag
"only known protocols" known
)
456 (item :tag
"ask" nil
))
457 :group
'mime-security
)
459 (defvar mm-viewer-completion-map
460 (let ((map (make-sparse-keymap 'mm-viewer-completion-map
)))
461 (set-keymap-parent map minibuffer-local-completion-map
)
462 ;; Should we bind other key to minibuffer-complete-word?
463 (define-key map
" " 'self-insert-command
)
465 "Keymap for input viewer with completion.")
467 (defvar mm-viewer-completion-map
468 (let ((map (make-sparse-keymap 'mm-viewer-completion-map
)))
469 (set-keymap-parent map minibuffer-local-completion-map
)
470 ;; Should we bind other key to minibuffer-complete-word?
471 (define-key map
" " 'self-insert-command
)
473 "Keymap for input viewer with completion.")
477 (defun mm-alist-to-plist (alist)
478 "Convert association list ALIST into the equivalent property-list form.
479 The plist is returned. This converts from
481 \((a . 1) (b . 2) (c . 3))
487 The original alist is not modified. See also `destructive-alist-to-plist'."
490 (let ((el (car alist
)))
491 (setq plist
(cons (cdr el
) (cons (car el
) plist
))))
492 (setq alist
(cdr alist
)))
495 (defun mm-keep-viewer-alive-p (handle)
496 "Say whether external viewer for HANDLE should stay alive."
497 (let ((types mm-keep-viewer-alive-types
)
498 (type (mm-handle-media-type handle
))
501 (while (setq ty
(pop types
))
502 (when (string-match ty type
)
503 (throw 'found t
))))))
505 (defun mm-handle-set-external-undisplayer (handle function
)
506 "Set the undisplayer for HANDLE to FUNCTION.
507 Postpone undisplaying of viewers for types in
508 `mm-keep-viewer-alive-types'."
509 (if (mm-keep-viewer-alive-p handle
)
510 (let ((new-handle (copy-sequence handle
)))
511 (mm-handle-set-undisplayer new-handle function
)
512 (mm-handle-set-undisplayer handle nil
)
513 (push new-handle mm-postponed-undisplay-list
))
514 (mm-handle-set-undisplayer handle function
)))
516 (defun mm-destroy-postponed-undisplay-list ()
517 (when mm-postponed-undisplay-list
518 (message "Destroying external MIME viewers")
519 (mm-destroy-parts mm-postponed-undisplay-list
)))
521 (defun mm-dissect-buffer (&optional no-strict-mime loose-mime from
)
522 "Dissect the current buffer and return a list of MIME handles."
524 (let (ct ctl type subtype cte cd description id result
)
526 (mail-narrow-to-head)
527 (when (or no-strict-mime
529 (mail-fetch-field "mime-version"))
530 (setq ct
(mail-fetch-field "content-type")
531 ctl
(ignore-errors (mail-header-parse-content-type ct
))
532 cte
(mail-fetch-field "content-transfer-encoding")
533 cd
(mail-fetch-field "content-disposition")
534 description
(mail-fetch-field "content-description")
535 id
(mail-fetch-field "content-id"))
537 (setq from
(mail-fetch-field "from")))
538 ;; FIXME: In some circumstances, this code is running within
539 ;; an unibyte macro. mail-extract-address-components
540 ;; creates unibyte buffers. This `if', though not a perfect
541 ;; solution, avoids most of them.
543 (setq from
(cadr (mail-extract-address-components from
))))))
545 (setq cte
(mail-header-strip cte
)))
547 (not (string-match "/" (car ctl
))))
548 (mm-dissect-singlepart
549 (list mm-dissect-default-type
)
550 (and cte
(intern (downcase (mail-header-remove-whitespace
551 (mail-header-remove-comments
554 (and cd
(ignore-errors (mail-header-parse-content-disposition cd
)))
556 (setq type
(split-string (car ctl
) "/"))
557 (setq subtype
(cadr type
)
562 ((equal type
"multipart")
563 (let ((mm-dissect-default-type (if (equal subtype
"digest")
566 (start (cdr (assq 'start
(cdr ctl
)))))
567 (add-text-properties 0 (length (car ctl
))
568 (mm-alist-to-plist (cdr ctl
)) (car ctl
))
570 ;; what really needs to be done here is a way to link a
571 ;; MIME handle back to it's parent MIME handle (in a multilevel
572 ;; MIME article). That would probably require changing
573 ;; the mm-handle API so we simply store the multipart buffer
574 ;; name as a text property of the "multipart/whatever" string.
575 (add-text-properties 0 (length (car ctl
))
576 (list 'buffer
(mm-copy-to-buffer)
580 (cons (car ctl
) (mm-dissect-multipart ctl from
))))
582 (mm-possibly-verify-or-decrypt
583 (mm-dissect-singlepart
585 (and cte
(intern (downcase (mail-header-remove-whitespace
586 (mail-header-remove-comments
589 (and cd
(ignore-errors
590 (mail-header-parse-content-disposition cd
)))
594 (when (string-match " *<\\(.*\\)> *" id
)
595 (setq id
(match-string 1 id
)))
596 (push (cons id result
) mm-content-id-alist
))
599 (defun mm-dissect-singlepart (ctl cte
&optional force cdl description id
)
601 (if (equal "text/plain" (car ctl
))
605 (mm-copy-to-buffer) ctl cte nil cdl description nil id
)))
607 (defun mm-dissect-multipart (ctl from
)
608 (goto-char (point-min))
609 (let* ((boundary (concat "\n--" (mail-content-type-get ctl
'boundary
)))
610 (close-delimiter (concat (regexp-quote boundary
) "--[ \t]*$"))
613 (goto-char (point-max))
614 (if (re-search-backward close-delimiter nil t
)
617 (setq boundary
(concat (regexp-quote boundary
) "[ \t]*$"))
618 (while (and (< (point) end
) (re-search-forward boundary end t
))
619 (goto-char (match-beginning 0))
623 (narrow-to-region start
(point))
624 (setq parts
(nconc (list (mm-dissect-buffer t nil from
)) parts
)))))
626 (or (looking-at boundary
)
628 (setq start
(point)))
629 (when (and start
(< start end
))
632 (narrow-to-region start end
)
633 (setq parts
(nconc (list (mm-dissect-buffer t nil from
)) parts
)))))
634 (mm-possibly-verify-or-decrypt (nreverse parts
) ctl
)))
636 (defun mm-copy-to-buffer ()
637 "Copy the contents of the current buffer to a fresh buffer."
639 (let ((obuf (current-buffer))
641 (goto-char (point-min))
642 (search-forward-regexp "^\n" nil t
)
645 ;; Preserve the data's unibyteness (for url-insert-file-contents).
646 (let ((default-enable-multibyte-characters (mm-multibyte-p)))
647 (generate-new-buffer " *mm*")))
648 (insert-buffer-substring obuf beg
)
651 (defun mm-display-parts (handle &optional no-default
)
652 (if (stringp (car handle
))
653 (mapcar 'mm-display-parts
(cdr handle
))
654 (if (bufferp (car handle
))
656 (narrow-to-region (point) (point))
657 (mm-display-part handle
)
658 (goto-char (point-max)))
659 (mapcar 'mm-display-parts handle
))))
661 (defun mm-display-part (handle &optional no-default
)
662 "Display the MIME part represented by HANDLE.
663 Returns nil if the part is removed; inline if displayed inline;
664 external if displayed external."
666 (mailcap-parse-mailcaps)
667 (if (mm-handle-displayed-p handle
)
668 (mm-remove-part handle
)
669 (let* ((type (mm-handle-media-type handle
))
670 (method (mailcap-mime-info type
))
671 (filename (or (mail-content-type-get
672 (mm-handle-disposition handle
) 'filename
)
673 (mail-content-type-get
674 (mm-handle-type handle
) 'name
)
676 (external mm-enable-external
))
677 (if (and (mm-inlinable-p handle
)
678 (mm-inlined-p handle
))
681 (mm-display-inline handle
)
685 (if (and (not method
)
686 (equal "text" (car (split-string type
))))
689 (mm-insert-inline handle
(mm-get-part handle
))
691 (if (and method
;; If nil, we always use "save".
692 (stringp method
) ;; 'mailcap-save-binary-file
693 (or (eq mm-enable-external t
)
694 (and (eq mm-enable-external
'ask
)
697 "Display part (" type
698 ") using external program"
699 ;; Can non-string method ever happen?
702 " \"" (format method filename
) "\"")
709 handle
(or method
'mailcap-save-binary-file
))
711 handle
'mailcap-save-binary-file
)))))))))
713 (defun mm-display-external (handle method
)
714 "Display HANDLE using METHOD."
715 (let ((outbuf (current-buffer)))
716 (mm-with-unibyte-buffer
717 (if (functionp method
)
718 (let ((cur (current-buffer)))
719 (if (eq method
'mailcap-save-binary-file
)
721 (set-buffer (generate-new-buffer " *mm*"))
723 (mm-insert-part handle
)
724 (let ((win (get-buffer-window cur t
)))
726 (select-window win
)))
727 (switch-to-buffer (generate-new-buffer " *mm*")))
728 (buffer-disable-undo)
729 (mm-set-buffer-file-coding-system mm-binary-coding-system
)
730 (insert-buffer-substring cur
)
731 (goto-char (point-min))
733 (message "Viewing with %s" method
))
734 (let ((mm (current-buffer))
735 (non-viewer (assq 'non-viewer
737 (mm-handle-media-type handle
) t
))))
741 (mm-save-part handle
))
742 (when (and (not non-viewer
)
744 (mm-handle-set-undisplayer handle mm
)))))
745 ;; The function is a string to be executed.
746 (mm-insert-part handle
)
747 (let* ((dir (mm-make-temp-file
748 (expand-file-name "emm." mm-tmp-directory
) 'dir
))
750 (mail-content-type-get
751 (mm-handle-disposition handle
) 'filename
)
752 (mail-content-type-get
753 (mm-handle-type handle
) 'name
)))
754 (mime-info (mailcap-mime-info
755 (mm-handle-media-type handle
) t
))
756 (needsterm (or (assoc "needsterm" mime-info
)
757 (assoc "needsterminal" mime-info
)))
758 (copiousoutput (assoc "copiousoutput" mime-info
))
760 ;; We create a private sub-directory where we store our files.
761 (set-file-modes dir
448)
763 (setq file
(expand-file-name
764 (gnus-map-function mm-file-name-rewrite-functions
765 (file-name-nondirectory filename
))
767 (setq file
(mm-make-temp-file (expand-file-name "mm." dir
)))
769 ;; Use nametemplate (defined in RFC1524) if it is
770 ;; specified in mailcap.
771 (if (assoc "nametemplate" mime-info
)
772 (format (assoc "nametemplate" mime-info
) file
)
773 ;; Add a suffix according to `mailcap-mime-extensions'.
774 (concat file
(car (rassoc (mm-handle-media-type handle
)
775 mailcap-mime-extensions
))))))
776 (unless (string-equal file newname
)
777 (when (file-exists-p file
)
778 (rename-file file newname
))
779 (setq file newname
))))
780 (let ((coding-system-for-write mm-binary-coding-system
))
781 (write-region (point-min) (point-max) file nil
'nomesg
))
782 (message "Viewing with %s" method
)
785 (let ((command (mm-mailcap-command
786 method file
(mm-handle-type handle
))))
789 (start-process "*display*" nil
790 mm-external-terminal-program
792 shell-command-switch command
)
800 shell-command-switch command
)))
803 (set-process-sentinel
804 (get-buffer-process buffer
)
805 `(lambda (process state
)
806 (if (eq 'exit
(process-status process
))
807 (gnus-configure-windows
808 ',gnus-current-window-configuration
))))
809 (gnus-configure-windows 'display-term
))
810 (mm-handle-set-external-undisplayer handle
(cons file buffer
)))
811 (message "Displaying %s..." command
))
814 (with-current-buffer outbuf
820 (call-process shell-file-name nil
822 (generate-new-buffer " *mm*"))
826 method file
(mm-handle-type handle
)))
827 (if (buffer-live-p buffer
)
828 (with-current-buffer buffer
831 (ignore-errors (delete-file file
))
832 (ignore-errors (delete-directory
833 (file-name-directory file
)))
834 (ignore-errors (kill-buffer buffer
))))))
837 ;; Deleting the temp file should be postponed for some wrappers,
838 ;; shell scripts, and so on, which might exit right after having
839 ;; started a viewer command as a background job.
840 (let ((command (mm-mailcap-command
841 method file
(mm-handle-type handle
))))
844 (start-process "*display*"
846 (generate-new-buffer " *mm*"))
848 shell-command-switch command
)
849 (set-process-sentinel
850 (get-buffer-process buffer
)
851 (lexical-let ;; Don't use `let'.
852 ;; Function used to remove temp file and directory.
854 ;; Don't use `ignore-errors'.
860 ,(file-name-directory file
))
862 ;; Form uses to kill the process buffer and
863 ;; remove the undisplayer.
865 (kill-buffer ,buffer
)
867 (list 'mm-handle-set-undisplayer
870 ;; Message to be issued when the process exits.
871 (done (format "Displaying %s...done" command
))
872 ;; In particular, the timer object (which is
873 ;; a vector in Emacs but is a list in XEmacs)
874 ;; requires that it is lexically scoped.
875 (timer (run-at-time 2.0 nil
'ignore
)))
876 (lambda (process state
)
877 (when (eq 'exit
(process-status process
))
878 (if (memq timer timer-list
)
879 (timer-set-function timer fn
)
881 (ignore-errors (eval fm
))
882 (message "%s" done
))))))
883 (mm-handle-set-external-undisplayer
884 handle
(cons file buffer
)))
885 (message "Displaying %s..." command
))
888 (defun mm-mailcap-command (method file type-list
)
889 (let ((ctl (cdr type-list
))
893 (while (string-match "%{\\([^}]+\\)}\\|'%s'\\|\"%s\"\\|%s\\|%t\\|%%"
895 (push (substring method beg
(match-beginning 0)) out
)
896 (setq beg
(match-end 0)
897 total
(match-string 0 method
)
898 sub
(match-string 1 method
))
900 ((string= total
"%%")
902 ((or (string= total
"%s")
903 ;; We do our own quoting.
904 (string= total
"'%s'")
905 (string= total
"\"%s\""))
906 (setq uses-stdin nil
)
908 (gnus-map-function mm-path-name-rewrite-functions file
)) out
))
909 ((string= total
"%t")
910 (push (mm-quote-arg (car type-list
)) out
))
912 (push (mm-quote-arg (or (cdr (assq (intern sub
) ctl
)) "")) out
))))
913 (push (substring method beg
(length method
)) out
)
917 (gnus-map-function mm-path-name-rewrite-functions file
))
919 (mapconcat 'identity
(nreverse out
) "")))
921 (defun mm-remove-parts (handles)
922 "Remove the displayed MIME parts represented by HANDLES."
923 (if (and (listp handles
)
924 (bufferp (car handles
)))
925 (mm-remove-part handles
)
927 (while (setq handle
(pop handles
))
930 (when (buffer-live-p (get-text-property 0 'buffer handle
))
931 (kill-buffer (get-text-property 0 'buffer handle
))))
933 (stringp (car handle
)))
934 (mm-remove-parts (cdr handle
)))
936 (mm-remove-part handle
)))))))
938 (defun mm-destroy-parts (handles)
939 "Remove the displayed MIME parts represented by HANDLES."
940 (if (and (listp handles
)
941 (bufferp (car handles
)))
942 (mm-destroy-part handles
)
944 (while (setq handle
(pop handles
))
947 (when (buffer-live-p (get-text-property 0 'buffer handle
))
948 (kill-buffer (get-text-property 0 'buffer handle
))))
950 (stringp (car handle
)))
951 (mm-destroy-parts handle
))
953 (mm-destroy-part handle
)))))))
955 (defun mm-remove-part (handle)
956 "Remove the displayed MIME part represented by HANDLE."
958 (let ((object (mm-handle-undisplayer handle
)))
961 ;; Internally displayed part.
962 ((mm-annotationp object
)
963 (delete-annotation object
))
964 ((or (functionp object
)
966 (eq (car object
) 'lambda
)))
968 ;; Externally displayed part.
971 (while (get-buffer-process (cdr object
))
972 (interrupt-process (get-buffer-process (cdr object
)))
973 (message "Waiting for external displayer to die...")
977 (ignore-errors (and (cdr object
) (kill-buffer (cdr object
))))
978 (message "Waiting for external displayer to die...done")
979 (ignore-errors (delete-file (car object
)))
980 (ignore-errors (delete-directory (file-name-directory
983 (when (buffer-live-p object
)
984 (kill-buffer object
)))))
985 (mm-handle-set-undisplayer handle nil
))))
987 (defun mm-display-inline (handle)
988 (let* ((type (mm-handle-media-type handle
))
989 (function (cadr (mm-assoc-string-match mm-inline-media-tests type
))))
990 (funcall function handle
)
991 (goto-char (point-min))))
993 (defun mm-assoc-string-match (alist type
)
995 (when (string-match (car elem
) type
)
998 (defun mm-automatic-display-p (handle)
999 "Say whether the user wants HANDLE to be displayed automatically."
1000 (let ((methods mm-automatic-display
)
1001 (type (mm-handle-media-type handle
))
1003 (while (setq method
(pop methods
))
1004 (when (and (not (mm-inline-override-p handle
))
1005 (string-match method type
))
1010 (defun mm-inlinable-p (handle)
1011 "Say whether HANDLE can be displayed inline."
1012 (let ((alist mm-inline-media-tests
)
1013 (type (mm-handle-media-type handle
))
1016 (when (string-match (caar alist
) type
)
1017 (setq test
(caddar alist
)
1019 (setq test
(funcall test handle
)))
1023 (defun mm-inlined-p (handle)
1024 "Say whether the user wants HANDLE to be displayed inline."
1025 (let ((methods mm-inlined-types
)
1026 (type (mm-handle-media-type handle
))
1028 (while (setq method
(pop methods
))
1029 (when (and (not (mm-inline-override-p handle
))
1030 (string-match method type
))
1035 (defun mm-attachment-override-p (handle)
1036 "Say whether HANDLE should have attachment behavior overridden."
1037 (let ((types mm-attachment-override-types
)
1038 (type (mm-handle-media-type handle
))
1041 (while (setq ty
(pop types
))
1042 (when (and (string-match ty type
)
1043 (mm-inlinable-p handle
))
1044 (throw 'found t
))))))
1046 (defun mm-inline-override-p (handle)
1047 "Say whether HANDLE should have inline behavior overridden."
1048 (let ((types mm-inline-override-types
)
1049 (type (mm-handle-media-type handle
))
1052 (while (setq ty
(pop types
))
1053 (when (string-match ty type
)
1054 (throw 'found t
))))))
1056 (defun mm-automatic-external-display-p (type)
1057 "Return the user-defined method for TYPE."
1058 (let ((methods mm-automatic-external-display
)
1060 (while (setq method
(pop methods
))
1061 (when (string-match method type
)
1066 (defun mm-destroy-part (handle)
1067 "Destroy the data structures connected to HANDLE."
1068 (when (listp handle
)
1069 (mm-remove-part handle
)
1070 (when (buffer-live-p (mm-handle-buffer handle
))
1071 (kill-buffer (mm-handle-buffer handle
)))))
1073 (defun mm-handle-displayed-p (handle)
1074 "Say whether HANDLE is displayed or not."
1075 (mm-handle-undisplayer handle
))
1078 ;;; Functions for outputting parts
1081 (defun mm-get-part (handle)
1082 "Return the contents of HANDLE as a string."
1083 (mm-with-unibyte-buffer
1084 (insert (with-current-buffer (mm-handle-buffer handle
)
1085 (mm-with-unibyte-current-buffer
1087 (mm-decode-content-transfer-encoding
1088 (mm-handle-encoding handle
)
1089 (mm-handle-media-type handle
))
1092 (defun mm-insert-part (handle)
1093 "Insert the contents of HANDLE in the current buffer."
1096 (cond ((eq (mail-content-type-get (mm-handle-type handle
) 'charset
)
1098 (with-current-buffer (mm-handle-buffer handle
)
1101 (mm-string-as-multibyte (mm-get-part handle
)))
1103 (mm-get-part handle
))))))
1105 (defun mm-file-name-delete-whitespace (file-name)
1106 "Remove all whitespace characters from FILE-NAME."
1107 (while (string-match "\\s-+" file-name
)
1108 (setq file-name
(replace-match "" t t file-name
)))
1111 (defun mm-file-name-trim-whitespace (file-name)
1112 "Remove leading and trailing whitespace characters from FILE-NAME."
1113 (when (string-match "\\`\\s-+" file-name
)
1114 (setq file-name
(substring file-name
(match-end 0))))
1115 (when (string-match "\\s-+\\'" file-name
)
1116 (setq file-name
(substring file-name
0 (match-beginning 0))))
1119 (defun mm-file-name-collapse-whitespace (file-name)
1120 "Collapse multiple whitespace characters in FILE-NAME."
1121 (while (string-match "\\s-\\s-+" file-name
)
1122 (setq file-name
(replace-match " " t t file-name
)))
1125 (defun mm-file-name-replace-whitespace (file-name)
1126 "Replace whitespace characters in FILE-NAME with underscores.
1127 Set the option `mm-file-name-replace-whitespace' to any other
1128 string if you do not like underscores."
1129 (let ((s (or mm-file-name-replace-whitespace
"_")))
1130 (while (string-match "\\s-" file-name
)
1131 (setq file-name
(replace-match s t t file-name
))))
1134 (defun mm-file-name-delete-control (filename)
1135 "Delete control characters from FILENAME."
1136 (gnus-replace-in-string filename
"[\x00-\x1f\x7f]" ""))
1138 (defun mm-file-name-delete-gotchas (filename)
1139 "Delete shell gotchas from FILENAME."
1140 (setq filename
(gnus-replace-in-string filename
"[<>|]" ""))
1141 (gnus-replace-in-string filename
"^[.-]+" ""))
1143 (defun mm-save-part (handle)
1144 "Write HANDLE to a file."
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 "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 ((ctl (ignore-errors
1399 (mail-header-parse-content-type
1400 (mail-fetch-field "content-type")))))
1402 (not (equal (car ctl
) type
))
1403 (equal (car ctl
) type
)))
1404 (setq result
(buffer-string))))))
1406 (setq start
(point)))
1407 (when (and (not result
) start
)
1410 (narrow-to-region start end
)
1411 (when (let ((ctl (ignore-errors
1412 (mail-header-parse-content-type
1413 (mail-fetch-field "content-type")))))
1415 (not (equal (car ctl
) type
))
1416 (equal (car ctl
) type
)))
1417 (setq result
(buffer-string))))))
1420 (defvar mm-security-handle nil
)
1422 (defsubst mm-set-handle-multipart-parameter
(handle parameter value
)
1423 ;; HANDLE could be a CTL.
1425 (put-text-property 0 (length (car handle
)) parameter value
1428 (defun mm-possibly-verify-or-decrypt (parts ctl
)
1429 (let ((type (car ctl
))
1430 (subtype (cadr (split-string (car ctl
) "/")))
1431 (mm-security-handle ctl
) ;; (car CTL) is the type.
1432 protocol func functest
)
1434 ((or (equal type
"application/x-pkcs7-mime")
1435 (equal type
"application/pkcs7-mime"))
1438 ((eq mm-decrypt-option
'never
) nil
)
1439 ((eq mm-decrypt-option
'always
) t
)
1440 ((eq mm-decrypt-option
'known
) t
)
1442 (format "Decrypt (S/MIME) part? "))))
1443 (mm-view-pkcs7 parts
))
1444 (setq parts
(mm-dissect-buffer t
)))))
1445 ((equal subtype
"signed")
1446 (unless (and (setq protocol
1447 (mm-handle-multipart-ctl-parameter ctl
'protocol
))
1448 (not (equal protocol
"multipart/mixed")))
1449 ;; The message is broken or draft-ietf-openpgp-multsig-01.
1450 (let ((protocols mm-verify-function-alist
))
1452 (if (and (or (not (setq functest
(nth 3 (car protocols
))))
1453 (funcall functest parts ctl
))
1454 (mm-find-part-by-type parts
(caar protocols
) nil t
))
1455 (setq protocol
(caar protocols
)
1457 (setq protocols
(cdr protocols
))))))
1458 (setq func
(nth 1 (assoc protocol mm-verify-function-alist
)))
1460 ((eq mm-verify-option
'never
) nil
)
1461 ((eq mm-verify-option
'always
) t
)
1462 ((eq mm-verify-option
'known
)
1464 (or (not (setq functest
1465 (nth 3 (assoc protocol
1466 mm-verify-function-alist
))))
1467 (funcall functest parts ctl
))))
1470 (format "Verify signed (%s) part? "
1471 (or (nth 2 (assoc protocol mm-verify-function-alist
))
1472 (format "protocol=%s" protocol
))))))
1475 (funcall func parts ctl
)
1476 (mm-set-handle-multipart-parameter
1477 mm-security-handle
'gnus-details
1478 (format "Unknown sign protocol (%s)" protocol
))))))
1479 ((equal subtype
"encrypted")
1480 (unless (setq protocol
1481 (mm-handle-multipart-ctl-parameter ctl
'protocol
))
1482 ;; The message is broken.
1483 (let ((parts parts
))
1485 (if (assoc (mm-handle-media-type (car parts
))
1486 mm-decrypt-function-alist
)
1487 (setq protocol
(mm-handle-media-type (car parts
))
1489 (setq parts
(cdr parts
))))))
1490 (setq func
(nth 1 (assoc protocol mm-decrypt-function-alist
)))
1492 ((eq mm-decrypt-option
'never
) nil
)
1493 ((eq mm-decrypt-option
'always
) t
)
1494 ((eq mm-decrypt-option
'known
)
1496 (or (not (setq functest
1497 (nth 3 (assoc protocol
1498 mm-decrypt-function-alist
))))
1499 (funcall functest parts ctl
))))
1502 (format "Decrypt (%s) part? "
1503 (or (nth 2 (assoc protocol mm-decrypt-function-alist
))
1504 (format "protocol=%s" protocol
))))))
1507 (setq parts
(funcall func parts ctl
))
1508 (mm-set-handle-multipart-parameter
1509 mm-security-handle
'gnus-details
1510 (format "Unknown encrypt protocol (%s)" protocol
))))))
1514 (defun mm-multiple-handles (handles)
1515 (and (listp handles
)
1516 (> (length handles
) 1)
1517 (or (listp (car handles
))
1518 (stringp (car handles
)))))
1520 (defun mm-complicated-handles (handles)
1521 (and (listp (car handles
))
1522 (> (length handles
) 1)))
1524 (defun mm-merge-handles (handles1 handles2
)
1526 (if (listp (car handles1
))
1529 (if (listp (car handles2
))
1533 (defun mm-readable-p (handle)
1534 "Say whether the content of HANDLE is readable."
1535 (and (< (with-current-buffer (mm-handle-buffer handle
)
1536 (buffer-size)) 10000)
1537 (mm-with-unibyte-buffer
1538 (mm-insert-part handle
)
1539 (and (eq (mm-body-7-or-8) '7bit
)
1540 (not (mm-long-lines-p 76))))))
1542 (provide 'mm-decode
)
1544 ;; arch-tag: 4f35d360-56b8-4030-9388-3ed82d359b9b
1545 ;;; mm-decode.el ends here