1 ;;; mm-decode.el --- Functions for decoding MIME things
2 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; This file is part of GNU Emacs.
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 2, or (at your option)
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.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
31 (eval-when-compile (require 'cl)
35 (autoload 'mm-inline-partial "mm-partial")
36 (autoload 'mm-inline-external-body "mm-extern")
37 (autoload 'mm-insert-inline "mm-view"))
39 (add-hook 'gnus-exit-gnus-hook 'mm-destroy-postponed-undisplay-list)
41 (defgroup mime-display ()
42 "Display of MIME in mail and news articles."
43 :link '(custom-manual "(emacs-mime)Display Customization")
49 (defgroup mime-security ()
50 "MIME security in mail and news articles."
51 :link '(custom-manual "(emacs-mime)Display Customization")
56 ;;; Convenience macros.
58 (defmacro mm-handle-buffer (handle)
60 (defmacro mm-handle-type (handle)
62 (defsubst mm-handle-media-type (handle)
63 (if (stringp (car handle))
65 (car (mm-handle-type handle))))
66 (defsubst mm-handle-media-supertype (handle)
67 (car (split-string (mm-handle-media-type handle) "/")))
68 (defsubst mm-handle-media-subtype (handle)
69 (cadr (split-string (mm-handle-media-type handle) "/")))
70 (defmacro mm-handle-encoding (handle)
72 (defmacro mm-handle-undisplayer (handle)
74 (defmacro mm-handle-set-undisplayer (handle function)
75 `(setcar (nthcdr 3 ,handle) ,function))
76 (defmacro mm-handle-disposition (handle)
78 (defmacro mm-handle-description (handle)
80 (defmacro mm-handle-cache (handle)
82 (defmacro mm-handle-set-cache (handle contents)
83 `(setcar (nthcdr 6 ,handle) ,contents))
84 (defmacro mm-handle-id (handle)
86 (defmacro mm-handle-multipart-original-buffer (handle)
87 `(get-text-property 0 'buffer (car ,handle)))
88 (defmacro mm-handle-multipart-from (handle)
89 `(get-text-property 0 'from (car ,handle)))
90 (defmacro mm-handle-multipart-ctl-parameter (handle parameter)
91 `(get-text-property 0 ,parameter (car ,handle)))
93 (defmacro mm-make-handle (&optional buffer type encoding undisplayer
94 disposition description cache
96 `(list ,buffer ,type ,encoding ,undisplayer
97 ,disposition ,description ,cache ,id))
99 (defcustom mm-text-html-renderer
100 (cond ((locate-library "w3") 'w3)
101 ((executable-find "w3m") (if (locate-library "w3m")
104 ((executable-find "links") 'links)
105 ((executable-find "lynx") 'lynx)
107 "Render of HTML contents.
108 It is one of defined renderer types, or a rendering function.
109 The defined renderer types are:
111 `w3m' : use emacs-w3m;
112 `w3m-standalone': use w3m;
115 `html2text' : use html2text;
116 nil : use external viewer."
117 :type '(choice (const w3)
119 (const w3m-standalone)
126 :group 'mime-display)
128 (defvar mm-inline-text-html-renderer nil
129 "Function used for rendering inline HTML contents.
130 It is suggested to customize `mm-text-html-renderer' instead.")
132 (defcustom mm-inline-text-html-with-images nil
133 "If non-nil, Gnus will allow retrieving images in HTML contents with
134 the <img> tags. It has no effect on Emacs/w3. See also the
135 documentation for the `mm-w3m-safe-url-regexp' variable."
137 :group 'mime-display)
139 (defcustom mm-w3m-safe-url-regexp "\\`cid:"
140 "Regexp matching URLs which are considered to be safe.
141 Some HTML mails might contain a nasty trick used by spammers, using
142 the <img> tag which is far more evil than the [Click Here!] button.
143 It is most likely intended to check whether the ominous spam mail has
144 reached your eyes or not, in which case the spammer knows for sure
145 that your email address is valid. It is done by embedding an
146 identifier string into a URL that you might automatically retrieve
147 when displaying the image. The default value is \"\\\\`cid:\" which only
148 matches parts embedded to the Multipart/Related type MIME contents and
149 Gnus will never connect to the spammer's site arbitrarily. You may
150 set this variable to nil if you consider all urls to be safe."
151 :type '(choice (regexp :tag "Regexp")
152 (const :tag "All URLs are safe" nil))
153 :group 'mime-display)
155 (defcustom mm-inline-text-html-with-w3m-keymap t
156 "If non-nil, use emacs-w3m command keys in the article buffer."
158 :group 'mime-display)
160 (defcustom mm-enable-external t
161 "Indicate whether external MIME handlers should be used.
163 If t, all defined external MIME handlers are used. If nil, files are saved by
164 `mailcap-save-binary-file'. If it is the symbol `ask', you are prompted
165 before the external MIME handler is invoked."
167 :type '(choice (const :tag "Always" t)
168 (const :tag "Never" nil)
169 (const :tag "Ask" ask))
170 :group 'mime-display)
172 (defcustom mm-inline-media-tests
176 (mm-valid-and-fit-image-p 'jpeg handle)))
180 (mm-valid-and-fit-image-p 'png handle)))
184 (mm-valid-and-fit-image-p 'gif handle)))
188 (mm-valid-and-fit-image-p 'tiff handle)) )
192 (mm-valid-and-fit-image-p 'xbm handle)))
196 (mm-valid-and-fit-image-p 'xbm handle)))
200 (mm-valid-and-fit-image-p 'xpm handle)))
204 (mm-valid-and-fit-image-p 'xpm handle)))
208 (mm-valid-and-fit-image-p 'bmp handle)))
209 ("image/x-portable-bitmap"
212 (mm-valid-and-fit-image-p 'pbm handle)))