Mercurial > emacs
annotate lisp/gnus/mailcap.el @ 62449:be9a675832ec
(cua-use-hyper-key): Doc fix.
(cua--init-keymaps): Bind C-return instead of S-return to set rectangle mark.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Tue, 17 May 2005 22:39:06 +0000 |
parents | 4e4ef6960726 |
children | 18a818a2ee7c 58db929d96c6 |
rev | line source |
---|---|
33821 | 1 ;;; mailcap.el --- MIME media types configuration |
57294
4e4ef6960726
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-589
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
2 ;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
3 ;; Free Software Foundation, Inc. |
31717 | 4 |
5 ;; Author: William M. Perry <wmperry@aventail.com> | |
6 ;; Lars Magne Ingebrigtsen <larsi@gnus.org> | |
33821 | 7 ;; Keywords: news, mail, multimedia |
31717 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
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 2, or (at your option) | |
14 ;; any later version. | |
15 | |
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. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
33821 | 28 ;; Provides configuration of MIME media types from directly from Lisp |
29 ;; and via the usual mailcap mechanism (RFC 1524). Deals with | |
30 ;; mime.types similarly. | |
31 | |
31717 | 32 ;;; Code: |
33 | |
34 (eval-when-compile (require 'cl)) | |
35 (require 'mail-parse) | |
36 (require 'mm-util) | |
37 | |
33821 | 38 (defgroup mailcap nil |
39 "Definition of viewers for MIME types." | |
40 :version "21.1" | |
41 :group 'mime) | |
42 | |
31717 | 43 (defvar mailcap-parse-args-syntax-table |
44 (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table))) | |
45 (modify-syntax-entry ?' "\"" table) | |
46 (modify-syntax-entry ?` "\"" table) | |
47 (modify-syntax-entry ?{ "(" table) | |
48 (modify-syntax-entry ?} ")" table) | |
49 table) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
50 "A syntax table for parsing SGML attributes.") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
51 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
52 (eval-and-compile |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
53 (when (featurep 'xemacs) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
54 (condition-case nil |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
55 (require 'lpr) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
56 (error nil)))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
57 |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
58 (defvar mailcap-print-command |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
59 (mapconcat 'identity |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
60 (cons (if (boundp 'lpr-command) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
61 lpr-command |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
62 "lpr") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
63 (when (boundp 'lpr-switches) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
64 (if (stringp lpr-switches) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
65 (list lpr-switches) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
66 lpr-switches))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
67 " ") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
68 "Shell command (including switches) used to print Postscript files.") |
31717 | 69 |
33821 | 70 ;; Postpone using defcustom for this as it's so big and we essentially |
71 ;; have to have two copies of the data around then. Perhaps just | |
72 ;; customize the Lisp viewers and rely on the normal configuration | |
73 ;; files for the rest? -- fx | |
31717 | 74 (defvar mailcap-mime-data |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
75 `(("application" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
76 ("vnd.ms-excel" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
77 (viewer . "gnumeric %s") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
78 (test . (getenv "DISPLAY")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
79 (type . "application/vnd.ms-excel")) |
31717 | 80 ("x-x509-ca-cert" |
81 (viewer . ssl-view-site-cert) | |
82 (test . (fboundp 'ssl-view-site-cert)) | |
83 (type . "application/x-x509-ca-cert")) | |
84 ("x-x509-user-cert" | |
85 (viewer . ssl-view-user-cert) | |
86 (test . (fboundp 'ssl-view-user-cert)) | |
87 (type . "application/x-x509-user-cert")) | |
88 ("octet-stream" | |
89 (viewer . mailcap-save-binary-file) | |
90 (non-viewer . t) | |
91 (type . "application/octet-stream")) | |
92 ("dvi" | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
93 (viewer . "xdvi -safer %s") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
94 (test . (eq window-system 'x)) |
31717 | 95 ("needsx11") |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
96 (type . "application/dvi") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
97 ("print" . "dvips -qRP %s")) |
31717 | 98 ("dvi" |
99 (viewer . "dvitty %s") | |
100 (test . (not (getenv "DISPLAY"))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
101 (type . "application/dvi") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
102 ("print" . "dvips -qRP %s")) |
31717 | 103 ("emacs-lisp" |
104 (viewer . mailcap-maybe-eval) | |
105 (type . "application/emacs-lisp")) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
106 ("x-emacs-lisp" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
107 (viewer . mailcap-maybe-eval) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
108 (type . "application/x-emacs-lisp")) |
31717 | 109 ("x-tar" |
110 (viewer . mailcap-save-binary-file) | |
111 (non-viewer . t) | |
112 (type . "application/x-tar")) | |
113 ("x-latex" | |
114 (viewer . tex-mode) | |
115 (test . (fboundp 'tex-mode)) | |
116 (type . "application/x-latex")) | |
117 ("x-tex" | |
118 (viewer . tex-mode) | |
119 (test . (fboundp 'tex-mode)) | |
120 (type . "application/x-tex")) | |
121 ("latex" | |
122 (viewer . tex-mode) | |
123 (test . (fboundp 'tex-mode)) | |
124 (type . "application/latex")) | |
125 ("tex" | |
126 (viewer . tex-mode) | |
127 (test . (fboundp 'tex-mode)) | |
128 (type . "application/tex")) | |
129 ("texinfo" | |
130 (viewer . texinfo-mode) | |
131 (test . (fboundp 'texinfo-mode)) | |
132 (type . "application/tex")) | |
133 ("zip" | |
134 (viewer . mailcap-save-binary-file) | |
135 (non-viewer . t) | |
136 (type . "application/zip") | |
137 ("copiousoutput")) | |
33821 | 138 ("pdf" |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
139 (viewer . "gv -safer %s") |
33821 | 140 (type . "application/pdf") |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
141 (test . window-system) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
142 ("print" . ,(concat "pdf2ps %s - | " mailcap-print-command))) |
33821 | 143 ("pdf" |
57294
4e4ef6960726
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-589
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
144 (viewer . "gpdf %s") |
33821 | 145 (type . "application/pdf") |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
146 ("print" . ,(concat "pdftops %s - | " mailcap-print-command)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
147 (test . (eq window-system 'x))) |
31717 | 148 ("pdf" |
57294
4e4ef6960726
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-589
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
149 (viewer . "xpdf %s") |
4e4ef6960726
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-589
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
150 (type . "application/pdf") |
4e4ef6960726
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-589
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
151 ("print" . ,(concat "pdftops %s - | " mailcap-print-command)) |
4e4ef6960726
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-589
Miles Bader <miles@gnu.org>
parents:
56927
diff
changeset
|
152 (test . (eq window-system 'x))) |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
153 ("pdf" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
154 (viewer . ,(concat "pdftotext %s -")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
155 (type . "application/pdf") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
156 ("print" . ,(concat "pdftops %s - | " mailcap-print-command)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
157 ("copiousoutput")) |
31717 | 158 ("postscript" |
33821 | 159 (viewer . "gv -safer %s") |
160 (type . "application/postscript") | |
161 (test . window-system) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
162 ("print" . ,(concat mailcap-print-command " %s")) |
33821 | 163 ("needsx11")) |
31717 | 164 ("postscript" |
165 (viewer . "ghostview -dSAFER %s") | |
166 (type . "application/postscript") | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
167 (test . (eq window-system 'x)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
168 ("print" . ,(concat mailcap-print-command " %s")) |
31717 | 169 ("needsx11")) |
170 ("postscript" | |
171 (viewer . "ps2ascii %s") | |
172 (type . "application/postscript") | |
173 (test . (not (getenv "DISPLAY"))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
174 ("print" . ,(concat mailcap-print-command " %s")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
175 ("copiousoutput")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
176 ("sieve" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
177 (viewer . sieve-mode) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
178 (test . (fboundp 'sieve-mode)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
179 (type . "application/sieve")) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
180 ("pgp-keys" |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
181 (viewer . "gpg --import --interactive --verbose") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
182 (type . "application/pgp-keys") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
183 ("needsterminal"))) |
31717 | 184 ("audio" |
185 ("x-mpeg" | |
186 (viewer . "maplay %s") | |
187 (type . "audio/x-mpeg")) | |
188 (".*" | |
189 (viewer . "showaudio") | |
190 (type . "audio/*"))) | |
191 ("message" | |
192 ("rfc-*822" | |
193 (viewer . mm-view-message) | |
194 (test . (and (featurep 'gnus) | |
195 (gnus-alive-p))) | |
196 (type . "message/rfc822")) | |
197 ("rfc-*822" | |
198 (viewer . vm-mode) | |
199 (test . (fboundp 'vm-mode)) | |
200 (type . "message/rfc822")) | |
201 ("rfc-*822" | |
202 (viewer . w3-mode) | |
203 (test . (fboundp 'w3-mode)) | |
204 (type . "message/rfc822")) | |
205 ("rfc-*822" | |
206 (viewer . view-mode) | |
207 (type . "message/rfc822"))) | |
208 ("image" | |
209 ("x-xwd" | |
210 (viewer . "xwud -in %s") | |
211 (type . "image/x-xwd") | |
212 ("compose" . "xwd -frame > %s") | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
213 (test . (eq window-system 'x)) |
31717 | 214 ("needsx11")) |
215 ("x11-dump" | |
216 (viewer . "xwud -in %s") | |
217 (type . "image/x-xwd") | |
218 ("compose" . "xwd -frame > %s") | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
219 (test . (eq window-system 'x)) |
31717 | 220 ("needsx11")) |
221 ("windowdump" | |
222 (viewer . "xwud -in %s") | |
223 (type . "image/x-xwd") | |
224 ("compose" . "xwd -frame > %s") | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
225 (test . (eq window-system 'x)) |
31717 | 226 ("needsx11")) |
227 (".*" | |
228 (viewer . "display %s") | |
229 (type . "image/*") | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
230 (test . (eq window-system 'x)) |
31717 | 231 ("needsx11")) |
232 (".*" | |
233 (viewer . "ee %s") | |
234 (type . "image/*") | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
235 (test . (eq window-system 'x)) |
31717 | 236 ("needsx11"))) |
237 ("text" | |
238 ("plain" | |
239 (viewer . w3-mode) | |
240 (test . (fboundp 'w3-mode)) | |
241 (type . "text/plain")) | |
242 ("plain" | |
243 (viewer . view-mode) | |
244 (test . (fboundp 'view-mode)) | |
245 (type . "text/plain")) | |
246 ("plain" | |
247 (viewer . fundamental-mode) | |
248 (type . "text/plain")) | |
249 ("enriched" | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
250 (viewer . enriched-decode) |
31717 | 251 (test . (fboundp 'enriched-decode)) |
252 (type . "text/enriched")) | |
253 ("html" | |
254 (viewer . mm-w3-prepare-buffer) | |
255 (test . (fboundp 'w3-prepare-buffer)) | |
256 (type . "text/html"))) | |
257 ("video" | |
258 ("mpeg" | |
259 (viewer . "mpeg_play %s") | |
260 (type . "video/mpeg") | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
261 (test . (eq window-system 'x)) |
31717 | 262 ("needsx11"))) |
263 ("x-world" | |
264 ("x-vrml" | |
265 (viewer . "webspace -remote %s -URL %u") | |
266 (type . "x-world/x-vrml") | |
267 ("description" | |
268 "VRML document"))) | |
269 ("archive" | |
270 ("tar" | |
271 (viewer . tar-mode) | |
272 (type . "archive/tar") | |
273 (test . (fboundp 'tar-mode))))) | |
274 "The mailcap structure is an assoc list of assoc lists. | |
275 1st assoc list is keyed on the major content-type | |
276 2nd assoc list is keyed on the minor content-type (which can be a regexp) | |
277 | |
278 Which looks like: | |
279 ----------------- | |
280 ((\"application\" | |
281 (\"postscript\" . <info>)) | |
282 (\"text\" | |
283 (\"plain\" . <info>))) | |
284 | |
285 Where <info> is another assoc list of the various information | |
33821 | 286 related to the mailcap RFC 1524. This is keyed on the lowercase |
31717 | 287 attribute name (viewer, test, etc). This looks like: |
33821 | 288 ((viewer . VIEWERINFO) |
289 (test . TESTINFO) | |
290 (xxxx . \"STRING\") | |
291 FLAG) | |
31717 | 292 |
33821 | 293 Where VIEWERINFO specifies how the content-type is viewed. Can be |
31717 | 294 a string, in which case it is run through a shell, with |
295 appropriate parameters, or a symbol, in which case the symbol is | |
33821 | 296 `funcall'ed, with the buffer as an argument. |
31717 | 297 |
33821 | 298 TESTINFO is a test for the viewer's applicability, or nil. If nil, it |
299 means the viewer is always valid. If it is a Lisp function, it is | |
300 called with a list of items from any extra fields from the | |
301 Content-Type header as argument to return a boolean value for the | |
302 validity. Otherwise, if it is a non-function Lisp symbol or list | |
303 whose car is a symbol, it is `eval'led to yield the validity. If it | |
304 is a string or list of strings, it represents a shell command to run | |
305 to return a true or false shell value for the validity.") | |
55046
59e11b0793cf
(mailcap-mime-data): Mark as risky.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
306 (put 'mailcap-mime-data 'risky-local-variable t) |
31717 | 307 |
33821 | 308 (defcustom mailcap-download-directory nil |
34330
8b1375dbcbc6
(mailcap-download-directory): Fix :type.
Dave Love <fx@gnu.org>
parents:
33821
diff
changeset
|
309 "*Directory to which `mailcap-save-binary-file' downloads files by default. |
42206 | 310 nil means your home directory." |
34330
8b1375dbcbc6
(mailcap-download-directory): Fix :type.
Dave Love <fx@gnu.org>
parents:
33821
diff
changeset
|
311 :type '(choice (const :tag "Home directory" nil) |
8b1375dbcbc6
(mailcap-download-directory): Fix :type.
Dave Love <fx@gnu.org>
parents:
33821
diff
changeset
|
312 directory) |
33821 | 313 :group 'mailcap) |
31717 | 314 |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
315 (defvar mailcap-poor-system-types |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
316 '(ms-dos ms-windows windows-nt win32 w32 mswindows) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
317 "Systems that don't have a Unix-like directory hierarchy.") |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
318 |
31717 | 319 ;;; |
320 ;;; Utility functions | |
321 ;;; | |
322 | |
323 (defun mailcap-save-binary-file () | |
324 (goto-char (point-min)) | |
325 (unwind-protect | |
326 (let ((file (read-file-name | |
327 "Filename to save as: " | |
328 (or mailcap-download-directory "~/"))) | |
329 (require-final-newline nil)) | |
330 (write-region (point-min) (point-max) file)) | |
331 (kill-buffer (current-buffer)))) | |
332 | |
333 (defvar mailcap-maybe-eval-warning | |
334 "*** WARNING *** | |
335 | |
33821 | 336 This MIME part contains untrusted and possibly harmful content. |
31717 | 337 If you evaluate the Emacs Lisp code contained in it, a lot of nasty |
338 things can happen. Please examine the code very carefully before you | |
339 instruct Emacs to evaluate it. You can browse the buffer containing | |
340 the code using \\[scroll-other-window]. | |
341 | |
342 If you are unsure what to do, please answer \"no\"." | |
343 "Text of warning message displayed by `mailcap-maybe-eval'. | |
344 Make sure that this text consists only of few text lines. Otherwise, | |
345 Gnus might fail to display all of it.") | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
42206
diff
changeset
|
346 |
31717 | 347 (defun mailcap-maybe-eval () |
33821 | 348 "Maybe evaluate a buffer of Emacs Lisp code." |
31717 | 349 (let ((lisp-buffer (current-buffer))) |
350 (goto-char (point-min)) | |
351 (when | |
352 (save-window-excursion | |
353 (delete-other-windows) | |
354 (let ((buffer (get-buffer-create (generate-new-buffer-name | |
355 "*Warning*")))) | |
356 (unwind-protect | |
357 (with-current-buffer buffer | |
33821 | 358 (insert (substitute-command-keys |
31717 | 359 mailcap-maybe-eval-warning)) |
360 (goto-char (point-min)) | |
361 (display-buffer buffer) | |
362 (yes-or-no-p "This is potentially dangerous emacs-lisp code, evaluate it? ")) | |
363 (kill-buffer buffer)))) | |
364 (eval-buffer (current-buffer))) | |
365 (when (buffer-live-p lisp-buffer) | |
366 (with-current-buffer lisp-buffer | |
367 (emacs-lisp-mode))))) | |
368 | |
369 | |
370 ;;; | |
371 ;;; The mailcap parser | |
372 ;;; | |
373 | |
374 (defun mailcap-replace-regexp (regexp to-string) | |
375 ;; Quiet replace-regexp. | |
376 (goto-char (point-min)) | |
377 (while (re-search-forward regexp nil t) | |
378 (replace-match to-string t nil))) | |
379 | |
380 (defvar mailcap-parsed-p nil) | |
381 | |
382 (defun mailcap-parse-mailcaps (&optional path force) | |
383 "Parse out all the mailcaps specified in a path string PATH. | |
384 Components of PATH are separated by the `path-separator' character | |
385 appropriate for this system. If FORCE, re-parse even if already | |
386 parsed. If PATH is omitted, use the value of environment variable | |
387 MAILCAPS if set; otherwise (on Unix) use the path from RFC 1524, plus | |
388 /usr/local/etc/mailcap." | |
389 (interactive (list nil t)) | |
390 (when (or (not mailcap-parsed-p) | |
391 force) | |
392 (cond | |
393 (path nil) | |
394 ((getenv "MAILCAPS") (setq path (getenv "MAILCAPS"))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
395 ((memq system-type mailcap-poor-system-types) |
31717 | 396 (setq path '("~/.mailcap" "~/mail.cap" "~/etc/mail.cap"))) |
397 (t (setq path | |
398 ;; This is per RFC 1524, specifically | |
399 ;; with /usr before /usr/local. | |
400 '("~/.mailcap" "/etc/mailcap" "/usr/etc/mailcap" | |
401 "/usr/local/etc/mailcap")))) | |
402 (let ((fnames (reverse | |
403 (if (stringp path) | |
32989
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
404 (delete "" (split-string path path-separator)) |
31717 | 405 path))) |
406 fname) | |
407 (while fnames | |
408 (setq fname (car fnames)) | |
409 (if (and (file-readable-p fname) | |
410 (file-regular-p fname)) | |
411 (mailcap-parse-mailcap fname)) | |
412 (setq fnames (cdr fnames)))) | |
413 (setq mailcap-parsed-p t))) | |
414 | |
415 (defun mailcap-parse-mailcap (fname) | |
33821 | 416 "Parse out the mailcap file specified by FNAME." |
31717 | 417 (let (major ; The major mime type (image/audio/etc) |
418 minor ; The minor mime type (gif, basic, etc) | |
419 save-pos ; Misc saved positions used in parsing | |
420 viewer ; How to view this mime type | |
421 info ; Misc info about this mime type | |
422 ) | |
423 (with-temp-buffer | |
424 (insert-file-contents fname) | |
425 (set-syntax-table mailcap-parse-args-syntax-table) | |
426 (mailcap-replace-regexp "#.*" "") ; Remove all comments | |
427 (mailcap-replace-regexp "\\\\[ \t]*\n" " ") ; And collapse spaces | |
428 (mailcap-replace-regexp "\n+" "\n") ; And blank lines | |
429 (goto-char (point-max)) | |
430 (skip-chars-backward " \t\n") | |
431 (delete-region (point) (point-max)) | |
432 (while (not (bobp)) | |
433 (skip-chars-backward " \t\n") | |
434 (beginning-of-line) | |
435 (setq save-pos (point) | |
436 info nil) | |
437 (skip-chars-forward "^/; \t\n") | |
438 (downcase-region save-pos (point)) | |
439 (setq major (buffer-substring save-pos (point))) | |
440 (skip-chars-forward " \t") | |
441 (setq minor "") | |
442 (when (eq (char-after) ?/) | |
443 (forward-char) | |
444 (skip-chars-forward " \t") | |
445 (setq save-pos (point)) | |
446 (skip-chars-forward "^; \t\n") | |
447 (downcase-region save-pos (point)) | |
448 (setq minor | |
449 (cond | |
450 ((eq ?* (or (char-after save-pos) 0)) ".*") | |
451 ((= (point) save-pos) ".*") | |
452 (t (regexp-quote (buffer-substring save-pos (point))))))) | |
453 (skip-chars-forward " \t") | |
454 ;;; Got the major/minor chunks, now for the viewers/etc | |
455 ;;; The first item _must_ be a viewer, according to the | |
33821 | 456 ;;; RFC for mailcap files (#1524) |
31717 | 457 (setq viewer "") |
33821 | 458 (when (eq (char-after) ?\;) |
31717 | 459 (forward-char) |
460 (skip-chars-forward " \t") | |
461 (setq save-pos (point)) | |
462 (skip-chars-forward "^;\n") | |
463 ;; skip \; | |
464 (while (eq (char-before) ?\\) | |
465 (backward-delete-char 1) | |
466 (forward-char) | |
467 (skip-chars-forward "^;\n")) | |
468 (if (eq (or (char-after save-pos) 0) ?') | |
469 (setq viewer (progn | |
470 (narrow-to-region (1+ save-pos) (point)) | |
471 (goto-char (point-min)) | |
472 (prog1 | |
473 (read (current-buffer)) | |
474 (goto-char (point-max)) | |
475 (widen)))) | |
476 (setq viewer (buffer-substring save-pos (point))))) | |
477 (setq save-pos (point)) | |
478 (end-of-line) | |
33821 | 479 (unless (equal viewer "") |
31717 | 480 (setq info (nconc (list (cons 'viewer viewer) |
481 (cons 'type (concat major "/" | |
482 (if (string= minor ".*") | |
483 "*" minor)))) | |
484 (mailcap-parse-mailcap-extras save-pos (point)))) | |
485 (mailcap-mailcap-entry-passes-test info) | |
486 (mailcap-add-mailcap-entry major minor info)) | |
487 (beginning-of-line))))) | |
488 | |
489 (defun mailcap-parse-mailcap-extras (st nd) | |
33821 | 490 "Grab all the extra stuff from a mailcap entry." |
31717 | 491 (let ( |
492 name ; From name= | |
493 value ; its value | |
494 results ; Assoc list of results | |
495 name-pos ; Start of XXXX= position | |
496 val-pos ; Start of value position | |
497 done ; Found end of \'d ;s? | |
498 ) | |
499 (save-restriction | |
500 (narrow-to-region st nd) | |
501 (goto-char (point-min)) | |
502 (skip-chars-forward " \n\t;") | |
503 (while (not (eobp)) | |
504 (setq done nil) | |
505 (setq name-pos (point)) | |
506 (skip-chars-forward "^ \n\t=;") | |
507 (downcase-region name-pos (point)) | |
508 (setq name (buffer-substring name-pos (point))) | |
509 (skip-chars-forward " \t\n") | |
510 (if (not (eq (char-after (point)) ?=)) ; There is no value | |
511 (setq value t) | |
512 (skip-chars-forward " \t\n=") | |
513 (setq val-pos (point)) | |
514 (if (memq (char-after val-pos) '(?\" ?')) | |
515 (progn | |
516 (setq val-pos (1+ val-pos)) | |
517 (condition-case nil | |
518 (progn | |
519 (forward-sexp 1) | |
520 (backward-char 1)) | |
521 (error (goto-char (point-max))))) | |
522 (while (not done) | |
523 (skip-chars-forward "^;") | |
524 (if (eq (char-after (1- (point))) ?\\ ) | |
525 (progn | |
526 (subst-char-in-region (1- (point)) (point) ?\\ ? ) | |
527 (skip-chars-forward ";")) | |
528 (setq done t)))) | |
529 (setq value (buffer-substring val-pos (point)))) | |
530 (setq results (cons (cons name value) results)) | |
531 (skip-chars-forward " \";\n\t")) | |
532 results))) | |
533 | |
534 (defun mailcap-mailcap-entry-passes-test (info) | |
33821 | 535 "Return non-nil iff mailcap entry INFO passes its test clause. |
536 Also return non-nil if no test clause is present." | |
537 (let ((test (assq 'test info)) ; The test clause | |
538 status) | |
31717 | 539 (setq status (and test (split-string (cdr test) " "))) |
540 (if (and (or (assoc "needsterm" info) | |
541 (assoc "needsterminal" info) | |
542 (assoc "needsx11" info)) | |
543 (not (getenv "DISPLAY"))) | |
544 (setq status nil) | |
545 (cond | |
546 ((and (equal (nth 0 status) "test") | |
547 (equal (nth 1 status) "-n") | |
548 (or (equal (nth 2 status) "$DISPLAY") | |
549 (equal (nth 2 status) "\"$DISPLAY\""))) | |
550 (setq status (if (getenv "DISPLAY") t nil))) | |
551 ((and (equal (nth 0 status) "test") | |
552 (equal (nth 1 status) "-z") | |
553 (or (equal (nth 2 status) "$DISPLAY") | |
554 (equal (nth 2 status) "\"$DISPLAY\""))) | |
555 (setq status (if (getenv "DISPLAY") nil t))) | |
556 (test nil) | |
557 (t nil))) | |
558 (and test (listp test) (setcdr test status)))) | |
559 | |
560 ;;; | |
561 ;;; The action routines. | |
562 ;;; | |
563 | |
564 (defun mailcap-possible-viewers (major minor) | |
33821 | 565 "Return a list of possible viewers from MAJOR for minor type MINOR." |
31717 | 566 (let ((exact '()) |
567 (wildcard '())) | |
568 (while major | |
569 (cond | |
570 ((equal (car (car major)) minor) | |
571 (setq exact (cons (cdr (car major)) exact))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
572 ((and minor (string-match (concat "^" (car (car major)) "$") minor)) |
31717 | 573 (setq wildcard (cons (cdr (car major)) wildcard)))) |
574 (setq major (cdr major))) | |
575 (nconc exact wildcard))) | |
576 | |
577 (defun mailcap-unescape-mime-test (test type-info) | |
578 (let (save-pos save-chr subst) | |
579 (cond | |
580 ((symbolp test) test) | |
581 ((and (listp test) (symbolp (car test))) test) | |
582 ((or (stringp test) | |
583 (and (listp test) (stringp (car test)) | |
584 (setq test (mapconcat 'identity test " ")))) | |
585 (with-temp-buffer | |
586 (insert test) | |
587 (goto-char (point-min)) | |
588 (while (not (eobp)) | |
589 (skip-chars-forward "^%") | |
590 (if (/= (- (point) | |
591 (progn (skip-chars-backward "\\\\") | |
592 (point))) | |
593 0) ; It is an escaped % | |
594 (progn | |
595 (delete-char 1) | |
596 (skip-chars-forward "%.")) | |
597 (setq save-pos (point)) | |
598 (skip-chars-forward "%") | |
599 (setq save-chr (char-after (point))) | |
33821 | 600 ;; Escapes: |
601 ;; %s: name of a file for the body data | |
602 ;; %t: content-type | |
603 ;; %{<parameter name}: value of parameter in mailcap entry | |
604 ;; %n: number of sub-parts for multipart content-type | |
605 ;; %F: a set of content-type/filename pairs for multiparts | |
31717 | 606 (cond |
607 ((null save-chr) nil) | |
608 ((= save-chr ?t) | |
609 (delete-region save-pos (progn (forward-char 1) (point))) | |
610 (insert (or (cdr (assq 'type type-info)) "\"\""))) | |
33821 | 611 ((memq save-chr '(?M ?n ?F)) |
31717 | 612 (delete-region save-pos (progn (forward-char 1) (point))) |
613 (insert "\"\"")) | |
614 ((= save-chr ?{) | |
615 (forward-char 1) | |
616 (skip-chars-forward "^}") | |
617 (downcase-region (+ 2 save-pos) (point)) | |
618 (setq subst (buffer-substring (+ 2 save-pos) (point))) | |
619 (delete-region save-pos (1+ (point))) | |
620 (insert (or (cdr (assoc subst type-info)) "\"\""))) | |
621 (t nil)))) | |
622 (buffer-string))) | |
33821 | 623 (t (error "Bad value to mailcap-unescape-mime-test: %s" test))))) |
31717 | 624 |
625 (defvar mailcap-viewer-test-cache nil) | |
626 | |
627 (defun mailcap-viewer-passes-test (viewer-info type-info) | |
33821 | 628 "Return non-nil iff viewer specified by VIEWER-INFO passes its test clause. |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
629 Also return non-nil if it has no test clause. TYPE-INFO is an argument |
33821 | 630 to supply to the test." |
31717 | 631 (let* ((test-info (assq 'test viewer-info)) |
632 (test (cdr test-info)) | |
633 (otest test) | |
634 (viewer (cdr (assoc 'viewer viewer-info))) | |
635 (default-directory (expand-file-name "~/")) | |
636 status parsed-test cache result) | |
637 (if (setq cache (assoc test mailcap-viewer-test-cache)) | |
638 (cadr cache) | |
639 (setq | |
640 result | |
641 (cond | |
642 ((not test-info) t) ; No test clause | |
643 ((not test) nil) ; Already failed test | |
644 ((eq test t) t) ; Already passed test | |
33821 | 645 ((functionp test) ; Lisp function as test |
31717 | 646 (funcall test type-info)) |
647 ((and (symbolp test) ; Lisp variable as test | |
648 (boundp test)) | |
649 (symbol-value test)) | |
650 ((and (listp test) ; List to be eval'd | |
651 (symbolp (car test))) | |
652 (eval test)) | |
653 (t | |
654 (setq test (mailcap-unescape-mime-test test type-info) | |
655 test (list shell-file-name nil nil nil | |
656 shell-command-switch test) | |
657 status (apply 'call-process test)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
658 (eq 0 status)))) |
31717 | 659 (push (list otest result) mailcap-viewer-test-cache) |
660 result))) | |
661 | |
662 (defun mailcap-add-mailcap-entry (major minor info) | |
663 (let ((old-major (assoc major mailcap-mime-data))) | |
664 (if (null old-major) ; New major area | |
665 (setq mailcap-mime-data | |
666 (cons (cons major (list (cons minor info))) | |
667 mailcap-mime-data)) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
668 (let ((cur-minor (assoc minor old-major))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
669 (cond |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
670 ((or (null cur-minor) ; New minor area, or |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
671 (assq 'test info)) ; Has a test, insert at beginning |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
672 (setcdr old-major (cons (cons minor info) (cdr old-major)))) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
673 ((and (not (assq 'test info)) ; No test info, replace completely |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
674 (not (assq 'test cur-minor)) |
31717 | 675 (equal (assq 'viewer info) ; Keep alternative viewer |
676 (assq 'viewer cur-minor))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
677 (setcdr cur-minor info)) |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
678 (t |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
679 (setcdr old-major (cons (cons minor info) (cdr old-major)))))) |
31717 | 680 ))) |
681 | |
682 (defun mailcap-add (type viewer &optional test) | |
683 "Add VIEWER as a handler for TYPE. | |
684 If TEST is not given, it defaults to t." | |
685 (let ((tl (split-string type "/"))) | |
686 (when (or (not (car tl)) | |
687 (not (cadr tl))) | |
688 (error "%s is not a valid MIME type" type)) | |
689 (mailcap-add-mailcap-entry | |
690 (car tl) (cadr tl) | |
691 `((viewer . ,viewer) | |
692 (test . ,(if test test t)) | |
693 (type . ,type))))) | |
694 | |
695 ;;; | |
696 ;;; The main whabbo | |
697 ;;; | |
698 | |
699 (defun mailcap-viewer-lessp (x y) | |
33821 | 700 "Return t iff viewer X is more desirable than viewer Y." |
31717 | 701 (let ((x-wild (string-match "[*?]" (or (cdr-safe (assq 'type x)) ""))) |
702 (y-wild (string-match "[*?]" (or (cdr-safe (assq 'type y)) ""))) | |
703 (x-lisp (not (stringp (or (cdr-safe (assq 'viewer x)) "")))) | |
704 (y-lisp (not (stringp (or (cdr-safe (assq 'viewer y)) ""))))) | |
705 (cond | |
706 ((and x-wild (not y-wild)) | |
707 nil) | |
708 ((and (not x-wild) y-wild) | |
709 t) | |
710 ((and (not y-lisp) x-lisp) | |
711 t) | |
712 (t nil)))) | |
713 | |
714 (defun mailcap-mime-info (string &optional request) | |
715 "Get the MIME viewer command for STRING, return nil if none found. | |
716 Expects a complete content-type header line as its argument. | |
717 | |
718 Second argument REQUEST specifies what information to return. If it is | |
719 nil or the empty string, the viewer (second field of the mailcap | |
720 entry) will be returned. If it is a string, then the mailcap field | |
721 corresponding to that string will be returned (print, description, | |
722 whatever). If a number, then all the information for this specific | |
723 viewer is returned. If `all', then all possible viewers for | |
724 this type is returned." | |
725 (let ( | |
726 major ; Major encoding (text, etc) | |
727 minor ; Minor encoding (html, etc) | |
728 info ; Other info | |
729 save-pos ; Misc. position during parse | |
730 major-info ; (assoc major mailcap-mime-data) | |
731 minor-info ; (assoc minor major-info) | |
732 test ; current test proc. | |
733 viewers ; Possible viewers | |
734 passed ; Viewers that passed the test | |
735 viewer ; The one and only viewer | |
736 ctl) | |
737 (save-excursion | |
738 (setq ctl (mail-header-parse-content-type (or string "text/plain"))) | |
739 (setq major (split-string (car ctl) "/")) | |
740 (setq minor (cadr major) | |
741 major (car major)) | |
742 (when (setq major-info (cdr (assoc major mailcap-mime-data))) | |
743 (when (setq viewers (mailcap-possible-viewers major-info minor)) | |
744 (setq info (mapcar (lambda (a) (cons (symbol-name (car a)) | |
745 (cdr a))) | |
746 (cdr ctl))) | |
747 (while viewers | |
748 (if (mailcap-viewer-passes-test (car viewers) info) | |
749 (setq passed (cons (car viewers) passed))) | |
750 (setq viewers (cdr viewers))) | |
751 (setq passed (sort passed 'mailcap-viewer-lessp)) | |
752 (setq viewer (car passed)))) | |
753 (when (and (stringp (cdr (assq 'viewer viewer))) | |
754 passed) | |
755 (setq viewer (car passed))) | |
756 (cond | |
757 ((and (null viewer) (not (equal major "default")) request) | |
758 (mailcap-mime-info "default" request)) | |
759 ((or (null request) (equal request "")) | |
760 (mailcap-unescape-mime-test (cdr (assq 'viewer viewer)) info)) | |
761 ((stringp request) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
762 (mailcap-unescape-mime-test |
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
763 (cdr-safe (assoc request viewer)) info)) |
31717 | 764 ((eq request 'all) |
765 passed) | |
766 (t | |
767 ;; MUST make a copy *sigh*, else we modify mailcap-mime-data | |
768 (setq viewer (copy-sequence viewer)) | |
769 (let ((view (assq 'viewer viewer)) | |
770 (test (assq 'test viewer))) | |
771 (if view (setcdr view (mailcap-unescape-mime-test (cdr view) info))) | |
772 (if test (setcdr test (mailcap-unescape-mime-test (cdr test) info)))) | |
773 viewer))))) | |
774 | |
775 ;;; | |
776 ;;; Experimental MIME-types parsing | |
777 ;;; | |
778 | |
779 (defvar mailcap-mime-extensions | |
33821 | 780 '(("" . "text/plain") |
781 (".abs" . "audio/x-mpeg") | |
782 (".aif" . "audio/aiff") | |
783 (".aifc" . "audio/aiff") | |
784 (".aiff" . "audio/aiff") | |
785 (".ano" . "application/x-annotator") | |
786 (".au" . "audio/ulaw") | |
787 (".avi" . "video/x-msvideo") | |
788 (".bcpio" . "application/x-bcpio") | |
789 (".bin" . "application/octet-stream") | |
790 (".cdf" . "application/x-netcdr") | |
791 (".cpio" . "application/x-cpio") | |
792 (".csh" . "application/x-csh") | |
793 (".css" . "text/css") | |
794 (".dvi" . "application/x-dvi") | |
795 (".diff" . "text/x-patch") | |
796 (".el" . "application/emacs-lisp") | |
797 (".eps" . "application/postscript") | |
798 (".etx" . "text/x-setext") | |
799 (".exe" . "application/octet-stream") | |
800 (".fax" . "image/x-fax") | |
801 (".gif" . "image/gif") | |
802 (".hdf" . "application/x-hdf") | |
803 (".hqx" . "application/mac-binhex40") | |
804 (".htm" . "text/html") | |
805 (".html" . "text/html") | |
806 (".icon" . "image/x-icon") | |
807 (".ief" . "image/ief") | |
808 (".jpg" . "image/jpeg") | |
809 (".macp" . "image/x-macpaint") | |
810 (".man" . "application/x-troff-man") | |
811 (".me" . "application/x-troff-me") | |
812 (".mif" . "application/mif") | |
813 (".mov" . "video/quicktime") | |
814 (".movie" . "video/x-sgi-movie") | |
815 (".mp2" . "audio/x-mpeg") | |
816 (".mp3" . "audio/x-mpeg") | |
817 (".mp2a" . "audio/x-mpeg2") | |
818 (".mpa" . "audio/x-mpeg") | |
819 (".mpa2" . "audio/x-mpeg2") | |
820 (".mpe" . "video/mpeg") | |
821 (".mpeg" . "video/mpeg") | |
822 (".mpega" . "audio/x-mpeg") | |
823 (".mpegv" . "video/mpeg") | |
824 (".mpg" . "video/mpeg") | |
825 (".mpv" . "video/mpeg") | |
826 (".ms" . "application/x-troff-ms") | |
827 (".nc" . "application/x-netcdf") | |
828 (".nc" . "application/x-netcdf") | |
829 (".oda" . "application/oda") | |
830 (".patch" . "text/x-patch") | |
831 (".pbm" . "image/x-portable-bitmap") | |
832 (".pdf" . "application/pdf") | |
833 (".pgm" . "image/portable-graymap") | |
834 (".pict" . "image/pict") | |
835 (".png" . "image/png") | |
836 (".pnm" . "image/x-portable-anymap") | |
837 (".ppm" . "image/portable-pixmap") | |
838 (".ps" . "application/postscript") | |
839 (".qt" . "video/quicktime") | |
840 (".ras" . "image/x-raster") | |
841 (".rgb" . "image/x-rgb") | |
842 (".rtf" . "application/rtf") | |
843 (".rtx" . "text/richtext") | |
844 (".sh" . "application/x-sh") | |
845 (".sit" . "application/x-stuffit") | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
846 (".siv" . "application/sieve") |
33821 | 847 (".snd" . "audio/basic") |
848 (".src" . "application/x-wais-source") | |
849 (".tar" . "archive/tar") | |
850 (".tcl" . "application/x-tcl") | |
851 (".tex" . "application/x-tex") | |
852 (".texi" . "application/texinfo") | |
853 (".tga" . "image/x-targa") | |
854 (".tif" . "image/tiff") | |
855 (".tiff" . "image/tiff") | |
856 (".tr" . "application/x-troff") | |
857 (".troff" . "application/x-troff") | |
858 (".tsv" . "text/tab-separated-values") | |
859 (".txt" . "text/plain") | |
860 (".vbs" . "video/mpeg") | |
861 (".vox" . "audio/basic") | |
862 (".vrml" . "x-world/x-vrml") | |
863 (".wav" . "audio/x-wav") | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
864 (".xls" . "application/vnd.ms-excel") |
33821 | 865 (".wrl" . "x-world/x-vrml") |
866 (".xbm" . "image/xbm") | |
867 (".xpm" . "image/xpm") | |
868 (".xwd" . "image/windowdump") | |
869 (".zip" . "application/zip") | |
870 (".ai" . "application/postscript") | |
871 (".jpe" . "image/jpeg") | |
872 (".jpeg" . "image/jpeg")) | |
873 "An alist of file extensions and corresponding MIME content-types. | |
874 This exists for you to customize the information in Lisp. It is | |
875 merged with values from mailcap files by `mailcap-parse-mimetypes'.") | |
31717 | 876 |
877 (defvar mailcap-mimetypes-parsed-p nil) | |
878 | |
879 (defun mailcap-parse-mimetypes (&optional path force) | |
33821 | 880 "Parse out all the mimetypes specified in a Unix-style path string PATH. |
31717 | 881 Components of PATH are separated by the `path-separator' character |
882 appropriate for this system. If PATH is omitted, use the value of | |
883 environment variable MIMETYPES if set; otherwise use a default path. | |
884 If FORCE, re-parse even if already parsed." | |
885 (interactive (list nil t)) | |
886 (when (or (not mailcap-mimetypes-parsed-p) | |
887 force) | |
888 (cond | |
889 (path nil) | |
890 ((getenv "MIMETYPES") (setq path (getenv "MIMETYPES"))) | |
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
55046
diff
changeset
|
891 ((memq system-type mailcap-poor-system-types) |
31717 | 892 (setq path '("~/mime.typ" "~/etc/mime.typ"))) |
893 (t (setq path | |
894 ;; mime.types seems to be the normal name, definitely so | |
895 ;; on current GNUish systems. The search order follows | |
896 ;; that for mailcap. | |
897 '("~/.mime.types" | |
898 "/etc/mime.types" | |
899 "/usr/etc/mime.types" | |
900 "/usr/local/etc/mime.types" | |
901 "/usr/local/www/conf/mime.types" | |
902 "~/.mime-types" | |
903 "/etc/mime-types" | |
904 "/usr/etc/mime-types" | |
905 "/usr/local/etc/mime-types" | |
906 "/usr/local/www/conf/mime-types")))) | |
907 (let ((fnames (reverse (if (stringp path) | |
32989
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
908 (delete "" (split-string path path-separator)) |
31717 | 909 path))) |
910 fname) | |
911 (while fnames | |
912 (setq fname (car fnames)) | |
913 (if (and (file-readable-p fname)) | |
914 (mailcap-parse-mimetype-file fname)) | |
915 (setq fnames (cdr fnames)))) | |
916 (setq mailcap-mimetypes-parsed-p t))) | |
917 | |
918 (defun mailcap-parse-mimetype-file (fname) | |
33821 | 919 "Parse out a mime-types file FNAME." |
31717 | 920 (let (type ; The MIME type for this line |
921 extns ; The extensions for this line | |
922 save-pos ; Misc. saved buffer positions | |
923 ) | |
924 (with-temp-buffer | |
925 (insert-file-contents fname) | |
926 (mailcap-replace-regexp "#.*" "") | |
927 (mailcap-replace-regexp "\n+" "\n") | |
928 (mailcap-replace-regexp "[ \t]+$" "") | |
929 (goto-char (point-max)) | |
930 (skip-chars-backward " \t\n") | |
931 (delete-region (point) (point-max)) | |
932 (goto-char (point-min)) | |
933 (while (not (eobp)) | |
934 (skip-chars-forward " \t\n") | |
935 (setq save-pos (point)) | |
936 (skip-chars-forward "^ \t\n") | |
937 (downcase-region save-pos (point)) | |
938 (setq type (buffer-substring save-pos (point))) | |
939 (while (not (eolp)) | |
940 (skip-chars-forward " \t") | |
941 (setq save-pos (point)) | |
942 (skip-chars-forward "^ \t\n") | |
943 (setq extns (cons (buffer-substring save-pos (point)) extns))) | |
944 (while extns | |
945 (setq mailcap-mime-extensions | |
946 (cons | |
947 (cons (if (= (string-to-char (car extns)) ?.) | |
948 (car extns) | |
949 (concat "." (car extns))) type) | |
950 mailcap-mime-extensions) | |
951 extns (cdr extns))))))) | |
952 | |
953 (defun mailcap-extension-to-mime (extn) | |
954 "Return the MIME content type of the file extensions EXTN." | |
955 (mailcap-parse-mimetypes) | |
956 (if (and (stringp extn) | |
957 (not (eq (string-to-char extn) ?.))) | |
958 (setq extn (concat "." extn))) | |
959 (cdr (assoc (downcase extn) mailcap-mime-extensions))) | |
960 | |
33821 | 961 ;; Unused? |
962 (defalias 'mailcap-command-p 'executable-find) | |
31717 | 963 |
964 (defun mailcap-mime-types () | |
965 "Return a list of MIME media types." | |
966 (mailcap-parse-mimetypes) | |
32989
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
967 (mm-delete-duplicates |
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
968 (nconc |
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
969 (mapcar 'cdr mailcap-mime-extensions) |
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
970 (apply |
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
971 'nconc |
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
972 (mapcar |
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
973 (lambda (l) |
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
974 (delq nil |
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
975 (mapcar |
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
976 (lambda (m) |
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
977 (let ((type (cdr (assq 'type (cdr m))))) |
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
978 (if (equal (cadr (split-string type "/")) |
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
979 "*") |
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
980 nil |
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
981 type))) |
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
982 (cdr l)))) |
74484f2d629a
2000-10-27 ShengHuo ZHU <zsh@cs.rochester.edu>
Dave Love <fx@gnu.org>
parents:
31717
diff
changeset
|
983 mailcap-mime-data))))) |
31717 | 984 |
985 (provide 'mailcap) | |
986 | |
52401 | 987 ;;; arch-tag: 1fd4f9c9-c305-4d2e-9747-3a4d45baa0bd |
31717 | 988 ;;; mailcap.el ends here |