Avoid using plusp; cl may not be loaded.
[gnus] / lisp / mm-decode.el
1 ;;; mm-decode.el --- Functions for decoding MIME things
2
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;;   2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5
6 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;;      MORIOKA Tomohiko <morioka@jaist.ac.jp>
8 ;; This file is part of GNU Emacs.
9
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 3 of the License, or
13 ;; (at your option) any later version.
14
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.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 ;; For Emacs < 22.2.
28 (eval-and-compile
29   (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
30
31 (require 'mail-parse)
32 (require 'mm-bodies)
33 (eval-when-compile (require 'cl)
34                    (require 'term))
35
36 (autoload 'gnus-map-function "gnus-util")
37 (autoload 'gnus-replace-in-string "gnus-util")
38 (autoload 'gnus-read-shell-command "gnus-util")
39
40 (autoload 'mm-inline-partial "mm-partial")
41 (autoload 'mm-inline-external-body "mm-extern")
42 (autoload 'mm-extern-cache-contents "mm-extern")
43 (autoload 'mm-insert-inline "mm-view")
44
45 (defvar gnus-current-window-configuration)
46
47 (add-hook 'gnus-exit-gnus-hook 'mm-destroy-postponed-undisplay-list)
48
49 (defgroup mime-display ()
50   "Display of MIME in mail and news articles."
51   :link '(custom-manual "(emacs-mime)Display Customization")
52   :version "21.1"
53   :group 'mail
54   :group 'news
55   :group 'multimedia)
56
57 (defgroup mime-security ()
58   "MIME security in mail and news articles."
59   :link '(custom-manual "(emacs-mime)Display Customization")
60   :group 'mail
61   :group 'news
62   :group 'multimedia)
63
64 ;;; Convenience macros.
65
66 (defmacro mm-handle-buffer (handle)
67   `(nth 0 ,handle))
68 (defmacro mm-handle-type (handle)
69   `(nth 1 ,handle))
70 (defsubst mm-handle-media-type (handle)
71   (if (stringp (car handle))
72       (car handle)
73     (car (mm-handle-type handle))))
74 (defsubst mm-handle-media-supertype (handle)
75   (car (split-string (mm-handle-media-type handle) "/")))
76 (defsubst mm-handle-media-subtype (handle)
77   (cadr (split-string (mm-handle-media-type handle) "/")))
78 (defmacro mm-handle-encoding (handle)
79   `(nth 2 ,handle))
80 (defmacro mm-handle-undisplayer (handle)
81   `(nth 3 ,handle))
82 (defmacro mm-handle-set-undisplayer (handle function)
83   `(setcar (nthcdr 3 ,handle) ,function))
84 (defmacro mm-handle-disposition (handle)
85   `(nth 4 ,handle))
86 (defmacro mm-handle-description (handle)
87   `(nth 5 ,handle))
88 (defmacro mm-handle-cache (handle)
89   `(nth 6 ,handle))
90 (defmacro mm-handle-set-cache (handle contents)
91   `(setcar (nthcdr 6 ,handle) ,contents))
92 (defmacro mm-handle-id (handle)
93   `(nth 7 ,handle))
94 (defmacro mm-handle-multipart-original-buffer (handle)
95   `(get-text-property 0 'buffer (car ,handle)))
96 (defmacro mm-handle-multipart-from (handle)
97   `(get-text-property 0 'from (car ,handle)))
98 (defmacro mm-handle-multipart-ctl-parameter (handle parameter)
99   `(get-text-property 0 ,parameter (car ,handle)))
100
101 (defmacro mm-make-handle (&optional buffer type encoding undisplayer
102                                     disposition description cache
103                                     id)
104   `(list ,buffer ,type ,encoding ,undisplayer
105          ,disposition ,description ,cache ,id))
106
107 (defcustom mm-text-html-renderer
108   (cond ((fboundp 'libxml-parse-html-region) 'mm-shr)
109         ((executable-find "w3m") 'gnus-article-html)
110         ((executable-find "links") 'links)
111         ((executable-find "lynx") 'lynx)
112         ((locate-library "w3") 'w3)
113         ((locate-library "html2text") 'html2text)
114         (t nil))
115   "Render of HTML contents.
116 It is one of defined renderer types, or a rendering function.
117 The defined renderer types are:
118 `gnus-article-html' : use Gnus renderer based on w3m;
119 `w3m'  : use emacs-w3m;
120 `w3m-standalone': use w3m;
121 `links': use links;
122 `lynx' : use lynx;
123 `w3'   : use Emacs/W3;
124 `html2text' : use html2text;
125 nil    : use external viewer (default web browser)."
126   :version "24.1"
127   :type '(choice (const gnus-article-html)
128                  (const w3)
129                  (const w3m :tag "emacs-w3m")
130                  (const w3m-standalone :tag "standalone w3m" )
131                  (const links)
132                  (const lynx)
133                  (const html2text)
134                  (const nil :tag "External viewer")
135                  (function))
136   :group 'mime-display)
137
138 (defvar mm-inline-text-html-renderer nil
139   "Function used for rendering inline HTML contents.
140 It is suggested to customize `mm-text-html-renderer' instead.")
141
142 (defcustom mm-inline-text-html-with-images nil
143   "If non-nil, Gnus will allow retrieving images in HTML contents with
144 the <img> tags.  It has no effect on Emacs/w3.  See also the
145 documentation for the `mm-w3m-safe-url-regexp' variable."
146   :version "22.1"
147   :type 'boolean
148   :group 'mime-display)
149
150 (defcustom mm-w3m-safe-url-regexp "\\`cid:"
151   "Regexp matching URLs which are considered to be safe.
152 Some HTML mails might contain a nasty trick used by spammers, using
153 the <img> tag which is far more evil than the [Click Here!] button.
154 It is most likely intended to check whether the ominous spam mail has
155 reached your eyes or not, in which case the spammer knows for sure
156 that your email address is valid.  It is done by embedding an
157 identifier string into a URL that you might automatically retrieve
158 when displaying the image.  The default value is \"\\\\`cid:\" which only
159 matches parts embedded to the Multipart/Related type MIME contents and
160 Gnus will never connect to the spammer's site arbitrarily.  You may
161 set this variable to nil if you consider all urls to be safe."
162   :version "22.1"
163   :type '(choice (regexp :tag "Regexp")
164                  (const :tag "All URLs are safe" nil))
165   :group 'mime-display)
166
167 (defcustom mm-inline-text-html-with-w3m-keymap t
168   "If non-nil, use emacs-w3m command keys in the article buffer."
169   :version "22.1"
170   :type 'boolean
171   :group 'mime-display)
172
173 (defcustom mm-enable-external t
174   "Indicate whether external MIME handlers should be used.
175
176 If t, all defined external MIME handlers are used.  If nil, files are saved by
177 `mailcap-save-binary-file'.  If it is the symbol `ask', you are prompted
178 before the external MIME handler is invoked."
179   :version "22.1"
180   :type '(choice (const :tag "Always" t)
181                  (const :tag "Never" nil)