1 ;;; mm-decode.el --- Functions for decoding MIME things
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
32 (eval-when-compile (require 'cl)
36 (autoload 'mm-inline-partial "mm-partial")
37 (autoload 'mm-inline-external-body "mm-extern")
38 (autoload 'mm-insert-inline "mm-view"))
40 (defvar gnus-current-window-configuration)
42 (add-hook 'gnus-exit-gnus-hook 'mm-destroy-postponed-undisplay-list)
44 (defgroup mime-display ()
45 "Display of MIME in mail and news articles."
46 :link '(custom-manual "(emacs-mime)Display Customization")
52 (defgroup mime-security ()
53 "MIME security in mail and news articles."
54 :link '(custom-manual "(emacs-mime)Display Customization")
59 ;;; Convenience macros.
61 (defmacro mm-handle-buffer (handle)
63 (defmacro mm-handle-type (handle)
65 (defsubst mm-handle-media-type (handle)
66 (if (stringp (car handle))
68 (car (mm-handle-type handle))))
69 (defsubst mm-handle-media-supertype (handle)
70 (car (split-string (mm-handle-media-type handle) "/")))
71 (defsubst mm-handle-media-subtype (handle)
72 (cadr (split-string (mm-handle-media-type handle) "/")))
73 (defmacro mm-handle-encoding (handle)
75 (defmacro mm-handle-undisplayer (handle)
77 (defmacro mm-handle-set-undisplayer (handle function)
78 `(setcar (nthcdr 3 ,handle) ,function))
79 (defmacro mm-handle-disposition (handle)
81 (defmacro mm-handle-description (handle)
83 (defmacro mm-handle-cache (handle)
85 (defmacro mm-handle-set-cache (handle contents)
86 `(setcar (nthcdr 6 ,handle) ,contents))
87 (defmacro mm-handle-id (handle)
89 (defmacro mm-handle-multipart-original-buffer (handle)
90 `(get-text-property 0 'buffer (car ,handle)))
91 (defmacro mm-handle-multipart-from (handle)
92 `(get-text-property 0 'from (car ,handle)))
93 (defmacro mm-handle-multipart-ctl-parameter (handle parameter)
94 `(get-text-property 0 ,parameter (car ,handle)))
96 (defmacro mm-make-handle (&optional buffer type encoding undisplayer
97 disposition description cache
99 `(list ,buffer ,type ,encoding ,undisplayer
100 ,disposition ,description ,cache ,id))
102 (defcustom mm-text-html-renderer
103 (cond ((locate-library "w3") 'w3)
104 ((executable-find "w3m") (if (locate-library "w3m")
107 ((executable-find "links") 'links)
108 ((executable-find "lynx") 'lynx)
110 "Render of HTML contents.
111 It is one of defined renderer types, or a rendering function.
112 The defined renderer types are:
114 `w3m' : use emacs-w3m;
115 `w3m-standalone': use w3m;
118 `html2text' : use html2text;
119 nil : use external viewer."
121 :type '(choice (const w3)
123 (const w3m-standalone)
129 :group 'mime-display)
131 (defvar mm-inline-text-html-renderer nil
132 "Function used for rendering inline HTML contents.
133 It is suggested to customize `mm-text-html-renderer' instead.")
135 (defcustom mm-inline-text-html-with-images nil
136 "If non-nil, Gnus will allow retrieving images in HTML contents with
137 the <img> tags. It has no effect on Emacs/w3. See also the
138 documentation for the `mm-w3m-safe-url-regexp' variable."
141 :group 'mime-display)
143 (defcustom mm-w3m-safe-url-regexp "\\`cid:"
144 "Regexp matching URLs which are considered to be safe.
145 Some HTML mails might contain a nasty trick used by spammers, using
146 the <img> tag which is far more evil than the [Click Here!] button.
147 It is most likely intended to check whether the ominous spam mail has
148 reached your eyes or not, in which case the spammer knows for sure
149 that your email address is valid. It is done by embedding an
150 identifier string into a URL that you might automatically retrieve
151 when displaying the image. The default value is \"\\\\`cid:\" which only
152 matches parts embedded to the Multipart/Related type MIME contents and
153 Gnus will never connect to the spammer's site arbitrarily. You may
154 set this variable to nil if you consider all urls to be safe."
156 :type '(choice (regexp :tag "Regexp")
157 (const :tag "All URLs are safe" nil))
158 :group 'mime-display)
160 (defcustom mm-inline-text-html-with-w3m-keymap t
161 "If non-nil, use emacs-w3m command keys in the article buffer."
164 :group 'mime-display)
166 (defcustom mm-enable-external t
167 "Indicate whether external MIME handlers should be used.
169 If t, all defined external MIME handlers are used. If nil, files are saved by
170 `mailcap-save-binary-file'. If it is the symbol `ask', you are prompted
171 before the external MIME handler is invoked."
173 :type '(choice (const :tag "Always" t)
174 (const :tag "Never" nil)
175 (const :tag "Ask" ask))
176 :group 'mime-display)
178 (defcustom mm-inline-media-tests
182 (mm-valid-and-fit-image-p 'jpeg handle)))
186 (mm-valid-and-fit-image-p 'png handle)))
190 (mm-valid-and-fit-image-p 'gif handle)))
194 (mm-valid-and-fit-image-p 'tiff handle)) )
198 (mm-valid-and-fit-image-p 'xbm handle)))
202 (mm-valid-and-fit-image-p 'xbm handle)))
206 (mm-valid-and-fit-image-p 'xpm handle)))
210 (mm-valid-and-fit-image-p 'xpm handle)))
214 (mm-valid-and-fit-image-p 'bmp handle)))
215 ("image/x-portable-bitmap"
218 (mm-valid-and-fit-image-p 'pbm handle)))
219 ("text/plain" mm-inline-text identity)
220 ("text/enriched" mm-inline-text identity)
221 ("text/richtext" mm-inline-text identity)
222 ("text/x-patch" mm-display-patch-inline
224 (locate-library "diff-mode")))
225 ("application/emacs-lisp" mm-display-elisp-inline identity)
226 ("application/x-emacs-lisp" mm-display-elisp-inline identity)
227 ("text/dns" mm-display-dns-inline identity)
231 (or mm-inline-text-html-renderer
232 mm-text-html-renderer)))
236 (or (featurep 'vcard)
237 (locate-library "vcard"))))
238 ("message/delivery-status" mm-inline-text identity)
239 ("message/rfc822" mm-inline-message identity)
240 ("message/partial" mm-inline-partial identity)
241 ("message/external-body" mm-inline-external-body identity)
242 ("text/.*" mm-inline-text identity)
243 ("audio/wav" mm-inline-audio
245 (and (or (featurep 'nas-sound) (featurep 'native-sound))
246 (device-sound-enabled-p))))
250 (and (or (featurep 'nas-sound) (featurep 'native-sound))
251 (device-sound-enabled-p))))
252 ("application/pgp-signature" ignore identity)
253 ("application/x-pkcs7-signature" ignore identity)
254 ("application/pkcs7-signature" ignore identity)
255 ("application/x-pkcs7-mime" ignore identity)
256 ("application/pkcs7-mime" ignore identity)
257 ("multipart/alternative" ignore identity)
258 ("multipart/mixed" ignore identity)
259 ("multipart/related" ignore identity)
260 ;; Disable audio and image
261 ("audio/.*" ignore ignore)
262 ("image/.*" ignore ignore)
263 ;; Default to displaying as text
264 (".*" mm-inline-text mm-readable-p))
265 "Alist of media types/tests saying whether types can be displayed inline."
266 :type '(repeat (list (regexp :tag "MIME type")
267 (function :tag "Display function")
268 (function :tag "Display test")))
269 :group 'mime-display)
271 (defcustom mm-inlined-types
272 '("image/.*" "text/.*" "message/delivery-status" "message/rfc822"
273 "message/partial" "message/external-body" "application/emacs-lisp"
274 "application/x-emacs-lisp"
275 "application/pgp-signature" "application/x-pkcs7-signature"
276 "application/pkcs7-signature" "application/x-pkcs7-mime"
277 "application/pkcs7-mime")
278 "List of media types that are to be displayed inline.
279 See also `mm-inline-media-tests', which says how to display a media
281 :type '(repeat string)
282 :group 'mime-display)
284 (defcustom mm-keep-viewer-alive-types
285 '("application/postscript" "application/msword" "application/vnd.ms-excel"
286 "application/pdf" "application/x-dvi")
287 "List of media types for which the external viewer will not be killed
288 when selecting a different article."
290 :type '(repeat string)
291 :group 'mime-display)
293 (defcustom mm-automatic-display
294 '("text/plain" "text/enriched" "text/richtext" "text/html"
295 "text/x-gnus-verbatim"
296 "text/x-vcard" "image/.*" "message/delivery-status" "multipart/.*"
297 "message/rfc822" "text/x-patch" "text/dns" "application/pgp-signature"
298 "application/emacs-lisp" "application/x-emacs-lisp"
299 "application/x-pkcs7-signature"
300 "application/pkcs7-signature" "application/x-pkcs7-mime"
301 "application/pkcs7-mime")
302 "A list of MIME types to be displayed automatically."
303 :type '(repeat string)
304 :group 'mime-display)