]> code.delx.au - gnu-emacs/blob - lisp/gnus/mm-decode.el
Merge from mainline.
[gnu-emacs] / lisp / gnus / mm-decode.el
1 ;;; mm-decode.el --- Functions for decoding MIME things
2
3 ;; Copyright (C) 1998-2013 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21
22 ;;; Commentary:
23
24 ;;; Code:
25
26 ;; For Emacs <22.2 and XEmacs.
27 (eval-and-compile
28 (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
29
30 (require 'mail-parse)
31 (require 'mm-bodies)
32 (eval-when-compile (require 'cl))
33
34 (autoload 'gnus-map-function "gnus-util")
35 (autoload 'gnus-replace-in-string "gnus-util")
36 (autoload 'gnus-read-shell-command "gnus-util")
37
38 (autoload 'mm-inline-partial "mm-partial")
39 (autoload 'mm-inline-external-body "mm-extern")
40 (autoload 'mm-extern-cache-contents "mm-extern")
41 (autoload 'mm-insert-inline "mm-view")
42
43 (autoload 'mm-archive-decoders "mm-archive")
44 (autoload 'mm-archive-dissect-and-inline "mm-archive")
45 (autoload 'mm-dissect-archive "mm-archive")
46
47 (defvar gnus-current-window-configuration)
48
49 (add-hook 'gnus-exit-gnus-hook 'mm-destroy-postponed-undisplay-list)
50
51 (defgroup mime-display ()
52 "Display of MIME in mail and news articles."
53 :link '(custom-manual "(emacs-mime)Display Customization")
54 :version "21.1"
55 :group 'mail
56 :group 'news
57 :group 'multimedia)
58
59 (defgroup mime-security ()
60 "MIME security in mail and news articles."
61 :link '(custom-manual "(emacs-mime)Display Customization")
62 :group 'mail
63 :group 'news
64 :group 'multimedia)
65
66 (defface mm-command-output
67 '((((class color)
68 (background dark))
69 (:foreground "ForestGreen"))
70 (((class color)
71 (background light))
72 (:foreground "red3"))
73 (t
74 (:italic t)))
75 "Face used for displaying output from commands."
76 :group 'mime-display)
77
78 ;;; Convenience macros.
79
80 (defmacro mm-handle-buffer (handle)
81 `(nth 0 ,handle))
82 (defmacro mm-handle-type (handle)
83 `(nth 1 ,handle))
84 (defsubst mm-handle-media-type (handle)
85 (if (stringp (car handle))
86 (car handle)
87 (car (mm-handle-type handle))))
88 (defsubst mm-handle-media-supertype (handle)
89 (car (split-string (mm-handle-media-type handle) "/")))
90 (defsubst mm-handle-media-subtype (handle)
91 (cadr (split-string (mm-handle-media-type handle) "/")))
92 (defmacro mm-handle-encoding (handle)
93 `(nth 2 ,handle))
94 (defmacro mm-handle-undisplayer (handle)
95 `(nth 3 ,handle))
96 (defmacro mm-handle-set-undisplayer (handle function)
97 `(setcar (nthcdr 3 ,handle) ,function))
98 (defmacro mm-handle-disposition (handle)
99 `(nth 4 ,handle))
100 (defmacro mm-handle-description (handle)
101 `(nth 5 ,handle))
102 (defmacro mm-handle-cache (handle)
103 `(nth 6 ,handle))
104 (defmacro mm-handle-set-cache (handle contents)
105 `(setcar (nthcdr 6 ,handle) ,contents))
106 (defmacro mm-handle-id (handle)
107 `(nth 7 ,handle))
108 (defmacro mm-handle-multipart-original-buffer (handle)
109 `(get-text-property 0 'buffer (car ,handle)))
110 (defmacro mm-handle-multipart-from (handle)
111 `(get-text-property 0 'from (car ,handle)))
112 (defmacro mm-handle-multipart-ctl-parameter (handle parameter)
113 `(get-text-property 0 ,parameter (car ,handle)))
114
115 (defmacro mm-make-handle (&optional buffer type encoding undisplayer
116 disposition description cache
117 id)
118 `(list ,buffer ,type ,encoding ,undisplayer
119 ,disposition ,description ,cache ,id))
120
121 (defcustom mm-text-html-renderer
122 (cond ((fboundp 'libxml-parse-html-region) 'shr)
123 ((executable-find "w3m") 'gnus-w3m)
124 ((executable-find "links") 'links)
125 ((executable-find "lynx") 'lynx)
126 ((locate-library "w3") 'w3)
127 ((locate-library "html2text") 'html2text)
128 (t nil))
129 "Render of HTML contents.
130 It is one of defined renderer types, or a rendering function.
131 The defined renderer types are:
132 `shr': use the built-in Gnus HTML renderer;
133 `gnus-w3m': use Gnus renderer based on w3m;
134 `w3m': use emacs-w3m;
135 `w3m-standalone': use plain w3m;
136 `links': use links;
137 `lynx': use lynx;
138 `w3': use Emacs/W3;
139 `html2text': use html2text;
140 nil : use external viewer (default web browser)."
141 :version "24.1"
142 :type '(choice (const shr)
143 (const gnus-w3m)
144 (const w3)
145 (const w3m :tag "emacs-w3m")
146 (const w3m-standalone :tag "standalone w3m" )
147 (const links)
148 (const lynx)
149 (const html2text)
150 (const nil :tag "External viewer")
151 (function))
152 :group 'mime-display)
153
154 (defcustom mm-inline-text-html-with-images nil
155 "If non-nil, Gnus will allow retrieving images in HTML contents with
156 the <img> tags. It has no effect on Emacs/w3. See also the
157 documentation for the `mm-w3m-safe-url-regexp' variable."
158 :version "22.1"
159 :type 'boolean
160 :group 'mime-display)
161
162 (defcustom mm-w3m-safe-url-regexp "\\`cid:"
163 "Regexp matching URLs which are considered to be safe.
164 Some HTML mails might contain a nasty trick used by spammers, using
165 the <img> tag which is far more evil than the [Click Here!] button.
166 It is most likely intended to check whether the ominous spam mail has
167 reached your eyes or not, in which case the spammer knows for sure
168 that your email address is valid. It is done by embedding an
169 identifier string into a URL that you might automatically retrieve
170 when displaying the image. The default value is \"\\\\`cid:\" which only
171 matches parts embedded to the Multipart/Related type MIME contents and
172 Gnus will never connect to the spammer's site arbitrarily. You may
173 set this variable to nil if you consider all urls to be safe."
174 :version "22.1"
175 :type '(choice (regexp :tag "Regexp")
176 (const :tag "All URLs are safe" nil))
177 :group 'mime-display)
178
179 (defcustom mm-inline-text-html-with-w3m-keymap t
180 "If non-nil, use emacs-w3m command keys in the article buffer."
181 :version "22.1"
182 :type 'boolean
183 :group 'mime-display)
184
185 (defcustom mm-enable-external t
186 "Indicate whether external MIME handlers should be used.
187
188 If t, all defined external MIME handlers are used. If nil, files are saved by
189 `mailcap-save-binary-file'. If it is the symbol `ask', you are prompted
190 before the external MIME handler is invoked."
191 :version "22.1"
192 :type '(choice (const :tag "Always" t)
193 (const :tag "Never" nil)
194 (const :tag "Ask" ask))
195 :group 'mime-display)
196
197 (defcustom mm-inline-media-tests
198 '(("image/p?jpeg"
199 mm-inline-image
200 (lambda (handle)
201 (mm-valid-and-fit-image-p 'jpeg handle)))
202 ("image/png"
203 mm-inline-image
204 (lambda (handle)
205 (mm-valid-and-fit-image-p 'png handle)))
206 ("image/gif"
207 mm-inline-image
208 (lambda (handle)
209 (mm-valid-and-fit-image-p 'gif handle)))
210 ("image/tiff"
211 mm-inline-image
212 (lambda (handle)
213 (mm-valid-and-fit-image-p 'tiff handle)))
214 ("image/xbm"
215 mm-inline-image
216 (lambda (handle)
217 (mm-valid-and-fit-image-p 'xbm handle)))
218 ("image/x-xbitmap"
219 mm-inline-image
220 (lambda (handle)
221 (mm-valid-and-fit-image-p 'xbm handle)))
222 ("image/xpm"
223 mm-inline-image
224 (lambda (handle)
225 (mm-valid-and-fit-image-p 'xpm handle)))
226 ("image/x-xpixmap"
227 mm-inline-image
228 (lambda (handle)
229 (mm-valid-and-fit-image-p 'xpm handle)))
230 ("image/bmp"
231 mm-inline-image
232 (lambda (handle)
233 (mm-valid-and-fit-image-p 'bmp handle)))
234 ("image/x-portable-bitmap"
235 mm-inline-image
236 (lambda (handle)
237 (mm-valid-and-fit-image-p 'pbm handle)))
238 ("text/plain" mm-inline-text identity)
239 ("text/enriched" mm-inline-text identity)
240 ("text/richtext" mm-inline-text identity)
241 ("text/x-patch" mm-display-patch-inline identity)
242 ;; In case mime.types uses x-diff (as does Debian's mime-support-3.40).
243 ("text/x-diff" mm-display-patch-inline identity)
244 ("application/emacs-lisp" mm-display-elisp-inline identity)
245 ("application/x-emacs-lisp" mm-display-elisp-inline identity)
246 ("application/x-shellscript" mm-display-shell-script-inline identity)
247 ("application/x-sh" mm-display-shell-script-inline identity)
248 ("text/x-sh" mm-display-shell-script-inline identity)
249 ("application/javascript" mm-display-javascript-inline identity)
250 ("text/dns" mm-display-dns-inline identity)
251 ("text/x-org" mm-display-org-inline identity)
252 ("text/html"
253 mm-inline-text-html
254 (lambda (handle)
255 mm-text-html-renderer))
256 ("text/x-vcard"
257 mm-inline-text-vcard
258 (lambda (handle)
259 (or (featurep 'vcard)
260 (locate-library "vcard"))))
261 ("message/delivery-status" mm-inline-text identity)
262 ("message/rfc822" mm-inline-message identity)
263 ("message/partial" mm-inline-partial identity)
264 ("message/external-body" mm-inline-external-body identity)
265 ("text/.*" mm-inline-text identity)
266 ("application/x-.?tar\\(-.*\\)?" mm-archive-dissect-and-inline identity)
267 ("application/zip" mm-archive-dissect-and-inline identity)
268 ("audio/wav" mm-inline-audio
269 (lambda (handle)
270 (and (or (featurep 'nas-sound) (featurep 'native-sound))
271 (device-sound-enabled-p))))
272 ("audio/au"
273 mm-inline-audio
274 (lambda (handle)
275 (and (or (featurep 'nas-sound) (featurep 'native-sound))
276 (device-sound-enabled-p))))
277 ("application/pgp-signature" ignore identity)
278 ("application/x-pkcs7-signature" ignore identity)
279 ("application/pkcs7-signature" ignore identity)
280 ("application/x-pkcs7-mime" ignore identity)
281 ("application/pkcs7-mime" ignore identity)
282 ("multipart/alternative" ignore identity)
283 ("multipart/mixed" ignore identity)
284 ("multipart/related" ignore identity)
285 ("image/.*"
286 mm-inline-image
287 (lambda (handle)
288 (and (mm-valid-image-format-p 'imagemagick)
289 (mm-with-unibyte-buffer
290 (mm-insert-part handle)
291 (let ((image
292 (ignore-errors
293 (if (fboundp 'create-image)
294 (create-image (buffer-string) 'imagemagick 'data-p)
295 (mm-create-image-xemacs
296 (mm-handle-media-subtype handle))))))
297 (when image
298 (setcar (cdr handle) (list "image/imagemagick"))
299 (mm-image-fit-p handle)))))))
300 ;; Disable audio and image
301 ("audio/.*" ignore ignore)
302 ("image/.*" ignore ignore)
303 ;; Default to displaying as text
304 (".*" mm-inline-text mm-readable-p))
305 "Alist of media types/tests saying whether types can be displayed inline."
306 :type '(repeat (list (regexp :tag "MIME type")
307 (function :tag "Display function")
308 (function :tag "Display test")))
309 :group 'mime-display)
310
311 (defcustom mm-inlined-types
312 '("image/.*" "text/.*" "message/delivery-status" "message/rfc822"
313 "message/partial" "message/external-body" "application/emacs-lisp"
314 "application/x-emacs-lisp"
315 "application/pgp-signature" "application/x-pkcs7-signature"
316 "application/pkcs7-signature" "application/x-pkcs7-mime"
317 "application/pkcs7-mime"
318 "application/x-gtar-compressed"
319 "application/x-tar"
320 "application/zip"
321 ;; Mutt still uses this even though it has already been withdrawn.
322 "application/pgp")
323 "List of media types that are to be displayed inline.
324 See also `mm-inline-media-tests', which says how to display a media
325 type inline."
326 :type '(repeat regexp)
327 :group 'mime-display)
328
329 (defcustom mm-keep-viewer-alive-types
330 '("application/postscript" "application/msword" "application/vnd.ms-excel"
331 "application/pdf" "application/x-dvi")
332 "List of media types for which the external viewer will not be killed
333 when selecting a different article."
334 :version "22.1"
335 :type '(repeat regexp)
336 :group 'mime-display)
337
338 (defcustom mm-automatic-display
339 '("text/plain" "text/enriched" "text/richtext" "text/html" "text/x-verbatim"
340 "text/x-vcard" "image/.*" "message/delivery-status" "multipart/.*"
341 "message/rfc822" "text/x-patch" "text/dns" "application/pgp-signature"
342 "application/emacs-lisp" "application/x-emacs-lisp"
343 "application/x-pkcs7-signature"
344 "application/pkcs7-signature" "application/x-pkcs7-mime"
345 "application/pkcs7-mime"
346 ;; Mutt still uses this even though it has already been withdrawn.
347 "application/pgp\\'"
348 "text/x-org")
349 "A list of MIME types to be displayed automatically."
350 :type '(repeat regexp)
351 :group 'mime-display)
352
353 (defcustom mm-attachment-override-types '("text/x-vcard"
354 "application/pkcs7-mime"
355 "application/x-pkcs7-mime"
356 "application/pkcs7-signature"
357 "application/x-pkcs7-signature")
358 "Types to have \"attachment\" ignored if they can be displayed inline."
359 :type '(repeat regexp)
360 :group 'mime-display)
361
362 (defcustom mm-inline-override-types nil
363 "Types to be treated as attachments even if they can be displayed inline."
364 :type '(repeat regexp)
365 :group 'mime-display)
366
367 (defcustom mm-automatic-external-display nil
368 "List of MIME type regexps that will be displayed externally automatically."
369 :type '(repeat regexp)
370 :group 'mime-display)
371
372 (defcustom mm-discouraged-alternatives nil
373 "List of MIME types that are discouraged when viewing multipart/alternative.
374 Viewing agents are supposed to view the last possible part of a message,
375 as that is supposed to be the richest. However, users may prefer other
376 types instead, and this list says what types are most unwanted. If,
377 for instance, text/html parts are very unwanted, and text/richtext are
378 somewhat unwanted, then the value of this variable should be set
379 to:
380
381 (\"text/html\" \"text/richtext\")
382
383 Adding \"image/.*\" might also be useful. Spammers use it as the
384 preferred part of multipart/alternative messages. See also
385 `gnus-buttonized-mime-types', to which adding \"multipart/alternative\"
386 enables you to choose manually one of two types those mails include."
387 :type '(repeat regexp) ;; See `mm-preferred-alternative-precedence'.
388 :group 'mime-display)
389
390 (defcustom mm-tmp-directory
391 (if (fboundp 'temp-directory)
392 (temp-directory)
393 (if (boundp 'temporary-file-directory)
394 temporary-file-directory
395 "/tmp/"))
396 "Where mm will store its temporary files."
397 :type 'directory
398 :group 'mime-display)
399
400 (defcustom mm-inline-large-images nil
401 "If t, then all images fit in the buffer.
402 If 'resize, try to resize the images so they fit."
403 :type '(radio
404 (const :tag "Inline large images as they are." t)
405 (const :tag "Resize large images." resize)
406 (const :tag "Do not inline large images." nil))
407 :group 'mime-display)
408
409 (defcustom mm-file-name-rewrite-functions
410 '(mm-file-name-delete-control mm-file-name-delete-gotchas)
411 "List of functions used for rewriting file names of MIME parts.
412 Each function takes a file name as input and returns a file name.
413
414 Ready-made functions include `mm-file-name-delete-control',
415 `mm-file-name-delete-gotchas' (you should not remove these two
416 functions), `mm-file-name-delete-whitespace',
417 `mm-file-name-trim-whitespace', `mm-file-name-collapse-whitespace',
418 `mm-file-name-replace-whitespace', `capitalize', `downcase',
419 `upcase', and `upcase-initials'."
420 :type '(list (set :inline t
421 (const mm-file-name-delete-control)
422 (const mm-file-name-delete-gotchas)
423 (const mm-file-name-delete-whitespace)
424 (const mm-file-name-trim-whitespace)
425 (const mm-file-name-collapse-whitespace)
426 (const mm-file-name-replace-whitespace)
427 (const capitalize)
428 (const downcase)
429 (const upcase)
430 (const upcase-initials)
431 (repeat :inline t
432 :tag "Function"
433 function)))
434 :version "23.1" ;; No Gnus
435 :group 'mime-display)
436
437
438 (defvar mm-path-name-rewrite-functions nil
439 "*List of functions for rewriting the full file names of MIME parts.
440 This is used when viewing parts externally, and is meant for
441 transforming the absolute name so that non-compliant programs can find
442 the file where it's saved.
443
444 Each function takes a file name as input and returns a file name.")
445
446 (defvar mm-file-name-replace-whitespace nil
447 "String used for replacing whitespace characters; default is `\"_\"'.")
448
449 (defcustom mm-default-directory nil
450 "The default directory where mm will save files.
451 If not set, `default-directory' will be used."
452 :type '(choice directory (const :tag "Default" nil))
453 :group 'mime-display)
454
455 (defcustom mm-attachment-file-modes 384
456 "Set the mode bits of saved attachments to this integer."
457 :version "22.1"
458 :type 'integer
459 :group 'mime-display)
460
461 (defcustom mm-external-terminal-program "xterm"
462 "The program to start an external terminal."
463 :version "22.1"
464 :type 'string
465 :group 'mime-display)
466
467 ;;; Internal variables.
468
469 (defvar mm-last-shell-command "")
470 (defvar mm-content-id-alist nil)
471 (defvar mm-postponed-undisplay-list nil)
472 (defvar mm-inhibit-auto-detect-attachment nil)
473
474 ;; According to RFC2046, in particular, in a digest, the default
475 ;; Content-Type value for a body part is changed from "text/plain" to
476 ;; "message/rfc822".
477 (defvar mm-dissect-default-type "text/plain")
478
479 (autoload 'mml2015-verify "mml2015")
480 (autoload 'mml2015-verify-test "mml2015")
481 (autoload 'mml-smime-verify "mml-smime")
482 (autoload 'mml-smime-verify-test "mml-smime")
483
484 (defvar mm-verify-function-alist
485 '(("application/pgp-signature" mml2015-verify "PGP" mml2015-verify-test)
486 ("application/x-gnus-pgp-signature" mm-uu-pgp-signed-extract-1 "PGP"
487 mm-uu-pgp-signed-test)
488 ("application/pkcs7-signature" mml-smime-verify "S/MIME"
489 mml-smime-verify-test)
490 ("application/x-pkcs7-signature" mml-smime-verify "S/MIME"
491 mml-smime-verify-test)))
492
493 (defcustom mm-verify-option 'never
494 "Option of verifying signed parts.
495 `never', not verify; `always', always verify;
496 `known', only verify known protocols. Otherwise, ask user.
497
498 When set to `always' or `known', you should add
499 \"multipart/signed\" to `gnus-buttonized-mime-types' to see
500 result of the verification."
501 :version "22.1"
502 :type '(choice (item always)
503 (item never)
504 (item :tag "only known protocols" known)
505 (item :tag "ask" nil))
506 :group 'mime-security)
507
508 (autoload 'mml2015-decrypt "mml2015")
509 (autoload 'mml2015-decrypt-test "mml2015")
510
511 (defvar mm-decrypt-function-alist
512 '(("application/pgp-encrypted" mml2015-decrypt "PGP" mml2015-decrypt-test)
513 ("application/x-gnus-pgp-encrypted" mm-uu-pgp-encrypted-extract-1 "PGP"
514 mm-uu-pgp-encrypted-test)))
515
516 (defcustom mm-decrypt-option nil
517 "Option of decrypting encrypted parts.
518 `never', not decrypt; `always', always decrypt;
519 `known', only decrypt known protocols. Otherwise, ask user."
520 :version "22.1"
521 :type '(choice (item always)
522 (item never)
523 (item :tag "only known protocols" known)
524 (item :tag "ask" nil))
525 :group 'mime-security)
526
527 (defvar mm-viewer-completion-map
528 (let ((map (make-sparse-keymap 'mm-viewer-completion-map)))
529 (set-keymap-parent map minibuffer-local-completion-map)
530 ;; Should we bind other key to minibuffer-complete-word?
531 (define-key map " " 'self-insert-command)
532 map)
533 "Keymap for input viewer with completion.")
534
535 (defvar mm-viewer-completion-map
536 (let ((map (make-sparse-keymap 'mm-viewer-completion-map)))
537 (set-keymap-parent map minibuffer-local-completion-map)
538 ;; Should we bind other key to minibuffer-complete-word?
539 (define-key map " " 'self-insert-command)
540 map)
541 "Keymap for input viewer with completion.")
542
543 ;;; The functions.
544
545 (defun mm-alist-to-plist (alist)
546 "Convert association list ALIST into the equivalent property-list form.
547 The plist is returned. This converts from
548
549 \((a . 1) (b . 2) (c . 3))
550
551 into
552
553 \(a 1 b 2 c 3)
554
555 The original alist is not modified. See also `destructive-alist-to-plist'."
556 (let (plist)
557 (while alist
558 (let ((el (car alist)))
559 (setq plist (cons (cdr el) (cons (car el) plist))))
560 (setq alist (cdr alist)))
561 (nreverse plist)))
562
563 (defun mm-keep-viewer-alive-p (handle)
564 "Say whether external viewer for HANDLE should stay alive."
565 (let ((types mm-keep-viewer-alive-types)
566 (type (mm-handle-media-type handle))
567 ty)
568 (catch 'found
569 (while (setq ty (pop types))
570 (when (string-match ty type)
571 (throw 'found t))))))
572
573 (defun mm-handle-set-external-undisplayer (handle function)
574 "Set the undisplayer for HANDLE to FUNCTION.
575 Postpone undisplaying of viewers for types in
576 `mm-keep-viewer-alive-types'."
577 (if (mm-keep-viewer-alive-p handle)
578 (let ((new-handle (copy-sequence handle)))
579 (mm-handle-set-undisplayer new-handle function)
580 (mm-handle-set-undisplayer handle nil)
581 (push new-handle mm-postponed-undisplay-list))
582 (mm-handle-set-undisplayer handle function)))
583
584 (defun mm-destroy-postponed-undisplay-list ()
585 (when mm-postponed-undisplay-list
586 (message "Destroying external MIME viewers")
587 (mm-destroy-parts mm-postponed-undisplay-list)))
588
589 (autoload 'message-fetch-field "message")
590
591 (defun mm-dissect-buffer (&optional no-strict-mime loose-mime from)
592 "Dissect the current buffer and return a list of MIME handles.
593 If NO-STRICT-MIME, don't require the message to have a
594 MIME-Version header before proceeding."
595 (save-excursion
596 (let (ct ctl type subtype cte cd description id result)
597 (save-restriction
598 (mail-narrow-to-head)
599 (when (or no-strict-mime
600 loose-mime
601 (mail-fetch-field "mime-version"))
602 (setq ct (mail-fetch-field "content-type")
603 ctl (and ct (mail-header-parse-content-type ct))
604 cte (mail-fetch-field "content-transfer-encoding")
605 cd (or (mail-fetch-field "content-disposition")
606 (when (and ctl
607 (eq 'mm-inline-text
608 (cadr (mm-assoc-string-match
609 mm-inline-media-tests
610 (car ctl)))))
611 "inline"))
612 ;; Newlines in description should be stripped so as
613 ;; not to break the MIME tag into two or more lines.
614 description (message-fetch-field "content-description")
615 id (mail-fetch-field "content-id"))
616 (unless from
617 (setq from (mail-fetch-field "from")))
618 ;; FIXME: In some circumstances, this code is running within
619 ;; an unibyte macro. mail-extract-address-components
620 ;; creates unibyte buffers. This `if', though not a perfect
621 ;; solution, avoids most of them.
622 (if from
623 (setq from (cadr (mail-extract-address-components from))))
624 (if description
625 (setq description (mail-decode-encoded-word-string
626 description)))))
627 (if (or (not ctl)
628 (not (string-match "/" (car ctl))))
629 (mm-dissect-singlepart
630 (list mm-dissect-default-type)
631 (and cte (intern (downcase (mail-header-strip cte))))
632 no-strict-mime
633 (and cd (mail-header-parse-content-disposition cd))
634 description)
635 (setq type (split-string (car ctl) "/"))
636 (setq subtype (cadr type)
637 type (car type))
638 (setq
639 result
640 (cond
641 ((equal type "multipart")
642 (let ((mm-dissect-default-type (if (equal subtype "digest")
643 "message/rfc822"
644 "text/plain"))
645 (start (cdr (assq 'start (cdr ctl)))))
646 (add-text-properties 0 (length (car ctl))
647 (mm-alist-to-plist (cdr ctl)) (car ctl))
648
649 ;; what really needs to be done here is a way to link a
650 ;; MIME handle back to it's parent MIME handle (in a multilevel
651 ;; MIME article). That would probably require changing
652 ;; the mm-handle API so we simply store the multipart buffer
653 ;; name as a text property of the "multipart/whatever" string.
654 (add-text-properties 0 (length (car ctl))
655 (list 'buffer (mm-copy-to-buffer)
656 'from from
657 'start start)
658 (car ctl))
659 (cons (car ctl) (mm-dissect-multipart ctl from))))
660 (t
661 (mm-possibly-verify-or-decrypt
662 (mm-dissect-singlepart
663 ctl
664 (and cte (intern (downcase (mail-header-strip cte))))
665 no-strict-mime
666 (and cd (mail-header-parse-content-disposition cd))
667 description id)
668 ctl from))))
669 (when id
670 (when (string-match " *<\\(.*\\)> *" id)
671 (setq id (match-string 1 id)))
672 (push (cons id result) mm-content-id-alist))
673 result))))
674
675 (defun mm-dissect-singlepart (ctl cte &optional force cdl description id)
676 (when (or force
677 (if (equal "text/plain" (car ctl))
678 (assoc 'format ctl)
679 t))
680 ;; Guess what the type of application/octet-stream parts should
681 ;; really be.
682 (let ((filename (cdr (assq 'filename (cdr cdl)))))
683 (when (and (not mm-inhibit-auto-detect-attachment)
684 (equal (car ctl) "application/octet-stream")
685 filename
686 (string-match "\\.\\([^.]+\\)$" filename))
687 (let ((new-type (mailcap-extension-to-mime (match-string 1 filename))))
688 (when new-type
689 (setcar ctl new-type)))))
690 (let ((handle
691 (mm-make-handle
692 (mm-copy-to-buffer) ctl cte nil cdl description nil id))
693 (decoder (assoc (car ctl) (mm-archive-decoders))))
694 (if (and decoder
695 ;; Do automatic decoding
696 (cadr decoder)
697 (executable-find (caddr decoder)))
698 (mm-dissect-archive handle)
699 handle))))
700
701 (defun mm-dissect-multipart (ctl from)
702 (goto-char (point-min))
703 (let* ((boundary (concat "\n--" (mail-content-type-get ctl 'boundary)))
704 (close-delimiter (concat (regexp-quote boundary) "--[ \t]*$"))
705 start parts
706 (end (save-excursion
707 (goto-char (point-max))
708 (if (re-search-backward close-delimiter nil t)
709 (match-beginning 0)
710 (point-max))))
711 (mm-inhibit-auto-detect-attachment
712 (equal (car ctl) "multipart/encrypted")))
713 (setq boundary (concat (regexp-quote boundary) "[ \t]*$"))
714 (while (and (< (point) end) (re-search-forward boundary end t))
715 (goto-char (match-beginning 0))
716 (when start
717 (save-excursion
718 (save-restriction
719 (narrow-to-region start (point))
720 (setq parts (nconc (list (mm-dissect-buffer t nil from)) parts)))))
721 (end-of-line 2)
722 (or (looking-at boundary)
723 (forward-line 1))
724 (setq start (point)))
725 (when (and start (< start end))
726 (save-excursion
727 (save-restriction
728 (narrow-to-region start end)
729 (setq parts (nconc (list (mm-dissect-buffer t nil from)) parts)))))
730 (mm-possibly-verify-or-decrypt (nreverse parts) ctl from)))
731
732 (defun mm-copy-to-buffer ()
733 "Copy the contents of the current buffer to a fresh buffer."
734 (let ((obuf (current-buffer))
735 (mb (mm-multibyte-p))
736 beg)
737 (goto-char (point-min))
738 (search-forward-regexp "^\n" nil t)
739 (setq beg (point))
740 (with-current-buffer
741 (generate-new-buffer " *mm*")
742 ;; Preserve the data's unibyteness (for url-insert-file-contents).
743 (mm-set-buffer-multibyte mb)
744 (insert-buffer-substring obuf beg)
745 (current-buffer))))
746
747 (defun mm-display-parts (handle &optional no-default)
748 (if (stringp (car handle))
749 (mapcar 'mm-display-parts (cdr handle))
750 (if (bufferp (car handle))
751 (save-restriction
752 (narrow-to-region (point) (point))
753 (mm-display-part handle)
754 (goto-char (point-max)))
755 (mapcar 'mm-display-parts handle))))
756
757 (autoload 'mailcap-parse-mailcaps "mailcap")
758 (autoload 'mailcap-mime-info "mailcap")
759
760 (defun mm-display-part (handle &optional no-default force)
761 "Display the MIME part represented by HANDLE.
762 Returns nil if the part is removed; inline if displayed inline;
763 external if displayed external."
764 (save-excursion
765 (mailcap-parse-mailcaps)
766 (if (and (not force)
767 (mm-handle-displayed-p handle))
768 (mm-remove-part handle)
769 (let* ((ehandle (if (equal (mm-handle-media-type handle)
770 "message/external-body")
771 (progn
772 (unless (mm-handle-cache handle)
773 (mm-extern-cache-contents handle))
774 (mm-handle-cache handle))
775 handle))
776 (type (mm-handle-media-type ehandle))
777 (method (mailcap-mime-info type))
778 (filename (or (mail-content-type-get
779 (mm-handle-disposition handle) 'filename)
780 (mail-content-type-get
781 (mm-handle-type handle) 'name)
782 "<file>"))
783 (external mm-enable-external)
784 (decoder (assoc (car (mm-handle-type handle))
785 (mm-archive-decoders))))
786 (cond
787 ((and decoder
788 (executable-find (caddr decoder)))
789 (mm-archive-dissect-and-inline handle)
790 'inline)
791 ((and (mm-inlinable-p ehandle)
792 (mm-inlined-p ehandle))
793 (forward-line 1)
794 (mm-display-inline handle)
795 'inline)
796 ((or method
797 (not no-default))
798 (if (and (not method)
799 (equal "text" (car (split-string type "/"))))
800 (progn
801 (forward-line 1)
802 (mm-insert-inline handle (mm-get-part handle))
803 'inline)
804 (setq external
805 (and method ;; If nil, we always use "save".
806 (stringp method) ;; 'mailcap-save-binary-file
807 (or (eq mm-enable-external t)
808 (and (eq mm-enable-external 'ask)
809 (y-or-n-p
810 (concat
811 "Display part (" type
812 ") using external program"
813 ;; Can non-string method ever happen?
814 (if (stringp method)
815 (concat
816 " \"" (format method filename) "\"")
817 "")
818 "? "))))))
819 (if external
820 (mm-display-external
821 handle (or method 'mailcap-save-binary-file))
822 (mm-display-external
823 handle 'mailcap-save-binary-file)))))))))
824
825 (declare-function gnus-configure-windows "gnus-win" (setting &optional force))
826 (defvar mailcap-mime-extensions) ; mailcap-mime-info autoloads
827 (declare-function term-mode "term" ())
828 (declare-function term-char-mode "term" ())
829
830 (defun mm-display-external (handle method)
831 "Display HANDLE using METHOD."
832 (let ((outbuf (current-buffer)))
833 (mm-with-unibyte-buffer
834 (if (functionp method)
835 (let ((cur (current-buffer)))
836 (if (eq method 'mailcap-save-binary-file)
837 (progn
838 (set-buffer (generate-new-buffer " *mm*"))
839 (setq method nil))
840 (mm-insert-part handle)
841 (mm-add-meta-html-tag handle)
842 (let ((win (get-buffer-window cur t)))
843 (when win
844 (select-window win)))
845 (switch-to-buffer (generate-new-buffer " *mm*")))
846 (buffer-disable-undo)
847 (mm-set-buffer-file-coding-system mm-binary-coding-system)
848 (insert-buffer-substring cur)
849 (goto-char (point-min))
850 (when method
851 (message "Viewing with %s" method))
852 (let ((mm (current-buffer))
853 (non-viewer (assq 'non-viewer
854 (mailcap-mime-info
855 (mm-handle-media-type handle) t))))
856 (unwind-protect
857 (if method
858 (funcall method)
859 (mm-save-part handle))
860 (when (and (not non-viewer)
861 method)
862 (mm-handle-set-undisplayer handle mm)))))
863 ;; The function is a string to be executed.
864 (mm-insert-part handle)
865 (mm-add-meta-html-tag handle)
866 (let* ((dir (mm-make-temp-file
867 (expand-file-name "emm." mm-tmp-directory) 'dir))
868 (filename (or
869 (mail-content-type-get
870 (mm-handle-disposition handle) 'filename)
871 (mail-content-type-get
872 (mm-handle-type handle) 'name)))
873 (mime-info (mailcap-mime-info
874 (mm-handle-media-type handle) t))
875 (needsterm (or (assoc "needsterm" mime-info)
876 (assoc "needsterminal" mime-info)))
877 (copiousoutput (assoc "copiousoutput" mime-info))
878 file buffer)
879 ;; We create a private sub-directory where we store our files.
880 (set-file-modes dir #o700)
881 (if filename
882 (setq file (expand-file-name
883 (gnus-map-function mm-file-name-rewrite-functions
884 (file-name-nondirectory filename))
885 dir))
886 ;; Use nametemplate (defined in RFC1524) if it is specified
887 ;; in mailcap.
888 (let ((suffix (cdr (assoc "nametemplate" mime-info))))
889 (if (and suffix
890 (string-match "\\`%s\\(\\..+\\)\\'" suffix))
891 (setq suffix (match-string 1 suffix))
892 ;; Otherwise, use a suffix according to
893 ;; `mailcap-mime-extensions'.
894 (setq suffix (car (rassoc (mm-handle-media-type handle)
895 mailcap-mime-extensions))))
896 (setq file (mm-make-temp-file (expand-file-name "mm." dir)
897 nil suffix))))
898 (let ((coding-system-for-write mm-binary-coding-system))
899 (write-region (point-min) (point-max) file nil 'nomesg))
900 ;; The file is deleted after the viewer exists. If the users edits
901 ;; the file, changes will be lost. Set file to read-only to make it
902 ;; clear.
903 (set-file-modes file #o400)
904 (message "Viewing with %s" method)
905 (cond
906 (needsterm
907 (let ((command (mm-mailcap-command
908 method file (mm-handle-type handle))))
909 (unwind-protect
910 (if window-system
911 (start-process "*display*" nil
912 mm-external-terminal-program
913 "-e" shell-file-name
914 shell-command-switch command)
915 (require 'term)
916 (require 'gnus-win)
917 (set-buffer
918 (setq buffer
919 (make-term "display"
920 shell-file-name
921 nil
922 shell-command-switch command)))
923 (term-mode)
924 (term-char-mode)
925 (set-process-sentinel
926 (get-buffer-process buffer)
927 `(lambda (process state)
928 (if (eq 'exit (process-status process))
929 (gnus-configure-windows
930 ',gnus-current-window-configuration))))
931 (gnus-configure-windows 'display-term))
932 (mm-handle-set-external-undisplayer handle (cons file buffer)))
933 (message "Displaying %s..." command))
934 'external)
935 (copiousoutput
936 (with-current-buffer outbuf
937 (forward-line 1)
938 (mm-insert-inline
939 handle
940 (unwind-protect
941 (progn
942 (call-process shell-file-name nil
943 (setq buffer
944 (generate-new-buffer " *mm*"))
945 nil
946 shell-command-switch
947 (mm-mailcap-command
948 method file (mm-handle-type handle)))
949 (if (buffer-live-p buffer)
950 (with-current-buffer buffer
951 (buffer-string))))
952 (progn
953 (ignore-errors (delete-file file))
954 (ignore-errors (delete-directory
955 (file-name-directory file)))
956 (ignore-errors (kill-buffer buffer))))))
957 'inline)
958 (t
959 ;; Deleting the temp file should be postponed for some wrappers,
960 ;; shell scripts, and so on, which might exit right after having
961 ;; started a viewer command as a background job.
962 (let ((command (mm-mailcap-command
963 method file (mm-handle-type handle))))
964 (unwind-protect
965 (progn
966 (start-process "*display*"
967 (setq buffer
968 (generate-new-buffer " *mm*"))
969 shell-file-name
970 shell-command-switch command)
971 (set-process-sentinel
972 (get-buffer-process buffer)
973 (lexical-let ((outbuf outbuf)
974 (file file)
975 (buffer buffer)
976 (command command)
977 (handle handle))
978 (run-at-time
979 30.0 nil
980 (lambda ()
981 (ignore-errors
982 (delete-file file))
983 (ignore-errors
984 (delete-directory (file-name-directory file)))))
985 (lambda (process state)
986 (when (eq (process-status process) 'exit)
987 (condition-case nil
988 (delete-file file)
989 (error))
990 (condition-case nil
991 (delete-directory (file-name-directory file))
992 (error))
993 (when (buffer-live-p outbuf)
994 (with-current-buffer outbuf
995 (let ((buffer-read-only nil)
996 (point (point)))
997 (forward-line 2)
998 (let ((start (point)))
999 (mm-insert-inline
1000 handle (with-current-buffer buffer
1001 (buffer-string)))
1002 (put-text-property start (point)
1003 'face 'mm-command-output))
1004 (goto-char point))))
1005 (when (buffer-live-p buffer)
1006 (kill-buffer buffer)))
1007 (message "Displaying %s...done" command)))))
1008 (mm-handle-set-external-undisplayer
1009 handle (cons file buffer)))
1010 (message "Displaying %s..." command))
1011 'external)))))))
1012
1013 (defun mm-mailcap-command (method file type-list)
1014 (let ((ctl (cdr type-list))
1015 (beg 0)
1016 (uses-stdin t)
1017 out sub total)
1018 (while (string-match "%{\\([^}]+\\)}\\|'%s'\\|\"%s\"\\|%s\\|%t\\|%%"
1019 method beg)
1020 (push (substring method beg (match-beginning 0)) out)
1021 (setq beg (match-end 0)
1022 total (match-string 0 method)
1023 sub (match-string 1 method))
1024 (cond
1025 ((string= total "%%")
1026 (push "%" out))
1027 ((or (string= total "%s")
1028 ;; We do our own quoting.
1029 (string= total "'%s'")
1030 (string= total "\"%s\""))
1031 (setq uses-stdin nil)
1032 (push (shell-quote-argument
1033 (gnus-map-function mm-path-name-rewrite-functions file)) out))
1034 ((string= total "%t")
1035 (push (shell-quote-argument (car type-list)) out))
1036 (t
1037 (push (shell-quote-argument (or (cdr (assq (intern sub) ctl)) "")) out))))
1038 (push (substring method beg (length method)) out)
1039 (when uses-stdin
1040 (push "<" out)
1041 (push (shell-quote-argument
1042 (gnus-map-function mm-path-name-rewrite-functions file))
1043 out))
1044 (mapconcat 'identity (nreverse out) "")))
1045
1046 (defun mm-remove-parts (handles)
1047 "Remove the displayed MIME parts represented by HANDLES."
1048 (if (and (listp handles)
1049 (bufferp (car handles)))
1050 (mm-remove-part handles)
1051 (let (handle)
1052 (while (setq handle (pop handles))
1053 (cond
1054 ((stringp handle)
1055 (when (buffer-live-p (get-text-property 0 'buffer handle))
1056 (kill-buffer (get-text-property 0 'buffer handle))))
1057 ((and (listp handle)
1058 (stringp (car handle)))
1059 (mm-remove-parts (cdr handle)))
1060 (t
1061 (mm-remove-part handle)))))))
1062
1063 (defun mm-destroy-parts (handles)
1064 "Remove the displayed MIME parts represented by HANDLES."
1065 (if (and (listp handles)
1066 (bufferp (car handles)))
1067 (mm-destroy-part handles)
1068 (let (handle)
1069 (while (setq handle (pop handles))
1070 (cond
1071 ((stringp handle)
1072 (when (buffer-live-p (get-text-property 0 'buffer handle))
1073 (kill-buffer (get-text-property 0 'buffer handle))))
1074 ((and (listp handle)
1075 (stringp (car handle)))
1076 (mm-destroy-parts handle))
1077 (t
1078 (mm-destroy-part handle)))))))
1079
1080 (defun mm-remove-part (handle)
1081 "Remove the displayed MIME part represented by HANDLE."
1082 (when (listp handle)
1083 (let ((object (mm-handle-undisplayer handle)))
1084 (ignore-errors
1085 (cond
1086 ;; Internally displayed part.
1087 ((mm-annotationp object)
1088 (if (featurep 'xemacs)
1089 (delete-annotation object)))
1090 ((or (functionp object)
1091 (and (listp object)
1092 (eq (car object) 'lambda)))
1093 (funcall object))
1094 ;; Externally displayed part.
1095 ((consp object)
1096 (condition-case ()
1097 (while (get-buffer-process (cdr object))
1098 (interrupt-process (get-buffer-process (cdr object)))
1099 (message "Waiting for external displayer to die...")
1100 (sit-for 1))
1101 (quit)
1102 (error))
1103 (ignore-errors (and (cdr object) (kill-buffer (cdr object))))
1104 (message "Waiting for external displayer to die...done")
1105 (ignore-errors (delete-file (car object)))
1106 (ignore-errors (delete-directory (file-name-directory
1107 (car object)))))
1108 ((bufferp object)
1109 (when (buffer-live-p object)
1110 (kill-buffer object)))))
1111 (mm-handle-set-undisplayer handle nil))))
1112
1113 (defun mm-display-inline (handle)
1114 (let* ((type (mm-handle-media-type handle))
1115 (function (cadr (mm-assoc-string-match mm-inline-media-tests type))))
1116 (funcall function handle)
1117 (goto-char (point-min))))
1118
1119 (defun mm-assoc-string-match (alist type)
1120 (dolist (elem alist)
1121 (when (string-match (car elem) type)
1122 (return elem))))
1123
1124 (defun mm-automatic-display-p (handle)
1125 "Say whether the user wants HANDLE to be displayed automatically."
1126 (let ((methods mm-automatic-display)
1127 (type (mm-handle-media-type handle))
1128 method result)
1129 (while (setq method (pop methods))
1130 (when (and (not (mm-inline-override-p handle))
1131 (string-match method type))
1132 (setq result t
1133 methods nil)))
1134 result))
1135
1136 (defun mm-inlinable-p (handle &optional type)
1137 "Say whether HANDLE can be displayed inline.
1138 TYPE is the mime-type of the object; it defaults to the one given
1139 in HANDLE."
1140 (unless type (setq type (mm-handle-media-type handle)))
1141 (let ((alist mm-inline-media-tests)
1142 test)
1143 (while alist
1144 (when (string-match (caar alist) type)
1145 (setq test (caddar alist)
1146 alist nil)
1147 (setq test (funcall test handle)))
1148 (pop alist))
1149 test))
1150
1151 (defun mm-inlined-p (handle)
1152 "Say whether the user wants HANDLE to be displayed inline."
1153 (let ((methods mm-inlined-types)
1154 (type (mm-handle-media-type handle))
1155 method result)
1156 (while (setq method (pop methods))
1157 (when (and (not (mm-inline-override-p handle))
1158 (string-match method type))
1159 (setq result t
1160 methods nil)))
1161 result))
1162
1163 (defun mm-attachment-override-p (handle)
1164 "Say whether HANDLE should have attachment behavior overridden."
1165 (let ((types mm-attachment-override-types)
1166 (type (mm-handle-media-type handle))
1167 ty)
1168 (catch 'found
1169 (while (setq ty (pop types))
1170 (when (and (string-match ty type)
1171 (mm-inlinable-p handle))
1172 (throw 'found t))))))
1173
1174 (defun mm-inline-override-p (handle)
1175 "Say whether HANDLE should have inline behavior overridden."
1176 (let ((types mm-inline-override-types)
1177 (type (mm-handle-media-type handle))
1178 ty)
1179 (catch 'found
1180 (while (setq ty (pop types))
1181 (when (string-match ty type)
1182 (throw 'found t))))))
1183
1184 (defun mm-automatic-external-display-p (type)
1185 "Return the user-defined method for TYPE."
1186 (let ((methods mm-automatic-external-display)
1187 method result)
1188 (while (setq method (pop methods))
1189 (when (string-match method type)
1190 (setq result t
1191 methods nil)))
1192 result))
1193
1194 (defun mm-destroy-part (handle)
1195 "Destroy the data structures connected to HANDLE."
1196 (when (listp handle)
1197 (mm-remove-part handle)
1198 (when (buffer-live-p (mm-handle-buffer handle))
1199 (kill-buffer (mm-handle-buffer handle)))))
1200
1201 (defun mm-handle-displayed-p (handle)
1202 "Say whether HANDLE is displayed or not."
1203 (mm-handle-undisplayer handle))
1204
1205 ;;;
1206 ;;; Functions for outputting parts
1207 ;;;
1208
1209 (defmacro mm-with-part (handle &rest forms)
1210 "Run FORMS in the temp buffer containing the contents of HANDLE."
1211 ;; The handle-buffer's content is a sequence of bytes, not a sequence of
1212 ;; chars, so the buffer should be unibyte. It may happen that the
1213 ;; handle-buffer is multibyte for some reason, in which case now is a good
1214 ;; time to adjust it, since we know at this point that it should
1215 ;; be unibyte.
1216 `(let* ((handle ,handle))
1217 (when (and (mm-handle-buffer handle)
1218 (buffer-name (mm-handle-buffer handle)))
1219 (with-temp-buffer
1220 (mm-disable-multibyte)
1221 (insert-buffer-substring (mm-handle-buffer handle))
1222 (mm-decode-content-transfer-encoding
1223 (mm-handle-encoding handle)
1224 (mm-handle-media-type handle))
1225 ,@forms))))
1226 (put 'mm-with-part 'lisp-indent-function 1)
1227 (put 'mm-with-part 'edebug-form-spec '(body))
1228
1229 (defun mm-get-part (handle &optional no-cache)
1230 "Return the contents of HANDLE as a string.
1231 If NO-CACHE is non-nil, cached contents of a message/external-body part
1232 are ignored."
1233 (if (and (not no-cache)
1234 (equal (mm-handle-media-type handle) "message/external-body"))
1235 (progn
1236 (unless (mm-handle-cache handle)
1237 (mm-extern-cache-contents handle))
1238 (with-current-buffer (mm-handle-buffer (mm-handle-cache handle))
1239 (buffer-string)))
1240 (mm-with-part handle
1241 (buffer-string))))
1242
1243 (defun mm-insert-part (handle &optional no-cache)
1244 "Insert the contents of HANDLE in the current buffer.
1245 If NO-CACHE is non-nil, cached contents of a message/external-body part
1246 are ignored."
1247 (let ((text (cond ((eq (mail-content-type-get (mm-handle-type handle)
1248 'charset)
1249 'gnus-decoded)
1250 (with-current-buffer (mm-handle-buffer handle)
1251 (buffer-string)))
1252 ((mm-multibyte-p)
1253 (mm-string-to-multibyte (mm-get-part handle no-cache)))
1254 (t
1255 (mm-get-part handle no-cache)))))
1256 (save-restriction
1257 (widen)
1258 (goto-char
1259 (prog1
1260 (point)
1261 (if (and (eq (get-char-property (max (point-min) (1- (point))) 'face)
1262 'mm-uu-extract)
1263 (eq (get-char-property 0 'face text) 'mm-uu-extract))
1264 ;; Separate the extracted parts that have the same faces.
1265 (insert "\n" text)
1266 (insert text)))))))
1267
1268 (defun mm-file-name-delete-whitespace (file-name)
1269 "Remove all whitespace characters from FILE-NAME."
1270 (while (string-match "\\s-+" file-name)
1271 (setq file-name (replace-match "" t t file-name)))
1272 file-name)
1273
1274 (defun mm-file-name-trim-whitespace (file-name)
1275 "Remove leading and trailing whitespace characters from FILE-NAME."
1276 (when (string-match "\\`\\s-+" file-name)
1277 (setq file-name (substring file-name (match-end 0))))
1278 (when (string-match "\\s-+\\'" file-name)
1279 (setq file-name (substring file-name 0 (match-beginning 0))))
1280 file-name)
1281
1282 (defun mm-file-name-collapse-whitespace (file-name)
1283 "Collapse multiple whitespace characters in FILE-NAME."
1284 (while (string-match "\\s-\\s-+" file-name)
1285 (setq file-name (replace-match " " t t file-name)))
1286 file-name)
1287
1288 (defun mm-file-name-replace-whitespace (file-name)
1289 "Replace whitespace characters in FILE-NAME with underscores.
1290 Set the option `mm-file-name-replace-whitespace' to any other
1291 string if you do not like underscores."
1292 (let ((s (or mm-file-name-replace-whitespace "_")))
1293 (while (string-match "\\s-" file-name)
1294 (setq file-name (replace-match s t t file-name))))
1295 file-name)
1296
1297 (defun mm-file-name-delete-control (filename)
1298 "Delete control characters from FILENAME."
1299 (gnus-replace-in-string filename "[\x00-\x1f\x7f]" ""))
1300
1301 (defun mm-file-name-delete-gotchas (filename)
1302 "Delete shell gotchas from FILENAME."
1303 (setq filename (gnus-replace-in-string filename "[<>|]" ""))
1304 (gnus-replace-in-string filename "^[.-]+" ""))
1305
1306 (defun mm-save-part (handle &optional prompt)
1307 "Write HANDLE to a file.
1308 PROMPT overrides the default one used to ask user for a file name."
1309 (let ((filename (or (mail-content-type-get
1310 (mm-handle-disposition handle) 'filename)
1311 (mail-content-type-get
1312 (mm-handle-type handle) 'name)))
1313 file)
1314 (when filename
1315 (setq filename (gnus-map-function mm-file-name-rewrite-functions
1316 (file-name-nondirectory filename))))
1317 (while
1318 (progn
1319 (setq file
1320 (read-file-name
1321 (or prompt
1322 (format "Save MIME part to (default %s): "
1323 (or filename "")))
1324 (or mm-default-directory default-directory)
1325 (expand-file-name (or filename "")
1326 (or mm-default-directory default-directory))))
1327 (cond ((or (not file) (equal file ""))
1328 (message "Please enter a file name")
1329 t)
1330 ((and (file-directory-p file)
1331 (not filename))
1332 (message "Please enter a non-directory file name")
1333 t)
1334 (t nil)))
1335 (sit-for 2)
1336 (discard-input))
1337 (if (file-directory-p file)
1338 (setq file (expand-file-name filename file))
1339 (setq file (expand-file-name
1340 file (or mm-default-directory default-directory))))
1341 (setq mm-default-directory (file-name-directory file))
1342 (and (or (not (file-exists-p file))
1343 (yes-or-no-p (format "File %s already exists; overwrite? "
1344 file)))
1345 (progn
1346 (mm-save-part-to-file handle file)
1347 file))))
1348
1349 (defun mm-add-meta-html-tag (handle &optional charset force-charset)
1350 "Add meta html tag to specify CHARSET of HANDLE in the current buffer.
1351 CHARSET defaults to the one HANDLE specifies. Existing meta tag that
1352 specifies charset will not be modified unless FORCE-CHARSET is non-nil.
1353 Return t if meta tag is added or replaced."
1354 (when (equal (mm-handle-media-type handle) "text/html")
1355 (when (or charset
1356 (setq charset (mail-content-type-get (mm-handle-type handle)
1357 'charset)))
1358 (setq charset (format "\
1359 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">" charset))
1360 (let ((case-fold-search t))
1361 (goto-char (point-min))
1362 (if (re-search-forward "\
1363 <meta\\s-+http-equiv=[\"']?content-type[\"']?\\s-+content=[\"']\
1364 text/\\(\\sw+\\)\\(?:\;\\s-*charset=\\(.+\\)\\)?[\"'][^>]*>" nil t)
1365 (if (and (not force-charset)
1366 (match-beginning 2)
1367 (string-match "\\`html\\'" (match-string 1)))
1368 ;; Don't modify existing meta tag.
1369 nil
1370 ;; Replace it with the one specifying charset.
1371 (replace-match charset)
1372 t)
1373 (if (re-search-forward "<head>\\s-*" nil t)
1374 (insert charset "\n")
1375 (re-search-forward "<html\\(?:\\s-+[^>]+\\|\\s-*\\)>\\s-*" nil t)
1376 (insert "<head>\n" charset "\n</head>\n"))
1377 t)))))
1378
1379 (defun mm-save-part-to-file (handle file)
1380 (mm-with-unibyte-buffer
1381 (mm-insert-part handle)
1382 (mm-add-meta-html-tag handle)
1383 (let ((current-file-modes (default-file-modes)))
1384 (set-default-file-modes mm-attachment-file-modes)
1385 (unwind-protect
1386 ;; Don't re-compress .gz & al. Arguably we should make
1387 ;; `file-name-handler-alist' nil, but that would chop
1388 ;; ange-ftp, which is reasonable to use here.
1389 (mm-write-region (point-min) (point-max) file nil nil nil 'binary t)
1390 (set-default-file-modes current-file-modes)))))
1391
1392 (defun mm-pipe-part (handle &optional cmd)
1393 "Pipe HANDLE to a process.
1394 Use CMD as the process."
1395 (let ((name (mail-content-type-get (mm-handle-type handle) 'name))
1396 (command (or cmd
1397 (gnus-read-shell-command
1398 "Shell command on MIME part: " mm-last-shell-command))))
1399 (mm-with-unibyte-buffer
1400 (mm-insert-part handle)
1401 (mm-add-meta-html-tag handle)
1402 (let ((coding-system-for-write 'binary))
1403 (shell-command-on-region (point-min) (point-max) command nil)))))
1404
1405 (autoload 'gnus-completing-read "gnus-util")
1406
1407 (defun mm-interactively-view-part (handle)
1408 "Display HANDLE using METHOD."
1409 (let* ((type (mm-handle-media-type handle))
1410 (methods
1411 (mapcar (lambda (i) (cdr (assoc 'viewer i)))
1412 (mailcap-mime-info type 'all)))
1413 (method (let ((minibuffer-local-completion-map
1414 mm-viewer-completion-map))
1415 (completing-read "Viewer: " methods))))
1416 (when (string= method "")
1417 (error "No method given"))
1418 (if (string-match "^[^% \t]+$" method)
1419 (setq method (concat method " %s")))
1420 (mm-display-external handle method)))
1421
1422 (defun mm-preferred-alternative (handles &optional preferred)
1423 "Say which of HANDLES are preferred."
1424 (let ((prec (if preferred (list preferred)
1425 (mm-preferred-alternative-precedence handles)))
1426 p h result type handle)
1427 (while (setq p (pop prec))
1428 (setq h handles)
1429 (while h
1430 (setq handle (car h))
1431 (setq type (mm-handle-media-type handle))
1432 (when (and (equal p type)
1433 (mm-automatic-display-p handle)
1434 (or (stringp (car handle))
1435 (not (mm-handle-disposition handle))
1436 (equal (car (mm-handle-disposition handle))
1437 "inline")))
1438 (setq result handle
1439 h nil
1440 prec nil))
1441 (pop h)))
1442 result))
1443
1444 (defun mm-preferred-alternative-precedence (handles)
1445 "Return the precedence based on HANDLES and `mm-discouraged-alternatives'."
1446 (setq handles (reverse handles))
1447 (dolist (disc (reverse mm-discouraged-alternatives))
1448 (dolist (handle (copy-sequence handles))
1449 (when (string-match disc (mm-handle-media-type handle))
1450 (setq handles (nconc (delete handle handles) (list handle))))))
1451 ;; Remove empty parts.
1452 (dolist (handle (copy-sequence handles))
1453 (when (and (bufferp (mm-handle-buffer handle))
1454 (not (with-current-buffer (mm-handle-buffer handle)
1455 (goto-char (point-min))
1456 (re-search-forward "[^ \t\n]" nil t))))
1457 (setq handles (nconc (delete handle handles) (list handle)))))
1458 (mapcar #'mm-handle-media-type handles))
1459
1460 (defun mm-get-content-id (id)
1461 "Return the handle(s) referred to by ID."
1462 (cdr (assoc id mm-content-id-alist)))
1463
1464 (defconst mm-image-type-regexps
1465 '(("/\\*.*XPM.\\*/" . xpm)
1466 ("P[1-6]" . pbm)
1467 ("GIF8" . gif)
1468 ("\377\330" . jpeg)
1469 ("\211PNG\r\n" . png)
1470 ("#define" . xbm)
1471 ("\\(MM\0\\*\\)\\|\\(II\\*\0\\)" . tiff)
1472 ("%!PS" . postscript))
1473 "Alist of (REGEXP . IMAGE-TYPE) pairs used to auto-detect image types.
1474 When the first bytes of an image file match REGEXP, it is assumed to
1475 be of image type IMAGE-TYPE.")
1476
1477 ;; Steal from image.el. image-type-from-data suffers multi-line matching bug.
1478 (defun mm-image-type-from-buffer ()
1479 "Determine the image type from data in the current buffer.
1480 Value is a symbol specifying the image type or nil if type cannot
1481 be determined."
1482 (let ((types mm-image-type-regexps)
1483 type)
1484 (goto-char (point-min))
1485 (while (and types (null type))
1486 (let ((regexp (car (car types)))
1487 (image-type (cdr (car types))))
1488 (when (looking-at regexp)
1489 (setq type image-type))
1490 (setq types (cdr types))))
1491 type))
1492
1493 (defun mm-get-image (handle)
1494 "Return an image instance based on HANDLE."
1495 (let ((type (mm-handle-media-subtype handle))
1496 spec)
1497 ;; Allow some common translations.
1498 (setq type
1499 (cond
1500 ((equal type "x-pixmap")
1501 "xpm")
1502 ((equal type "x-xbitmap")
1503 "xbm")
1504 ((equal type "x-portable-bitmap")
1505 "pbm")
1506 (t type)))
1507 (or (mm-handle-cache handle)
1508 (mm-with-unibyte-buffer
1509 (mm-insert-part handle)
1510 (prog1
1511 (setq spec
1512 (ignore-errors
1513 ;; Avoid testing `make-glyph' since W3 may define
1514 ;; a bogus version of it.
1515 (if (fboundp 'create-image)
1516 (create-image (buffer-string)
1517 (or (mm-image-type-from-buffer)
1518 (intern type))
1519 'data-p)
1520 (mm-create-image-xemacs type))))
1521 (mm-handle-set-cache handle spec))))))
1522
1523 (defun mm-create-image-xemacs (type)
1524 (when (featurep 'xemacs)
1525 (cond
1526 ((equal type "xbm")
1527 ;; xbm images require special handling, since
1528 ;; the only way to create glyphs from these
1529 ;; (without a ton of work) is to write them
1530 ;; out to a file, and then create a file
1531 ;; specifier.
1532 (let ((file (mm-make-temp-file
1533 (expand-file-name "emm" mm-tmp-directory)
1534 nil ".xbm")))
1535 (unwind-protect
1536 (progn
1537 (write-region (point-min) (point-max) file)
1538 (make-glyph (list (cons 'x file))))
1539 (ignore-errors
1540 (delete-file file)))))
1541 (t
1542 (make-glyph
1543 (vector
1544 (or (mm-image-type-from-buffer)
1545 (intern type))
1546 :data (buffer-string)))))))
1547
1548 (declare-function image-size "image.c" (spec &optional pixels frame))
1549
1550 (defun mm-image-fit-p (handle)
1551 "Say whether the image in HANDLE will fit the current window."
1552 (let ((image (mm-get-image handle)))
1553 (or (not image)
1554 (if (featurep 'xemacs)
1555 ;; XEmacs's glyphs can actually tell us about their width, so
1556 ;; let's be nice and smart about them.
1557 (or mm-inline-large-images
1558 (and (<= (glyph-width image) (window-pixel-width))
1559 (<= (glyph-height image) (window-pixel-height))))
1560 (let* ((size (image-size image))
1561 (w (car size))
1562 (h (cdr size)))
1563 (or mm-inline-large-images
1564 (and (<= h (1- (window-height))) ; Don't include mode line.
1565 (<= w (window-width)))))))))
1566
1567 (defun mm-valid-image-format-p (format)
1568 "Say whether FORMAT can be displayed natively by Emacs."
1569 (cond
1570 ;; Handle XEmacs
1571 ((fboundp 'valid-image-instantiator-format-p)
1572 (valid-image-instantiator-format-p format))
1573 ;; Handle Emacs
1574 ((fboundp 'image-type-available-p)
1575 (and (display-graphic-p)
1576 (image-type-available-p format)))
1577 ;; Nobody else can do images yet.
1578 (t
1579 nil)))
1580
1581 (defun mm-valid-and-fit-image-p (format handle)
1582 "Say whether FORMAT can be displayed natively and HANDLE fits the window."
1583 (and (mm-valid-image-format-p format)
1584 (mm-image-fit-p handle)))
1585
1586 (defun mm-find-part-by-type (handles type &optional notp recursive)
1587 "Search in HANDLES for part with TYPE.
1588 If NOTP, returns first non-matching part.
1589 If RECURSIVE, search recursively."
1590 (let (handle)
1591 (while handles
1592 (if (and recursive (stringp (caar handles)))
1593 (if (setq handle (mm-find-part-by-type (cdar handles) type
1594 notp recursive))
1595 (setq handles nil))
1596 (if (if notp
1597 (not (equal (mm-handle-media-type (car handles)) type))
1598 (equal (mm-handle-media-type (car handles)) type))
1599 (setq handle (car handles)
1600 handles nil)))
1601 (setq handles (cdr handles)))
1602 handle))
1603
1604 (defun mm-find-raw-part-by-type (ctl type &optional notp)
1605 (goto-char (point-min))
1606 (let* ((boundary (concat "--" (mm-handle-multipart-ctl-parameter ctl
1607 'boundary)))
1608 (close-delimiter (concat "^" (regexp-quote boundary) "--[ \t]*$"))
1609 start
1610 (end (save-excursion
1611 (goto-char (point-max))
1612 (if (re-search-backward close-delimiter nil t)
1613 (match-beginning 0)
1614 (point-max))))
1615 result)
1616 (setq boundary (concat "^" (regexp-quote boundary) "[ \t]*$"))
1617 (while (and (not result)
1618 (re-search-forward boundary end t))
1619 (goto-char (match-beginning 0))
1620 (when start
1621 (save-excursion
1622 (save-restriction
1623 (narrow-to-region start (1- (point)))
1624 (when (let* ((ct (mail-fetch-field "content-type"))
1625 (ctl (and ct (mail-header-parse-content-type ct))))
1626 (if notp
1627 (not (equal (car ctl) type))
1628 (equal (car ctl) type)))
1629 (setq result (buffer-string))))))
1630 (forward-line 1)
1631 (setq start (point)))
1632 (when (and (not result) start)
1633 (save-excursion
1634 (save-restriction
1635 (narrow-to-region start end)
1636 (when (let* ((ct (mail-fetch-field "content-type"))
1637 (ctl (and ct (mail-header-parse-content-type ct))))
1638 (if notp
1639 (not (equal (car ctl) type))
1640 (equal (car ctl) type)))
1641 (setq result (buffer-string))))))
1642 result))
1643
1644 (defvar mm-security-handle nil)
1645
1646 (defsubst mm-set-handle-multipart-parameter (handle parameter value)
1647 ;; HANDLE could be a CTL.
1648 (when handle
1649 (put-text-property 0 (length (car handle)) parameter value
1650 (car handle))))
1651
1652 (autoload 'mm-view-pkcs7 "mm-view")
1653
1654 (defun mm-possibly-verify-or-decrypt (parts ctl &optional from)
1655 (let ((type (car ctl))
1656 (subtype (cadr (split-string (car ctl) "/")))
1657 (mm-security-handle ctl) ;; (car CTL) is the type.
1658 protocol func functest)
1659 (cond
1660 ((or (equal type "application/x-pkcs7-mime")
1661 (equal type "application/pkcs7-mime"))
1662 (with-temp-buffer
1663 (when (and (cond
1664 ((eq mm-decrypt-option 'never) nil)
1665 ((eq mm-decrypt-option 'always) t)
1666 ((eq mm-decrypt-option 'known) t)
1667 (t (y-or-n-p
1668 (format "Decrypt (S/MIME) part? "))))
1669 (mm-view-pkcs7 parts from))
1670 (setq parts (mm-dissect-buffer t)))))
1671 ((equal subtype "signed")
1672 (unless (and (setq protocol
1673 (mm-handle-multipart-ctl-parameter ctl 'protocol))
1674 (not (equal protocol "multipart/mixed")))
1675 ;; The message is broken or draft-ietf-openpgp-multsig-01.
1676 (let ((protocols mm-verify-function-alist))
1677 (while protocols
1678 (if (and (or (not (setq functest (nth 3 (car protocols))))
1679 (funcall functest parts ctl))
1680 (mm-find-part-by-type parts (caar protocols) nil t))
1681 (setq protocol (caar protocols)
1682 protocols nil)
1683 (setq protocols (cdr protocols))))))
1684 (setq func (nth 1 (assoc protocol mm-verify-function-alist)))
1685 (when (cond
1686 ((eq mm-verify-option 'never) nil)
1687 ((eq mm-verify-option 'always) t)
1688 ((eq mm-verify-option 'known)
1689 (and func
1690 (or (not (setq functest
1691 (nth 3 (assoc protocol
1692 mm-verify-function-alist))))
1693 (funcall functest parts ctl))))
1694 (t
1695 (y-or-n-p
1696 (format "Verify signed (%s) part? "
1697 (or (nth 2 (assoc protocol mm-verify-function-alist))
1698 (format "protocol=%s" protocol))))))
1699 (save-excursion
1700 (if func
1701 (setq parts (funcall func parts ctl))
1702 (mm-set-handle-multipart-parameter
1703 mm-security-handle 'gnus-details
1704 (format "Unknown sign protocol (%s)" protocol))))))
1705 ((equal subtype "encrypted")
1706 (unless (setq protocol
1707 (mm-handle-multipart-ctl-parameter ctl 'protocol))
1708 ;; The message is broken.
1709 (let ((parts parts))
1710 (while parts
1711 (if (assoc (mm-handle-media-type (car parts))
1712 mm-decrypt-function-alist)
1713 (setq protocol (mm-handle-media-type (car parts))
1714 parts nil)
1715 (setq parts (cdr parts))))))
1716 (setq func (nth 1 (assoc protocol mm-decrypt-function-alist)))
1717 (when (cond
1718 ((eq mm-decrypt-option 'never) nil)
1719 ((eq mm-decrypt-option 'always) t)
1720 ((eq mm-decrypt-option 'known)
1721 (and func
1722 (or (not (setq functest
1723 (nth 3 (assoc protocol
1724 mm-decrypt-function-alist))))
1725 (funcall functest parts ctl))))
1726 (t
1727 (y-or-n-p
1728 (format "Decrypt (%s) part? "
1729 (or (nth 2 (assoc protocol mm-decrypt-function-alist))
1730 (format "protocol=%s" protocol))))))
1731 (save-excursion
1732 (if func
1733 (setq parts (funcall func parts ctl))
1734 (mm-set-handle-multipart-parameter
1735 mm-security-handle 'gnus-details
1736 (format "Unknown encrypt protocol (%s)" protocol))))))
1737 (t nil))
1738 parts))
1739
1740 (defun mm-multiple-handles (handles)
1741 (and (listp handles)
1742 (> (length handles) 1)
1743 (or (listp (car handles))
1744 (stringp (car handles)))))
1745
1746 (defun mm-complicated-handles (handles)
1747 (and (listp (car handles))
1748 (> (length handles) 1)))
1749
1750 (defun mm-merge-handles (handles1 handles2)
1751 (append
1752 (if (listp (car handles1))
1753 handles1
1754 (list handles1))
1755 (if (listp (car handles2))
1756 handles2
1757 (list handles2))))
1758
1759 (defun mm-readable-p (handle)
1760 "Say whether the content of HANDLE is readable."
1761 (and (< (with-current-buffer (mm-handle-buffer handle)
1762 (buffer-size)) 10000)
1763 (mm-with-unibyte-buffer
1764 (mm-insert-part handle)
1765 (and (eq (mm-body-7-or-8) '7bit)
1766 (not (mm-long-lines-p 76))))))
1767
1768 (declare-function libxml-parse-html-region "xml.c"
1769 (start end &optional base-url))
1770 (declare-function shr-insert-document "shr" (dom))
1771 (defvar shr-blocked-images)
1772 (defvar gnus-inhibit-images)
1773 (autoload 'gnus-blocked-images "gnus-art")
1774
1775 (defun mm-shr (handle)
1776 ;; Require since we bind its variables.
1777 (require 'shr)
1778 (let ((article-buffer (current-buffer))
1779 (shr-content-function (lambda (id)
1780 (let ((handle (mm-get-content-id id)))
1781 (when handle
1782 (mm-with-part handle
1783 (buffer-string))))))
1784 shr-inhibit-images shr-blocked-images charset char)
1785 (if (and (boundp 'gnus-summary-buffer)
1786 (bufferp gnus-summary-buffer)
1787 (buffer-name gnus-summary-buffer))
1788 (with-current-buffer gnus-summary-buffer
1789 (setq shr-inhibit-images gnus-inhibit-images
1790 shr-blocked-images (gnus-blocked-images)))
1791 (setq shr-inhibit-images gnus-inhibit-images
1792 shr-blocked-images (gnus-blocked-images)))
1793 (unless handle
1794 (setq handle (mm-dissect-buffer t)))
1795 (setq charset (mail-content-type-get (mm-handle-type handle) 'charset))
1796 (save-restriction
1797 (narrow-to-region (point) (point))
1798 (shr-insert-document
1799 (mm-with-part handle
1800 (insert (prog1
1801 (if (and charset
1802 (setq charset
1803 (mm-charset-to-coding-system charset
1804 nil t))
1805 (not (eq charset 'ascii)))
1806 (mm-decode-coding-string (buffer-string) charset)
1807 (mm-string-as-multibyte (buffer-string)))
1808 (erase-buffer)
1809 (mm-enable-multibyte)))
1810 (goto-char (point-min))
1811 (setq case-fold-search t)
1812 (while (re-search-forward
1813 "&#\\(?:x\\([89][0-9a-f]\\)\\|\\(1[2-5][0-9]\\)\\);" nil t)
1814 (when (setq char
1815 (cdr (assq (if (match-beginning 1)
1816 (string-to-number (match-string 1) 16)
1817 (string-to-number (match-string 2)))
1818 mm-extra-numeric-entities)))
1819 (replace-match (char-to-string char))))
1820 ;; Remove "soft hyphens".
1821 (goto-char (point-min))
1822 (while (search-forward "­" nil t)
1823 (replace-match "" t t))
1824 (libxml-parse-html-region (point-min) (point-max))))
1825 (unless (bobp)
1826 (insert "\n"))
1827 (mm-convert-shr-links)
1828 (mm-handle-set-undisplayer
1829 handle
1830 `(lambda ()
1831 (let ((inhibit-read-only t))
1832 (delete-region ,(point-min-marker)
1833 ,(point-max-marker))))))))
1834
1835 (defvar shr-map)
1836
1837 (autoload 'widget-convert-button "wid-edit")
1838
1839 (defun mm-convert-shr-links ()
1840 (let ((start (point-min))
1841 end)
1842 (while (and start
1843 (< start (point-max)))
1844 (when (setq start (text-property-not-all start (point-max) 'shr-url nil))
1845 (setq end (next-single-property-change start 'shr-url nil (point-max)))
1846 (widget-convert-button
1847 'url-link start end
1848 :help-echo (get-text-property start 'help-echo)
1849 :keymap shr-map
1850 (get-text-property start 'shr-url))
1851 (put-text-property start end 'local-map nil)
1852 (setq start end)))))
1853
1854 (defun mm-handle-filename (handle)
1855 "Return filename of HANDLE if any."
1856 (or (mail-content-type-get (mm-handle-type handle)
1857 'name)
1858 (mail-content-type-get (mm-handle-disposition handle)
1859 'filename)))
1860
1861 (provide 'mm-decode)
1862
1863 ;; Local Variables:
1864 ;; coding: utf-8
1865 ;; End:
1866
1867 ;;; mm-decode.el ends here