1 ;;; mm-decode.el --- Functions for decoding MIME things
2 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; This file is part of GNU Emacs.
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)
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.
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.
30 (eval-when-compile (require 'cl)
34 (autoload 'executable-find "executable")
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)Customization")
49 (defgroup mime-security ()
50 "MIME security in mail and news articles."
51 :link '(custom-manual "(emacs-mime)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 ((locate-library "w3m") 'w3m)
102 ((executable-find "links") 'links)
103 ((executable-find "lynx") 'lynx)
105 "Render of HTML contents.
106 It is one of defined renderer types, or a rendering function.
107 The defined renderer types are:
108 `w3' : using Emacs/W3;
109 `w3m' : using emacs-w3m;
110 `links': using links;
112 `html2text' : using html2text;
113 `nil' : using external viewer."
114 :type '(choice (symbol w3)
122 :group 'mime-display)
124 (defvar mm-inline-text-html-renderer nil
125 "Function used for rendering inline HTML contents.
126 It is suggested to customize `mm-text-html-renderer' instead.")
128 (defcustom mm-inline-text-html-with-images nil
129 "If non-nil, Gnus will allow retrieving images in the HTML contents
130 with <img> tags. It has no effect on Emacs/w3. For emacs-w3m, the
131 value of the option `w3m-display-inline-images' will be bound with
132 this value. In addition, the variable `w3m-safe-url-regexp' will be
133 bound with the value nil if it is non-nil to make emacs-w3m show all
134 images, however this behavior may be changed in the future."
136 :group 'mime-display)
138 (defcustom mm-inline-text-html-with-w3m-keymap t
139 "If non-nil, use emacs-w3m command keys in the article buffer."
141 :group 'mime-display)
143 (defcustom mm-inline-media-tests
147 (mm-valid-and-fit-image-p 'jpeg handle)))
151 (mm-valid-and-fit-image-p 'png handle)))
155 (mm-valid-and-fit-image-p 'gif handle)))
159 (mm-valid-and-fit-image-p 'tiff handle)) )
163 (mm-valid-and-fit-image-p 'xbm handle)))
167 (mm-valid-and-fit-image-p 'xbm handle)))
171 (mm-valid-and-fit-image-p 'xpm handle)))
175 (mm-valid-and-fit-image-p 'xpm handle)))
179 (mm-valid-and-fit-image-p 'bmp handle)))
180 ("image/x-portable-bitmap"
183 (mm-valid-and-fit-image-p 'pbm handle)))
184 ("text/plain" mm-inline-text identity)
185 ("text/enriched" mm-inline-text identity)
186 ("text/richtext" mm-inline-text identity)
187 ("text/x-patch" mm-display-patch-inline