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