1 ;;; mailcap.el --- MIME media types configuration
3 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: William M. Perry <wmperry@aventail.com>
7 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; Keywords: news, mail, multimedia
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; Provides configuration of MIME media types from directly from Lisp
28 ;; and via the usual mailcap mechanism (RFC 1524). Deals with
29 ;; mime.types similarly.
33 (eval-when-compile (require 'cl))
34 (autoload 'mail-header-parse-content-type "mail-parse")
36 ;; `mm-delete-duplicates' is an alias for `delete-dups' in Emacs 22.
37 (defalias 'mailcap-delete-duplicates
38 (if (fboundp 'delete-dups)
40 (autoload 'mm-delete-duplicates "mm-util")
41 'mm-delete-duplicates))
43 ;; `mailcap-replace-in-string' is an alias like `gnus-replace-in-string'.
46 ((fboundp 'replace-regexp-in-string)
47 (defun mailcap-replace-in-string (string regexp newtext &optional literal)
48 "Replace all matches for REGEXP with NEWTEXT in STRING.
49 If LITERAL is non-nil, insert NEWTEXT literally. Return a new
50 string containing the replacements.
51 This is a compatibility function for different Emacsen."
52 (replace-regexp-in-string regexp newtext string nil literal)))
53 ((fboundp 'replace-in-string)
54 (defalias 'mailcap-replace-in-string 'replace-in-string))))
57 "Definition of viewers for MIME types."
61 (defvar mailcap-parse-args-syntax-table
62 (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
63 (modify-syntax-entry ?' "\"" table)
64 (modify-syntax-entry ?` "\"" table)
65 (modify-syntax-entry ?{ "(" table)
66 (modify-syntax-entry ?} ")" table)
68 "A syntax table for parsing SGML attributes.")
71 (when (featurep 'xemacs)
76 (defvar mailcap-print-command
78 (cons (if (boundp 'lpr-command)
81 (when (boundp 'lpr-switches)
82 (if (stringp lpr-switches)
86 "Shell command (including switches) used to print Postscript files.")
88 ;; Postpone using defcustom for this as it's so big and we essentially
89 ;; have to have two copies of the data around then. Perhaps just
90 ;; customize the Lisp viewers and rely on the normal configuration
91 ;; files for the rest? -- fx
92 (defvar mailcap-mime-data
95 (viewer . "gnumeric %s")
96 (test . (getenv "DISPLAY"))
97 (type . "application/vnd.ms-excel"))
99 (viewer . ssl-view-site-cert)
100 (test . (fboundp 'ssl-view-site-cert))
101 (type . "application/x-x509-ca-cert"))
103 (viewer . ssl-view-user-cert)
104 (test . (fboundp 'ssl-view-user-cert))
105 (type . "application/x-x509-user-cert"))
107 (viewer . mailcap-save-binary-file)
109 (type . "application/octet-stream"))
111 (viewer . "xdvi -safer %s")
112 (test . (eq window-system 'x))
114 (type . "application/dvi")
115 ("print" . "dvips -qRP %s"))
117 (viewer . "dvitty %s")
118 (test . (not (getenv "DISPLAY")))
119 (type . "application/dvi")
120 ("print" . "dvips -qRP %s"))
122 (viewer . mailcap-maybe-eval)
123 (type . "application/emacs-lisp"))
125 (viewer . mailcap-maybe-eval)
126 (type . "application/x-emacs-lisp"))
128 (viewer . mailcap-save-binary-file)
130 (type . "application/x-tar"))
133 (test . (fboundp 'tex-mode))
134 (type . "application/x-latex"))
137 (test . (fboundp 'tex-mode))
138 (type . "application/x-tex"))
141 (test . (fboundp 'tex-mode))
142 (type . "application/latex"))
145 (test . (fboundp 'tex-mode))
146 (type . "application/tex"))
148 (viewer . texinfo-mode)
149 (test . (fboundp 'texinfo-mode))
150 (type . "application/tex"))
152 (viewer . mailcap-save-binary-file)
154 (type . "application/zip")
157 (viewer . "gv -safer %s")
158 (type . "application/pdf")
159 (test . window-system)
160 ("print" . ,(concat "pdf2ps %s - | " mailcap-print-command)))
163 (type . "application/pdf")
164 ("print" . ,(concat "pdftops %s - | " mailcap-print-command))
165 (test . (eq window-system 'x)))
168 (type . "application/pdf")
169 ("print" . ,(concat "pdftops %s - | " mailcap-print-command))
170 (test . (eq window-system 'x)))
172 (viewer . ,(concat "pdftotext %s -"))
173 (type . "application/pdf")
174 ("print" . ,(concat "pdftops %s - | " mailcap-print-command))
177 (viewer . "gv -safer %s")
178 (type . "application/postscript")
179 (test . window-system)
180 ("print" . ,(concat mailcap-print-command " %s"))
183 (viewer . "ghostview -dSAFER %s")
184 (type . "application/postscript")
185 (test . (eq window-system 'x))
186 ("print" . ,(concat mailcap-print-command " %s"))
189 (viewer . "ps2ascii %s")
190 (type . "application/postscript")
191 (test . (not (getenv "DISPLAY")))
192 ("print" . ,(concat mailcap-print-command " %s"))
195 (viewer . sieve-mode)
196 (test . (fboundp 'sieve-mode))
197 (type . "application/sieve"))
199 (viewer . "gpg --import --interactive --verbose")
200 (type . "application/pgp-keys")
204 (viewer . "maplay %s")
205 (type . "audio/x-mpeg"))
207 (viewer . "showaudio")
211 (viewer . mm-view-message)
212 (test . (and (featurep 'gnus)
214 (type . "message/rfc822"))
217 (test . (fboundp 'vm-mode))
218 (type . "message/rfc822"))
221 (test . (fboundp 'w3-mode))
222 (type . "message/rfc822"))
225 (type . "message/rfc822")))
228 (viewer . "xwud -in %s")
229 (type . "image/x-xwd")
230 ("compose" . "xwd -frame > %s")
231 (test . (eq window-system 'x))
234 (viewer . "xwud -in %s")
235 (type . "image/x-xwd")
236 ("compose" . "xwd -frame > %s")
237 (test . (eq window-system 'x))
240 (viewer . "xwud -in %s")
241 (type . "image/x-xwd")
242 ("compose" . "xwd -frame > %s")
243 (test . (eq window-system 'x))
246 (viewer . "display %s")
248 (test . (eq window-system 'x))
253 (test . (eq window-system 'x))
258 (test . (fboundp 'w3-mode))
259 (type . "text/plain"))
262 (test . (fboundp 'view-mode))
263 (type . "text/plain"))
265 (viewer . fundamental-mode)
266 (type . "text/plain"))
268 (viewer . enriched-decode)
269 (test . (fboundp 'enriched-decode))
270 (type . "text/enriched"))
272 (viewer . mm-w3-prepare-buffer)
273 (test . (fboundp 'w3-prepare-buffer))
274 (type . "text/html"))
277 (test . (fboundp 'dns-mode))
278 (type . "text/dns")))
281 (viewer . "mpeg_play %s")
282 (type . "video/mpeg")
283 (test . (eq window-system 'x))
287 (viewer . "webspace -remote %s -URL %u")
288 (type . "x-world/x-vrml")
294 (type . "archive/tar")
295 (test . (fboundp 'tar-mode)))))
296 "The mailcap structure is an assoc list of assoc lists.
297 1st assoc list is keyed on the major content-type
298 2nd assoc list is keyed on the minor content-type (which can be a regexp)