0538fb5787e3aabed662d6edb4938e91a4096bb0
[elisp/gnus.git-] / lisp / mm-decode.el
1 ;;; mm-decode.el --- Functions for decoding MIME things
2 ;; Copyright (C) 1998,99 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;;      MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; This file is part of GNU Emacs.
7
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
12
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ;; Boston, MA 02111-1307, USA.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (require 'mail-parse)
28 (require 'mailcap)
29 (require 'mm-bodies)
30
31 ;;; Convenience macros.
32
33 (defmacro mm-handle-buffer (handle)
34   `(nth 0 ,handle))
35 (defmacro mm-handle-type (handle)
36   `(nth 1 ,handle))
37 (defmacro mm-handle-encoding (handle)
38   `(nth 2 ,handle))
39 (defmacro mm-handle-undisplayer (handle)
40   `(nth 3 ,handle))
41 (defmacro mm-handle-set-undisplayer (handle function)
42   `(setcar (nthcdr 3 ,handle) ,function))
43 (defmacro mm-handle-disposition (handle)
44   `(nth 4 ,handle))
45 (defmacro mm-handle-description (handle)
46   `(nth 5 ,handle))
47 (defmacro mm-handle-cache (handle)
48   `(nth 6 ,handle))
49 (defmacro mm-handle-set-cache (handle contents)
50   `(setcar (nthcdr 6 ,handle) ,contents))
51 (defmacro mm-handle-id (handle)
52   `(nth 7 ,handle))
53 (defmacro mm-make-handle (&optional buffer type encoding undisplayer
54                                     disposition description cache
55                                     id)
56   `(list ,buffer ,type ,encoding ,undisplayer
57          ,disposition ,description ,cache ,id))
58
59 (defvar mm-inline-media-tests
60   '(("image/jpeg" mm-inline-image (mm-valid-and-fit-image-p 'jpeg handle))
61     ("image/png" mm-inline-image (mm-valid-and-fit-image-p 'png handle))
62     ("image/gif" mm-inline-image (mm-valid-and-fit-image-p 'gif handle))
63     ("image/tiff" mm-inline-image (mm-valid-and-fit-image-p 'tiff handle)) 
64     ("image/xbm" mm-inline-image (mm-valid-and-fit-image-p 'xbm handle))
65     ("image/x-xbitmap" mm-inline-image (mm-valid-and-fit-image-p 'xbm handle))
66     ("image/xpm" mm-inline-image (mm-valid-and-fit-image-p 'xpm handle))
67     ("image/x-pixmap" mm-inline-image (mm-valid-and-fit-image-p 'xpm handle))
68     ("image/bmp" mm-inline-image (mm-valid-and-fit-image-p 'bmp handle))
69     ("text/plain" mm-inline-text t)
70     ("text/enriched" mm-inline-text t)
71     ("text/richtext" mm-inline-text t)
72     ("text/html" mm-inline-text (locate-library "w3"))
73     ("text/x-vcard" mm-inline-text (locate-library "vcard"))
74     ("message/delivery-status" mm-inline-text t)
75     ("message/rfc822" mm-inline-message t)
76     ("text/.*" mm-inline-text t)
77     ("audio/wav" mm-inline-audio
78      (and (or (featurep 'nas-sound) (featurep 'native-sound))
79           (device-sound-enabled-p)))
80     ("audio/au" mm-inline-audio
81      (and (or (featurep 'nas-sound) (featurep 'native-sound))
82           (device-sound-enabled-p)))
83     ("multipart/alternative" ignore t)
84     ("multipart/mixed" ignore t)
85     ("multipart/related" ignore t))
86   "Alist of media types/test that say whether the media types can be displayed inline.")
87
88 (defvar mm-user-display-methods
89   '(("image/.*" . inline)
90     ("text/.*" . inline)
91     ("message/delivery-status" . inline)
92     ("message/rfc822" . inline)))
93
94 (defvar mm-user-automatic-display
95   '("text/plain" "text/enriched" "text/richtext" "text/html"
96     "text/x-vcard" "image/.*" "message/delivery-status" "multipart/.*"
97     "message/rfc822"))
98
99 (defvar mm-attachment-override-types
100   '("text/plain" "text/x-vcard")
101   "Types that should have \"attachment\" ignored if they can be displayed inline.")
102
103 (defvar mm-user-automatic-external-display nil
104   "List of MIME type regexps that will be displayed externally automatically.")
105
106 (defvar mm-discouraged-alternatives nil
107   "List of MIME types that are discouraged when viewing multiapart/alternative.
108 Viewing agents are supposed to view the last possible part of a message,
109 as that is supposed to be the richest.  However, users may prefer other
110 types instead, and this list says what types are most unwanted.  If,
111 for instance, text/html parts are very unwanted, and text/richtech are
112 somewhat unwanted, then the value of this variable should be set
113 to:
114
115  (\"text/html\" \"text/richtext\")")
116
117 (defvar mm-tmp-directory
118   (cond ((fboundp 'temp-directory) (temp-directory))
119         ((boundp 'temporary-file-directory) temporary-file-directory)
120         ("/tmp/"))
121   "Where mm will store its temporary files.")
122
123 (defvar mm-all-images-fit nil
124   "If non-nil, then all images fit in the buffer.")
125
126 ;;; Internal variables.
127
128 (defvar mm-dissection-list nil)
129 (defvar mm-last-shell-command "")
130 (defvar mm-content-id-alist nil)
131
132 ;;; The functions.
133
134 (defun mm-dissect-buffer (&optional no-strict-mime)
135   "Dissect the current buffer and return a list of MIME handles."
136   (save-excursion
137     (let (ct ctl type subtype cte cd description id result)
138       (save-restriction
139         (mail-narrow-to-head)
140         (when (or no-strict-mime
141                   (mail-fetch-field "mime-version"))
142           (setq ct (mail-fetch-field "content-type")
143                 ctl (ignore-errors (mail-header-parse-content-type ct))
144                 cte (mail-fetch-field "content-transfer-encoding")
145                 cd (mail-fetch-field "content-disposition")
146                 description (mail-fetch-field "content-description")
147                 id (mail-fetch-field "content-id"))))
148       (if (or (not ctl)
149               (not (string-match "/" (car ctl))))
150           (mm-dissect-singlepart
151            '("text/plain") nil no-strict-mime
152            (and cd (ignore-errors (mail-header-parse-content-disposition cd)))
153            description)
154         (setq type (split-string (car ctl) "/"))
155         (setq subtype (cadr type)
156               type (pop type))
157         (setq
158          result
159          (cond
160           ((equal type "multipart")
161            (cons (car ctl) (mm-dissect-multipart ctl)))
162           (t
163            (mm-dissect-singlepart
164             ctl
165             (and cte (intern (downcase (mail-header-remove-whitespace
166                                         (mail-header-remove-comments
167                                          cte)))))
168             no-strict-mime
169             (and cd (ignore-errors (mail-header-parse-content-disposition cd)))
170             description id))))
171         (when id
172           (when (string-match " *<\\(.*\\)> *" id)
173             (setq id (match-string 1 id)))
174           (push (cons id result) mm-content-id-alist))
175         result))))
176
177 (defun mm-dissect-singlepart (ctl cte &optional force cdl description id)
178   (when (or force
179             (not (equal "text/plain" (car ctl))))
180     (let ((res (mm-make-handle
181                 (mm-copy-to-buffer) ctl cte nil cdl description nil id)))
182       (push (car res) mm-dissection-list)
183       res)))
184
185 (defun mm-remove-all-parts ()
186   "Remove all MIME handles."
187   (interactive)
188   (mapcar 'mm-remove-part mm-dissection-list)
189   (setq mm-dissection-list nil))
190
191 (defun mm-dissect-multipart (ctl)
192   (goto-char (point-min))
193   (let* ((boundary (concat "\n--" (mail-content-type-get ctl 'boundary)))
194         (close-delimiter (concat (regexp-quote boundary) "--[ \t]*$"))
195         start parts
196         (end (save-excursion
197                (goto-char (point-max))
198                (if (re-search-backward close-delimiter nil t)
199                    (match-beginning 0)
200                  (point-max)))))
201     (while (search-forward boundary end t)
202       (goto-char (match-beginning 0))
203       (when start
204         (save-excursion
205           (save-restriction
206             (narrow-to-region start (point))
207             (setq parts (nconc (list (mm-dissect-buffer t)) parts)))))
208       (forward-line 2)
209       (setq start (point)))
210     (when start
211       (save-excursion
212         (save-restriction
213           (narrow-to-region start end)
214           (setq parts (nconc (list (mm-dissect-buffer t)) parts)))))
215     (nreverse parts)))
216
217 (defun mm-copy-to-buffer ()
218   "Copy the contents of the current buffer to a fresh buffer."
219   (save-excursion
220     (let ((obuf (current-buffer))
221           beg)
222       (goto-char (point-min))
223       (search-forward-regexp "^\n" nil t)
224       (setq beg (point))
225       (set-buffer (generate-new-buffer " *mm*"))
226       (insert-buffer-substring obuf beg)
227       (current-buffer))))
228
229 (defun mm-inlinable-part-p (type)
230   "Say whether TYPE can be displayed inline."
231   (eq (mm-user-method type) 'inline))
232
233 (defun mm-display-part (handle &optional no-default)
234   "Display the MIME part represented by HANDLE.
235 Returns nil if the part is removed; inline if displayed inline;
236 external if displayed external."
237   (save-excursion
238     (mailcap-parse-mailcaps)
239     (if (mm-handle-displayed-p handle)
240         (mm-remove-part handle)
241       (let* ((type (car (mm-handle-type handle)))
242              (method (mailcap-mime-info type))
243              (user-method (mm-user-method type)))
244         (if (eq user-method 'inline)
245             (progn
246               (forward-line 1)
247               (mm-display-inline handle)
248               'inline)
249           (when (or user-method
250                     method
251                     (not no-default))
252             (if (and (not user-method)
253                      (not method)
254                      (equal "text" (car (split-string type))))
255                 (progn
256                   (forward-line 1)
257                   (mm-insert-inline handle (mm-get-part handle))
258                   'inline)
259               (mm-display-external
260                handle (or user-method method
261                           'mailcap-save-binary-file))
262               'external)))))))
263
264 (defun mm-display-external (handle method)
265   "Display HANDLE using METHOD."
266   (mm-with-unibyte-buffer
267     (if (functionp method)
268         (let ((cur (current-buffer)))
269           (if (eq method 'mailcap-save-binary-file)
270               (progn
271                 (set-buffer (generate-new-buffer "*mm*"))
272                 (setq method nil))
273             (mm-insert-part handle)
274             (let ((win (get-buffer-window cur t)))
275               (when win
276                 (select-window win)))
277             (switch-to-buffer (generate-new-buffer "*mm*")))
278           (buffer-disable-undo)
279           (mm-set-buffer-file-coding-system mm-binary-coding-system)
280           (insert-buffer-substring cur)
281           (message "Viewing with %s" method)
282           (let ((mm (current-buffer))
283                 (non-viewer (assoc "non-viewer"
284                                    (mailcap-mime-info
285                                     (car (mm-handle-type handle)) t))))
286             (unwind-protect
287                 (if method
288                     (funcall method)
289                   (mm-save-part handle))
290               (when (and (not non-viewer)
291                          method)
292                 (mm-handle-set-undisplayer handle mm)))))
293       ;; The function is a string to be executed.
294       (mm-insert-part handle)
295       (let* ((dir (make-temp-name (expand-file-name "emm." mm-tmp-directory)))
296              (filename (mail-content-type-get
297                         (mm-handle-disposition handle) 'filename))
298              (needsterm (assoc "needsterm"
299                                (mailcap-mime-info
300                                 (car (mm-handle-type handle)) t)))
301              process file buffer)
302         ;; We create a private sub-directory where we store our files.
303         (make-directory dir)
304         (set-file-modes dir 448)
305         (if filename
306             (setq file (expand-file-name (file-name-nondirectory filename)
307                                          dir))
308           (setq file (make-temp-name (expand-file-name "mm." dir))))
309         (write-region (point-min) (point-max) file nil 'nomesg)
310         (message "Viewing with %s" method)
311         (unwind-protect
312             (setq process
313                   (if needsterm
314                       (start-process "*display*" nil
315                                      "xterm"
316                                      "-e" shell-file-name "-c"
317                                      (format method
318                                              (mm-quote-arg file)))
319                     (start-process "*display*"
320                                    (setq buffer (generate-new-buffer "*mm*"))
321                                    shell-file-name
322                                    "-c" (format method
323                                                 (mm-quote-arg file)))))
324           (mm-handle-set-undisplayer handle (cons file buffer)))
325         (message "Displaying %s..." (format method file))))))
326
327 (defun mm-remove-parts (handles)
328   "Remove the displayed MIME parts represented by HANDLE."
329   (if (and (listp handles)
330            (bufferp (car handles)))
331       (mm-remove-part handles)
332     (let (handle)
333       (while (setq handle (pop handles))
334         (cond
335          ((stringp handle)
336           )
337          ((and (listp handle)
338                (stringp (car handle)))
339           (mm-remove-parts (cdr handle)))
340          (t
341           (mm-remove-part handle)))))))
342
343 (defun mm-destroy-parts (handles)
344   "Remove the displayed MIME parts represented by HANDLE."
345   (if (and (listp handles)
346            (bufferp (car handles)))
347       (mm-destroy-part handles)
348     (let (handle)
349       (while (setq handle (pop handles))
350         (cond
351          ((stringp handle)
352           )
353          ((and (listp handle)
354                (stringp (car handle)))
355           (mm-destroy-parts (cdr handle)))
356          (t
357           (mm-destroy-part handle)))))))
358
359 (defun mm-remove-part (handle)
360   "Remove the displayed MIME part represented by HANDLE."
361   (when (listp handle)
362     (let ((object (mm-handle-undisplayer handle)))
363       (ignore-errors
364         (cond
365          ;; Internally displayed part.
366          ((mm-annotationp object)
367           (delete-annotation object))
368          ((or (functionp object)
369               (and (listp object)
370                    (eq (car object) 'lambda)))
371           (funcall object))
372          ;; Externally displayed part.
373          ((consp object)
374           (ignore-errors (delete-file (car object)))
375           (ignore-errors (delete-directory (file-name-directory (car object))))
376           (ignore-errors (kill-buffer (cdr object))))
377          ((bufferp object)
378           (when (buffer-live-p object)
379             (kill-buffer object)))))
380       (mm-handle-set-undisplayer handle nil))))
381
382 (defun mm-display-inline (handle)
383   (let* ((type (car (mm-handle-type handle)))
384          (function (cadr (assoc type mm-inline-media-tests))))
385     (funcall function handle)
386     (goto-char (point-min))))
387
388 (defun mm-inlinable-p (type)
389   "Say whether TYPE can be displayed inline."
390   (let ((alist mm-inline-media-tests)
391         test)
392     (while alist
393       (when (equal type (caar alist))
394         (setq test (caddar alist)
395               alist nil)
396         (setq test (eval test)))
397       (pop alist))
398     test))
399
400 (defun mm-user-method (type)
401   "Return the user-defined method for TYPE."
402   (let ((methods mm-user-display-methods)
403         method result)
404     (while (setq method (pop methods))
405       (when (string-match (car method) type)
406         (when (or (not (eq (cdr method) 'inline))
407                   (mm-inlinable-p type))
408           (setq result (cdr method)
409                 methods nil))))
410     result))
411
412 (defun mm-automatic-display-p (type)
413   "Return the user-defined method for TYPE."
414   (let ((methods mm-user-automatic-display)
415         method result)
416     (while (setq method (pop methods))
417       (when (and (string-match method type)
418                  (mm-inlinable-p type))
419         (setq result t
420               methods nil)))
421     result))
422
423 (defun mm-attachment-override-p (type)
424   "Say whether TYPE should have attachment behavior overridden."
425   (let ((types mm-attachment-override-types)
426         ty)
427     (catch 'found
428       (while (setq ty (pop types))
429         (when (and (string-match ty type)
430                    (mm-inlinable-p type))
431           (throw 'found t))))))
432
433 (defun mm-automatic-external-display-p (type)
434   "Return the user-defined method for TYPE."
435   (let ((methods mm-user-automatic-external-display)
436         method result)
437     (while (setq method (pop methods))
438       (when (string-match method type)
439         (setq result t
440               methods nil)))
441     result))
442
443 (defun add-mime-display-method (type method)
444   "Make parts of TYPE be displayed with METHOD.
445 This overrides entries in the mailcap file."
446   (push (cons type method) mm-user-display-methods))
447
448 (defun mm-destroy-part (handle)
449   "Destroy the data structures connected to HANDLE."
450   (when (listp handle)
451     (mm-remove-part handle)
452     (when (buffer-live-p (mm-handle-buffer handle))
453       (kill-buffer (mm-handle-buffer handle)))))
454
455 (defun mm-handle-displayed-p (handle)
456   "Say whether HANDLE is displayed or not."
457   (mm-handle-undisplayer handle))
458
459 ;;;
460 ;;; Functions for outputting parts
461 ;;;
462
463 (defun mm-get-part (handle)
464   "Return the contents of HANDLE as a string."
465   (mm-with-unibyte-buffer
466     (mm-insert-part handle)
467     (buffer-string)))
468
469 (defun mm-insert-part (handle)
470   "Insert the contents of HANDLE in the current buffer."
471   (let ((cur (current-buffer)))
472     (save-excursion
473       (if (member (car (split-string (car (mm-handle-type handle)) "/"))
474                   '("text" "message"))
475           (with-temp-buffer
476             (insert-buffer-substring (mm-handle-buffer handle))
477             (mm-decode-content-transfer-encoding
478              (mm-handle-encoding handle)
479              (car (mm-handle-type handle)))
480             (let ((temp (current-buffer)))
481               (set-buffer cur)
482               (insert-buffer-substring temp)))
483         (mm-with-unibyte-buffer
484           (insert-buffer-substring (mm-handle-buffer handle))
485           (mm-decode-content-transfer-encoding
486            (mm-handle-encoding handle)
487            (car (mm-handle-type handle)))
488           (let ((temp (current-buffer)))
489             (set-buffer cur)
490             (insert-buffer-substring temp)))))))
491
492 (defvar mm-default-directory nil)
493
494 (defun mm-save-part (handle)
495   "Write HANDLE to a file."
496   (let* ((name (mail-content-type-get (mm-handle-type handle) 'name))
497          (filename (mail-content-type-get
498                     (mm-handle-disposition handle) 'filename))
499          file)
500     (when filename
501       (setq filename (file-name-nondirectory filename)))
502     (setq file
503           (read-file-name "Save MIME part to: "
504                           (expand-file-name
505                            (or filename name "")
506                            (or mm-default-directory default-directory))))
507     (setq mm-default-directory (file-name-directory file))
508     (when (or (not (file-exists-p file))
509               (yes-or-no-p (format "File %s already exists; overwrite? "
510                                    file)))
511       (mm-save-part-to-file handle file))))
512
513 (defun mm-save-part-to-file (handle file)
514   (mm-with-unibyte-buffer
515     (mm-insert-part handle)
516     ;; Now every coding system is 100% binary within mm-with-unibyte-buffer
517     ;; Is text still special?
518     (let ((coding-system-for-write
519            (if (equal "text" (car (split-string
520                                    (car (mm-handle-type handle)) "/")))
521                buffer-file-coding-system
522              'binary))
523           ;; Don't re-compress .gz & al.  Arguably we should make
524           ;; `file-name-handler-alist' nil, but that would chop
525           ;; ange-ftp which it's reasonable to use here.
526           (inhibit-file-name-operation 'write-region)
527           (inhibit-file-name-handlers
528            (if (equal (car (mm-handle-type handle))
529                       "application/octet-stream")
530                (cons 'jka-compr-handler inhibit-file-name-handlers)
531              inhibit-file-name-handlers)))
532       (write-region (point-min) (point-max) file))))
533
534 (defun mm-pipe-part (handle)
535   "Pipe HANDLE to a process."
536   (let* ((name (mail-content-type-get (mm-handle-type handle) 'name))
537          (command
538           (read-string "Shell command on MIME part: " mm-last-shell-command)))
539     (mm-with-unibyte-buffer
540       (mm-insert-part handle)
541       (shell-command-on-region (point-min) (point-max) command nil))))
542
543 (defun mm-interactively-view-part (handle)
544   "Display HANDLE using METHOD."
545   (let* ((type (car (mm-handle-type handle)))
546          (methods
547           (mapcar (lambda (i) (list (cdr (assoc 'viewer i))))
548                   (mailcap-mime-info type 'all)))
549          (method (completing-read "Viewer: " methods)))
550     (mm-display-external (copy-sequence handle) method)))
551
552 (defun mm-preferred-alternative (handles &optional preferred)
553   "Say which of HANDLES are preferred."
554   (let ((prec (if preferred (list preferred)
555                 (mm-preferred-alternative-precedence handles)))
556         p h result type handle)
557     (while (setq p (pop prec))
558       (setq h handles)
559       (while h
560         (setq type
561               (if (stringp (caar h))
562                   (caar h)
563                 (car (mm-handle-type (car h)))))
564         (setq handle (car h))
565         (when (and (equal p type)
566                    (mm-automatic-display-p type)
567                    (or (stringp (caar h))
568                        (not (mm-handle-disposition (car h)))
569                        (equal (car (mm-handle-disposition (car h)))
570                               "inline")))
571           (setq result (car h)
572                 h nil
573                 prec nil))
574         (pop h)))
575     result))
576
577 (defun mm-preferred-alternative-precedence (handles)
578   "Return the precedence based on HANDLES and mm-discouraged-alternatives."
579   (let ((seq (nreverse (mapcar (lambda (h)
580                                  (car (mm-handle-type h))) handles))))
581     (dolist (disc (reverse mm-discouraged-alternatives))
582       (dolist (elem (copy-sequence seq))
583         (when (string-match disc elem)
584           (setq seq (nconc (delete elem seq) (list elem))))))
585     seq))
586
587 (defun mm-get-content-id (id)
588   "Return the handle(s) referred to by ID."
589   (cdr (assoc id mm-content-id-alist)))
590
591 (defun mm-get-image (handle)
592   "Return an image instance based on HANDLE."
593   (let ((type (cadr (split-string (car (mm-handle-type handle)) "/")))
594         spec)
595     ;; Allow some common translations.
596     (setq type
597           (cond
598            ((equal type "x-pixmap")
599             "xpm")
600            ((equal type "x-xbitmap")
601             "xbm")
602            (t type)))
603     (or (mm-handle-cache handle)
604         (mm-with-unibyte-buffer
605           (mm-insert-part handle)
606           (prog1
607               (setq spec
608                     (ignore-errors
609                       (cond
610                        ((equal type "xbm")
611                         ;; xbm images require special handling, since
612                         ;; the only way to create glyphs from these
613                         ;; (without a ton of work) is to write them
614                         ;; out to a file, and then create a file
615                         ;; specifier.
616                         (let ((file (make-temp-name
617                                      (expand-file-name "emm.xbm"
618                                                        mm-tmp-directory))))
619                           (unwind-protect
620                               (progn
621                                 (write-region (point-min) (point-max) file)
622                                 (make-glyph (list (cons 'x file))))
623                             (ignore-errors
624                               (delete-file file)))))
625                        (t
626                         (make-glyph
627                          (vector (intern type) :data (buffer-string)))))))
628             (mm-handle-set-cache handle spec))))))
629
630 (defun mm-image-fit-p (handle)
631   "Say whether the image in HANDLE will fit the current window."
632   (let ((image (mm-get-image handle)))
633     (or mm-all-images-fit
634         (and (< (glyph-width image) (window-pixel-width))
635              (< (glyph-height image) (window-pixel-height))))))
636
637 (defun mm-valid-image-format-p (format)
638   "Say whether FORMAT can be displayed natively by Emacs."
639   (and (fboundp 'valid-image-instantiator-format-p)
640        (valid-image-instantiator-format-p format)))
641
642 (defun mm-valid-and-fit-image-p (format handle)
643   "Say whether FORMAT can be displayed natively and HANDLE fits the window."
644   (and window-system
645        (mm-valid-image-format-p format)
646        (mm-image-fit-p handle)))
647
648 (provide 'mm-decode)
649
650 ;; mm-decode.el ends here