1 ;;; mailcap.el --- MIME media types configuration
3 ;; Copyright (C) 1998-2011 Free Software Foundation, Inc.
5 ;; Author: William M. Perry <wmperry@aventail.com>
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news, mail, multimedia
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; Provides configuration of MIME media types from directly from Lisp
27 ;; and via the usual mailcap mechanism (RFC 1524). Deals with
28 ;; mime.types similarly.
32 (eval-when-compile (require 'cl))
33 (autoload 'mail-header-parse-content-type "mail-parse")
35 ;; `mm-delete-duplicates' is an alias for `delete-dups' in Emacs 22.
36 (defalias 'mailcap-delete-duplicates
37 (if (fboundp 'delete-dups)
39 (autoload 'mm-delete-duplicates "mm-util")
40 'mm-delete-duplicates))
42 ;; `mailcap-replace-in-string' is an alias like `gnus-replace-in-string'.
45 ((fboundp 'replace-regexp-in-string)
46 (defun mailcap-replace-in-string (string regexp newtext &optional literal)
47 "Replace all matches for REGEXP with NEWTEXT in STRING.
48 If LITERAL is non-nil, insert NEWTEXT literally. Return a new
49 string containing the replacements.
50 This is a compatibility function for different Emacsen."
51 (replace-regexp-in-string regexp newtext string nil literal)))
52 ((fboundp 'replace-in-string)
53 (defalias 'mailcap-replace-in-string 'replace-in-string))))
56 "Definition of viewers for MIME types."
60 (defvar mailcap-parse-args-syntax-table
61 (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
62 (modify-syntax-entry ?' "\"" table)
63 (modify-syntax-entry ?` "\"" table)
64 (modify-syntax-entry ?{ "(" table)
65 (modify-syntax-entry ?} ")" table)
67 "A syntax table for parsing SGML attributes.")
70 (when (featurep 'xemacs)
75 (defvar mailcap-print-command
77 (cons (if (boundp 'lpr-command)
80 (when (boundp 'lpr-switches)
81 (if (stringp lpr-switches)
85 "Shell command (including switches) used to print Postscript files.")
87 ;; Postpone using defcustom for this as it's so big and we essentially
88 ;; have to have two copies of the data around then. Perhaps just
89 ;; customize the Lisp viewers and rely on the normal configuration
90 ;; files for the rest? -- fx
91 (defvar mailcap-mime-data
94 (viewer . "gnumeric %s")
95 (test . (getenv "DISPLAY"))
96 (type . "application/vnd.ms-excel"))
98 (viewer . ssl-view-site-cert)
99 (test . (fboundp 'ssl-view-site-cert))
100 (type . "application/x-x509-ca-cert"))
102 (viewer . ssl-view-user-cert)
103 (test . (fboundp 'ssl-view-user-cert))
104 (type . "application/x-x509-user-cert"))
106 (viewer . mailcap-save-binary-file)
108 (type . "application/octet-stream"))
110 (viewer . "xdvi -safer %s")
111 (test . (eq window-system 'x))
113 (type . "application/dvi")
114 ("print" . "dvips -qRP %s"))
116 (viewer . "dvitty %s")
117 (test . (not (getenv "DISPLAY")))
118 (type . "application/dvi")
119 ("print" . "dvips -qRP %s"))
121 (viewer . mailcap-maybe-eval)
122 (type . "application/emacs-lisp"))
124 (viewer . mailcap-maybe-eval)
125 (type . "application/x-emacs-lisp"))
127 (viewer . mailcap-save-binary-file)
129 (type . "application/x-tar"))
132 (test . (fboundp 'tex-mode))
133 (type . "application/x-latex"))
136 (test . (fboundp 'tex-mode))
137 (type . "application/x-tex"))
140 (test . (fboundp 'tex-mode))
141 (type . "application/latex"))
144 (test . (fboundp 'tex-mode))
145 (type . "application/tex"))
147 (viewer . texinfo-mode)
148 (test . (fboundp 'texinfo-mode))
149 (type . "application/tex"))
151 (viewer . mailcap-save-binary-file)
153 (type . "application/zip")
156 (viewer . "gv -safer %s")
157 (type . "application/pdf")
158 (test . window-system)
159 ("print" . ,(concat "pdf2ps %s - | " mailcap-print-command)))
162 (type . "application/pdf")
163 ("print" . ,(concat "pdftops %s - | " mailcap-print-command))
164 (test . (eq window-system 'x)))
167 (type . "application/pdf")
168 ("print" . ,(concat "pdftops %s - | " mailcap-print-command))
169 (test . (eq window-system 'x)))
171 (viewer . ,(concat "pdftotext %s -"))
172 (type . "application/pdf")
173 ("print" . ,(concat "pdftops %s - | " mailcap-print-command))
176 (viewer . "gv -safer %s")
177 (type . "application/postscript")
178 (test . window-system)
179 ("print" . ,(concat mailcap-print-command " %s"))
182 (viewer . "ghostview -dSAFER %s")
183 (type . "application/postscript")
184 (test . (eq window-system 'x))
185 ("print" . ,(concat mailcap-print-command " %s"))
188 (viewer . "ps2ascii %s")
189 (type . "application/postscript")
190 (test . (not (getenv "DISPLAY")))
191 ("print" . ,(concat mailcap-print-command " %s"))
194 (viewer . sieve-mode)
195 (test . (fboundp 'sieve-mode))
196 (type . "application/sieve"))
198 (viewer . "gpg --import --interactive --verbose")
199 (type . "application/pgp-keys")
203 (viewer . "maplay %s")
204 (type . "audio/x-mpeg"))
206 (viewer . "showaudio")