annotate lisp/w3/mm.el @ 62:28a7c63c7e1e r19-16-pre6

Import from CVS: tag r19-16-pre6
author cvs
date Mon, 13 Aug 2007 08:59:13 +0200
parents 8d2a9b52c682
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1 ;;; mm.el,v --- Mailcap parsing routines, and MIME handling
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
2 ;; Author: wmperry
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
3 ;; Created: 1996/05/28 02:46:51
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
4 ;; Version: 1.96
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
5 ;; Keywords: mail, news, hypermedia
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
6
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
8 ;;; Copyright (c) 1994, 1995, 1996 by William M. Perry (wmperry@cs.indiana.edu)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
9 ;;; Copyright (c) 1996, 1997 Free Software Foundation, Inc.
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
10 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
11 ;;; This file is not part of GNU Emacs, but the same permissions apply.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
12 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
13 ;;; GNU Emacs is free software; you can redistribute it and/or modify
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
14 ;;; it under the terms of the GNU General Public License as published by
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
15 ;;; the Free Software Foundation; either version 2, or (at your option)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
16 ;;; any later version.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
17 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
19 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
21 ;;; GNU General Public License for more details.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
22 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
23 ;;; You should have received a copy of the GNU General Public License
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
24 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
25 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
26 ;;; Boston, MA 02111-1307, USA.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
27 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
29 ;;; Generalized mailcap parsing and access routines
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
30 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
31 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
32 ;;; Data structures
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
33 ;;; ---------------
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
34 ;;; The mailcap structure is an assoc list of assoc lists.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
35 ;;; 1st assoc list is keyed on the major content-type
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
36 ;;; 2nd assoc list is keyed on the minor content-type (which can be a regexp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
37 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
38 ;;; Which looks like:
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
39 ;;; -----------------
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
40 ;;; (
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
41 ;;; ("application"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
42 ;;; ("postscript" . <info>)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
43 ;;; )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
44 ;;; ("text"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
45 ;;; ("plain" . <info>)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
46 ;;; )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
47 ;;; )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
48 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
49 ;;; Where <info> is another assoc list of the various information
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
50 ;;; related to the mailcap RFC. This is keyed on the lowercase
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
51 ;;; attribute name (viewer, test, etc). This looks like:
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
52 ;;; (("viewer" . viewerinfo)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
53 ;;; ("test" . testinfo)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
54 ;;; ("xxxx" . "string")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
55 ;;; )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
56 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
57 ;;; Where viewerinfo specifies how the content-type is viewed. Can be
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
58 ;;; a string, in which case it is run through a shell, with
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
59 ;;; appropriate parameters, or a symbol, in which case the symbol is
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
60 ;;; funcall'd, with the buffer as an argument.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
61 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
62 ;;; testinfo is a list of strings, or nil. If nil, it means the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
63 ;;; viewer specified is always valid. If it is a list of strings,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
64 ;;; these are used to determine whether a viewer passes the 'test' or
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
65 ;;; not.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
66 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
67 ;;; The main interface to this code is:
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
68 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
69 ;;; To set everything up:
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
70 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
71 ;;; (mm-parse-mailcaps [path])
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
72 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
73 ;;; Where PATH is a unix-style path specification (: separated list
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
74 ;;; of strings). If PATH is nil, the environment variable MAILCAPS
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
75 ;;; will be consulted. If there is no environment variable, then a
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
76 ;;; default list of paths is used.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
77 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
78 ;;; To retrieve the information:
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
79 ;;; (mm-mime-info st [nd] [request])
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
80 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
81 ;;; Where st and nd are positions in a buffer that contain the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
82 ;;; content-type header information of a mail/news/whatever message.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
83 ;;; st can optionally be a string that contains the content-type
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
84 ;;; information.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
85 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
86 ;;; Third argument REQUEST specifies what information to return. If
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
87 ;;; it is nil or the empty string, the viewer (second field of the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
88 ;;; mailcap entry) will be returned. If it is a string, then the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
89 ;;; mailcap field corresponding to that string will be returned
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
90 ;;; (print, description, whatever). If a number, then all the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
91 ;;; information for this specific viewer is returned.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
92 ;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
93 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
94 ;;; Variables, etc
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
95 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
96 (eval-and-compile
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
97 (require 'cl))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
98
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
99 (defconst mm-version (let ((x "1.96"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
100 (if (string-match "Revision: \\([^ \t\n]+\\)" x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
101 (substring x (match-beginning 1) (match-end 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
102 x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
103 "Version # of MM package")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
104
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
105 (defvar mm-parse-args-syntax-table
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
106 (copy-syntax-table emacs-lisp-mode-syntax-table)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
107 "A syntax table for parsing sgml attributes.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
108
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
109 (modify-syntax-entry ?' "\"" mm-parse-args-syntax-table)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
110 (modify-syntax-entry ?` "\"" mm-parse-args-syntax-table)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
111 (modify-syntax-entry ?{ "(" mm-parse-args-syntax-table)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
112 (modify-syntax-entry ?} ")" mm-parse-args-syntax-table)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
113
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
114 (defvar mm-mime-data
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
115 '(
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
116 ("multipart" . (
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
117 ("alternative". (("viewer" . mm-multipart-viewer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
118 ("type" . "multipart/alternative")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
119 ("mixed" . (("viewer" . mm-multipart-viewer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
120 ("type" . "multipart/mixed")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
121 (".*" . (("viewer" . mm-save-binary-file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
122 ("type" . "multipart/*")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
123 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
124 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
125 ("application" . (
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 36
diff changeset
126 ("x-x509-ca-cert" . (("viewer" . ssl-view-site-cert)
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 36
diff changeset
127 ("test" . (fboundp 'ssl-view-site-cert))
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 36
diff changeset
128 ("type" . "application/x-x509-ca-cert")))
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 36
diff changeset
129 ("x-x509-user-cert" . (("viewer" . ssl-view-user-cert)
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 36
diff changeset
130 ("test" . (fboundp 'ssl-view-user-cert))
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 36
diff changeset
131 ("type" . "application/x-x509-user-cert")))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
132 ("octet-stream" . (("viewer" . mm-save-binary-file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
133 ("type" ."application/octet-stream")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
134 ("dvi" . (("viewer" . "open %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
135 ("type" . "application/dvi")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
136 ("test" . (eq (device-type) 'ns))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
137 ("dvi" . (("viewer" . "xdvi %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
138 ("test" . (eq (device-type) 'x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
139 ("needsx11")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
140 ("type" . "application/dvi")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
141 ("dvi" . (("viewer" . "dvitty %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
142 ("test" . (not (getenv "DISPLAY")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
143 ("type" . "application/dvi")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
144 ("emacs-lisp" . (("viewer" . mm-maybe-eval)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
145 ("type" . "application/emacs-lisp")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
146 ; ("x-tar" . (("viewer" . tar-mode)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
147 ; ("test" . (fboundp 'tar-mode))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
148 ; ("type" . "application/x-tar")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
149 ("x-tar" . (("viewer" . mm-save-binary-file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
150 ("type" . "application/x-tar")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
151 ("x-latex" . (("viewer" . tex-mode)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
152 ("test" . (fboundp 'tex-mode))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
153 ("type" . "application/x-latex")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
154 ("x-tex" . (("viewer" . tex-mode)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
155 ("test" . (fboundp 'tex-mode))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
156 ("type" . "application/x-tex")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
157 ("latex" . (("viewer" . tex-mode)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
158 ("test" . (fboundp 'tex-mode))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
159 ("type" . "application/latex")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
160 ("tex" . (("viewer" . tex-mode)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
161 ("test" . (fboundp 'tex-mode))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
162 ("type" . "application/tex")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
163 ("texinfo" . (("viewer" . texinfo-mode)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
164 ("test" . (fboundp 'texinfo-mode))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
165 ("type" . "application/tex")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
166 ("zip" . (("viewer" . mm-save-binary-file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
167 ("type" . "application/zip")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
168 ("copiousoutput")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
169 ("pdf" . (("viewer" . "acroread %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
170 ("type" . "application/pdf")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
171 ("postscript" . (("viewer" . "open %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
172 ("type" . "application/postscript")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
173 ("test" . (eq (device-type) 'ns))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
174 ("postscript" . (("viewer" . "ghostview %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
175 ("type" . "application/postscript")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
176 ("test" . (eq (device-type) 'x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
177 ("needsx11")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
178 ("postscript" . (("viewer" . "ps2ascii %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
179 ("type" . "application/postscript")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
180 ("test" . (not (getenv "DISPLAY")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
181 ("copiousoutput")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
182 ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
183 ("audio" . (
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
184 ("x-mpeg" . (("viewer" . "maplay %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
185 ("type" . "audio/x-mpeg")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
186 (".*" . (("viewer" . mm-play-sound-file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
187 ("test" . (or (featurep 'nas-sound)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
188 (featurep 'native-sound)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
189 ("type" . "audio/*")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
190 (".*" . (("viewer" . "showaudio")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
191 ("type" . "audio/*")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
192 ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
193 ("message" . (
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
194 ("rfc-*822" . (("viewer" . vm-mode)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
195 ("test" . (fboundp 'vm-mode))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
196 ("type" . "message/rfc-822")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
197 ("rfc-*822" . (("viewer" . w3-mode)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
198 ("test" . (fboundp 'w3-mode))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
199 ("type" . "message/rfc-822")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
200 ("rfc-*822" . (("viewer" . view-mode)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
201 ("test" . (fboundp 'view-mode))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
202 ("type" . "message/rfc-822")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
203 ("rfc-*822" . (("viewer" . fundamental-mode)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
204 ("type" . "message/rfc-822")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
205 ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
206 ("image" . (
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
207 ("x-xwd" . (("viewer" . "xwud -in %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
208 ("type" . "image/x-xwd")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
209 ("compose" . "xwd -frame > %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
210 ("test" . (eq (device-type) 'x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
211 ("needsx11")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
212 ("x11-dump" . (("viewer" . "xwud -in %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
213 ("type" . "image/x-xwd")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
214 ("compose" . "xwd -frame > %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
215 ("test" . (eq (device-type) 'x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
216 ("needsx11")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
217 ("windowdump" . (("viewer" . "xwud -in %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
218 ("type" . "image/x-xwd")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
219 ("compose" . "xwd -frame > %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
220 ("test" . (eq (device-type) 'x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
221 ("needsx11")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
222 (".*" . (("viewer" . "open %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
223 ("type" . "image/*")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
224 ("test" . (eq (device-type) 'ns))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
225 (".*" . (("viewer" . "xv -perfect %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
226 ("type" . "image/*")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
227 ("test" . (eq (device-type) 'x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
228 ("needsx11")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
229 ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
230 ("text" . (
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
231 ("plain" . (("viewer" . w3-mode)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
232 ("test" . (fboundp 'w3-mode))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
233 ("type" . "text/plain")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
234 ("plain" . (("viewer" . view-mode)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
235 ("test" . (fboundp 'view-mode))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
236 ("type" . "text/plain")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
237 ("plain" . (("viewer" . fundamental-mode)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
238 ("type" . "text/plain")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
239 ("enriched" . (("viewer" . enriched-decode-region)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
240 ("test" . (fboundp
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
241 'enriched-decode-region))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
242 ("type" . "text/enriched")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
243 ("html" . (("viewer" . w3-prepare-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
244 ("test" . (fboundp 'w3-prepare-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
245 ("type" . "text/html")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
246 ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
247 ("video" . (
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
248 ("mpeg" . (("viewer" . "mpeg_play %s")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
249 ("type" . "video/mpeg")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
250 ("test" . (eq (device-type) 'x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
251 ("needsx11")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
252 ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
253 ("x-world" . (
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
254 ("x-vrml" . (("viewer" . "webspace -remote %s -URL %u")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
255 ("type" . "x-world/x-vrml")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
256 ("description"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
257 "VRML document")))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
258 ("archive" . (
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
259 ("tar" . (("viewer" . tar-mode)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
260 ("type" . "archive/tar")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
261 ("test" . (fboundp 'tar-mode))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
262 ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
263 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
264 "*The mailcap structure is an assoc list of assoc lists.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
265 1st assoc list is keyed on the major content-type
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
266 2nd assoc list is keyed on the minor content-type (which can be a regexp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
267
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
268 Which looks like:
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
269 -----------------
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
270 (
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
271 (\"application\"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
272 (\"postscript\" . <info>)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
273 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
274 (\"text\"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
275 (\"plain\" . <info>)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
276 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
277 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
278
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
279 Where <info> is another assoc list of the various information
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
280 related to the mailcap RFC. This is keyed on the lowercase
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
281 attribute name (viewer, test, etc). This looks like:
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
282 ((\"viewer\" . viewerinfo)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
283 (\"test\" . testinfo)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
284 (\"xxxx\" . \"string\")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
285 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
286
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
287 Where viewerinfo specifies how the content-type is viewed. Can be
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
288 a string, in which case it is run through a shell, with
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
289 appropriate parameters, or a symbol, in which case the symbol is
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
290 funcall'd, with the buffer as an argument.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
291
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
292 testinfo is a list of strings, or nil. If nil, it means the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
293 viewer specified is always valid. If it is a list of strings,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
294 these are used to determine whether a viewer passes the 'test' or
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
295 not.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
296
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
297 (defvar mm-content-transfer-encodings
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
298 '(("base64" . base64-decode-region)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
299 ("7bit" . ignore)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
300 ("8bit" . ignore)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
301 ("binary" . ignore)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
302 ("x-compress" . ("uncompress" "-c"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
303 ("x-gzip" . ("gzip" "-dc"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
304 ("compress" . ("uncompress" "-c"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
305 ("gzip" . ("gzip" "-dc"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
306 ("x-hqx" . ("mcvert" "-P" "-s" "-S"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
307 ("quoted-printable" . mm-decode-quoted-printable)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
308 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
309 "*An assoc list of content-transfer-encodings and how to decode them.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
310
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
311 (defvar mm-download-directory nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
312 "*Where downloaded files should go by default.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
313
36
c53a95d3c46d Import from CVS: tag r19-15b101
cvs
parents: 32
diff changeset
314 (defvar mm-temporary-directory (or (getenv "TMPDIR") "/tmp")
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
315 "*Where temporary files go.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
316
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
317
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
318 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
319 ;;; A few things from w3 and url, just in case this is used without them
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
320 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
321
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
322 (defun mm-generate-unique-filename (&optional fmt)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
323 "Generate a unique filename in mm-temporary-directory"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
324 (if (not fmt)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
325 (let ((base (format "mm-tmp.%d" (user-real-uid)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
326 (fname "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
327 (x 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
328 (setq fname (format "%s%d" base x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
329 (while (file-exists-p
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
330 (expand-file-name fname mm-temporary-directory))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
331 (setq x (1+ x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
332 fname (concat base (int-to-string x))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
333 (expand-file-name fname mm-temporary-directory))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
334 (let ((base (concat "mm" (int-to-string (user-real-uid))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
335 (fname "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
336 (x 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
337 (setq fname (format fmt (concat base (int-to-string x))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
338 (while (file-exists-p
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
339 (expand-file-name fname mm-temporary-directory))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
340 (setq x (1+ x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
341 fname (format fmt (concat base (int-to-string x)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
342 (expand-file-name fname mm-temporary-directory))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
343
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
344 (if (and (fboundp 'copy-tree)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
345 (subrp (symbol-function 'copy-tree)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
346 (fset 'mm-copy-tree 'copy-tree)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
347 (defun mm-copy-tree (tree)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
348 (if (consp tree)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
349 (cons (mm-copy-tree (car tree))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
350 (mm-copy-tree (cdr tree)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
351 (if (vectorp tree)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
352 (let* ((new (copy-sequence tree))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
353 (i (1- (length new))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
354 (while (>= i 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
355 (aset new i (mm-copy-tree (aref new i)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
356 (setq i (1- i)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
357 new)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
358 tree))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
359
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
360 (require 'mule-sysdp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
361
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
362 (if (not (fboundp 'w3-save-binary-file))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
363 (defun mm-save-binary-file ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
364 ;; Ok, this is truly fucked. In XEmacs, if you use the mouse to select
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
365 ;; a URL that gets saved via this function, read-file-name will pop up a
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
366 ;; dialog box for file selection. For some reason which buffer we are in
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
367 ;; gets royally screwed (even with save-excursions and the whole nine
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
368 ;; yards). SO, we just keep the old buffer name around and away we go.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
369 (let ((old-buff (current-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
370 (file (read-file-name "Filename to save as: "
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
371 (or mm-download-directory "~/")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
372 (file-name-nondirectory (url-view-url t))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
373 nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
374 (file-name-nondirectory (url-view-url t))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
375 (require-final-newline nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
376 (set-buffer old-buff)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
377 (mule-write-region-no-coding-system (point-min) (point-max) file)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
378 (kill-buffer (current-buffer))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
379 (fset 'mm-save-binary-file 'w3-save-binary-file))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
380
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
381 (defun mm-maybe-eval ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
382 "Maybe evaluate a buffer of emacs lisp code"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
383 (if (yes-or-no-p "This is emacs-lisp code, evaluate it? ")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
384 (eval-buffer (current-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
385 (emacs-lisp-mode)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
386
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
387
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
388 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
389 ;;; The mailcap parser
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
390 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
391 (defun mm-viewer-unescape (format &optional filename url)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
392 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
393 (set-buffer (get-buffer-create " *mm-parse*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
394 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
395 (insert format)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
396 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
397 (while (re-search-forward "%\\(.\\)" nil t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
398 (let ((escape (aref (match-string 1) 0)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
399 (replace-match "" t t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
400 (case escape
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
401 (?% (insert "%"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
402 (?s (insert (or filename "\"\"")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
403 (?u (insert (or url "\"\""))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
404 (buffer-string)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
405
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
406 (defun mm-in-assoc (elt list)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
407 ;; Check to see if ELT matches any of the regexps in the car elements of LIST
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
408 (let (rslt)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
409 (while (and list (not rslt))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
410 (and (car (car list))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
411 (string-match (car (car list)) elt)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
412 (setq rslt (car list)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
413 (setq list (cdr list)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
414 rslt))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
415
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
416 (defun mm-replace-regexp (regexp to-string)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
417 ;; Quiet replace-regexp.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
418 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
419 (while (re-search-forward regexp nil t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
420 (replace-match to-string t nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
421
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
422 (defun mm-parse-mailcaps (&optional path)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
423 ;; Parse out all the mailcaps specified in a unix-style path string PATH
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
424 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
425 (path nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
426 ((getenv "MAILCAPS") (setq path (getenv "MAILCAPS")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
427 ((memq system-type '(ms-dos ms-windows windows-nt))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
428 (setq path (mapconcat 'expand-file-name '("~/mail.cap" "~/etc/mail.cap")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
429 ";")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
430 (t (setq path (concat "/etc/mailcap:/usr/etc/mailcap:"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
431 "/usr/local/etc/mailcap:"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
432 (expand-file-name "~/.mailcap")))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
433 (let ((fnames (mm-string-to-tokens path
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
434 (if (memq system-type
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
435 '(ms-dos ms-windows windows-nt))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
436 ?;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
437 ?:))) fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
438 (while fnames
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
439 (setq fname (car fnames))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
440 (if (and (file-exists-p fname) (file-readable-p fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
441 (mm-parse-mailcap (car fnames)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
442 (setq fnames (cdr fnames)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
443
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
444 (defun mm-parse-mailcap (fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
445 ;; Parse out the mailcap file specified by FNAME
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
446 (let (major ; The major mime type (image/audio/etc)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
447 minor ; The minor mime type (gif, basic, etc)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
448 save-pos ; Misc saved positions used in parsing
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
449 viewer ; How to view this mime type
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
450 info ; Misc info about this mime type
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
451 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
452 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
453 (set-buffer (get-buffer-create " *mailcap*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
454 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
455 (insert-file-contents fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
456 (set-syntax-table mm-parse-args-syntax-table)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
457 (mm-replace-regexp "#.*" "") ; Remove all comments
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
458 (mm-replace-regexp "\n+" "\n") ; And blank lines
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
459 (mm-replace-regexp "\\\\[ \t\n]+" " ") ; And collapse spaces
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
460 (mm-replace-regexp (concat (regexp-quote "\\") "[ \t]*\n") "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
461 (goto-char (point-max))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
462 (skip-chars-backward " \t\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
463 (delete-region (point) (point-max))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
464 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
465 (while (not (eobp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
466 (skip-chars-forward " \t\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
467 (setq save-pos (point)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
468 info nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
469 (skip-chars-forward "^/;")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
470 (downcase-region save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
471 (setq major (buffer-substring save-pos (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
472 (skip-chars-forward "/ \t\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
473 (setq save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
474 (skip-chars-forward "^;")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
475 (downcase-region save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
476 (setq minor
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
477 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
478 ((= ?* (or (char-after save-pos) 0)) ".*")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
479 ((= (point) save-pos) ".*")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
480 (t (buffer-substring save-pos (point)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
481 (skip-chars-forward "; \t\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
482 ;;; Got the major/minor chunks, now for the viewers/etc
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
483 ;;; The first item _must_ be a viewer, according to the
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
484 ;;; RFC for mailcap files (#1343)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
485 (skip-chars-forward "; \t\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
486 (setq save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
487 (skip-chars-forward "^;\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
488 (if (= (or (char-after save-pos) 0) ?')
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
489 (setq viewer (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
490 (narrow-to-region (1+ save-pos) (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
491 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
492 (prog1
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
493 (read (current-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
494 (goto-char (point-max))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
495 (widen))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
496 (setq viewer (buffer-substring save-pos (point))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
497 (setq save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
498 (end-of-line)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
499 (setq info (nconc (list (cons "viewer" viewer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
500 (cons "type" (concat major "/"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
501 (if (string= minor ".*")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
502 "*" minor))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
503 (mm-parse-mailcap-extras save-pos (point))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
504 (mm-mailcap-entry-passes-test info)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
505 (mm-add-mailcap-entry major minor info)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
506
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
507 (defun mm-parse-mailcap-extras (st nd)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
508 ;; Grab all the extra stuff from a mailcap entry
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
509 (let (
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
510 name ; From name=
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
511 value ; its value
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
512 results ; Assoc list of results
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
513 name-pos ; Start of XXXX= position
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
514 val-pos ; Start of value position
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
515 done ; Found end of \'d ;s?
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
516 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
517 (save-restriction
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
518 (narrow-to-region st nd)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
519 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
520 (skip-chars-forward " \n\t;")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
521 (while (not (eobp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
522 (setq done nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
523 (skip-chars-forward " \";\n\t")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
524 (setq name-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
525 (skip-chars-forward "^ \n\t=")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
526 (downcase-region name-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
527 (setq name (buffer-substring name-pos (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
528 (skip-chars-forward " \t\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
529 (if (/= (or (char-after (point)) 0) ?=) ; There is no value
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
530 (setq value nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
531 (skip-chars-forward " \t\n=")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
532 (setq val-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
533 (if (memq (char-after val-pos) '(?\" ?'))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
534 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
535 (setq val-pos (1+ val-pos))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
536 (condition-case nil
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
537 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
538 (forward-sexp 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
539 (backward-char 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
540 (error (goto-char (point-max)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
541 (while (not done)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
542 (skip-chars-forward "^;")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
543 (if (= (or (char-after (1- (point))) 0) ?\\ )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
544 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
545 (subst-char-in-region (1- (point)) (point) ?\\ ? )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
546 (skip-chars-forward ";"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
547 (setq done t))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
548 (setq value (buffer-substring val-pos (point))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
549 (setq results (cons (cons name value) results)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
550 results)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
551
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
552 (defun mm-string-to-tokens (str &optional delim)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
553 "Return a list of words from the string STR"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
554 (setq delim (or delim ? ))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
555 (let (results y)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
556 (mapcar
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
557 (function
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
558 (lambda (x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
559 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
560 ((and (= x delim) y) (setq results (cons y results) y nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
561 ((/= x delim) (setq y (concat y (char-to-string x))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
562 (t nil)))) str)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
563 (nreverse (cons y results))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
564
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
565 (defun mm-mailcap-entry-passes-test (info)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
566 ;; Return t iff a mailcap entry passes its test clause or no test
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
567 ;; clause is present.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
568 (let (status ; Call-process-regions return value
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
569 (test (assoc "test" info)); The test clause
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
570 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
571 (setq status (and test (mm-string-to-tokens (cdr test))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
572 (if (and (assoc "needsx11" info) (not (getenv "DISPLAY")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
573 (setq status nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
574 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
575 ((and (equal (nth 0 status) "test")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
576 (equal (nth 1 status) "-n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
577 (or (equal (nth 2 status) "$DISPLAY")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
578 (equal (nth 2 status) "\"$DISPLAY\"")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
579 (setq status (if (getenv "DISPLAY") t nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
580 ((and (equal (nth 0 status) "test")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
581 (equal (nth 1 status) "-z")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
582 (or (equal (nth 2 status) "$DISPLAY")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
583 (equal (nth 2 status) "\"$DISPLAY\"")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
584 (setq status (if (getenv "DISPLAY") nil t)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
585 (test nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
586 (t nil)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
587 (and test (listp test) (setcdr test status))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
588
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
589 (defun mm-parse-args (st &optional nd nodowncase)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
590 ;; Return an assoc list of attribute/value pairs from an RFC822-type string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
591 (let (
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
592 name ; From name=
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
593 value ; its value
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
594 results ; Assoc list of results
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
595 name-pos ; Start of XXXX= position
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
596 val-pos ; Start of value position
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
597 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
598 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
599 (if (stringp st)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
600 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
601 (set-buffer (get-buffer-create " *mm-temp*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
602 (set-syntax-table mm-parse-args-syntax-table)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
603 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
604 (insert st)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
605 (setq st (point-min)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
606 nd (point-max)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
607 (set-syntax-table mm-parse-args-syntax-table))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
608 (save-restriction
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
609 (narrow-to-region st nd)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
610 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
611 (while (not (eobp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
612 (skip-chars-forward "; \n\t")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
613 (setq name-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
614 (skip-chars-forward "^ \n\t=;")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
615 (if (not nodowncase)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
616 (downcase-region name-pos (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
617 (setq name (buffer-substring name-pos (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
618 (skip-chars-forward " \t\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
619 (if (/= (or (char-after (point)) 0) ?=) ; There is no value
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
620 (setq value nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
621 (skip-chars-forward " \t\n=")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
622 (setq val-pos (point)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
623 value
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
624 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
625 ((or (= (or (char-after val-pos) 0) ?\")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
626 (= (or (char-after val-pos) 0) ?'))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
627 (buffer-substring (1+ val-pos)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
628 (condition-case ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
629 (prog2
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
630 (forward-sexp 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
631 (1- (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
632 (skip-chars-forward "\""))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
633 (error
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
634 (skip-chars-forward "^ \t\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
635 (point)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
636 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
637 (buffer-substring val-pos
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
638 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
639 (skip-chars-forward "^;")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
640 (skip-chars-backward " \t")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
641 (point)))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
642 (setq results (cons (cons name value) results))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
643 (skip-chars-forward "; \n\t"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
644 results))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
645
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
646 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
647 ;;; The action routines.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
648 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
649 (defun mm-possible-viewers (major minor)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
650 ;; Return a list of possible viewers from MAJOR for minor type MINOR
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
651 (let ((exact '())
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
652 (wildcard '()))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
653 (while major
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
654 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
655 ((equal (car (car major)) minor)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
656 (setq exact (cons (cdr (car major)) exact)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
657 ((string-match (car (car major)) minor)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
658 (setq wildcard (cons (cdr (car major)) wildcard))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
659 (setq major (cdr major)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
660 (nconc (nreverse exact) (nreverse wildcard))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
661
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
662 (defun mm-unescape-mime-test (test type-info)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
663 (let ((buff (get-buffer-create " *unescape*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
664 save-pos save-chr subst)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
665 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
666 ((symbolp test) test)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
667 ((and (listp test) (symbolp (car test))) test)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
668 ((or (stringp test)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
669 (and (listp test) (stringp (car test))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
670 (setq test (mapconcat 'identity test " "))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
671 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
672 (set-buffer buff)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
673 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
674 (insert test)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
675 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
676 (while (not (eobp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
677 (skip-chars-forward "^%")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
678 (if (/= (- (point)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
679 (progn (skip-chars-backward "\\\\")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
680 (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
681 0) ; It is an escaped %
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
682 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
683 (delete-char 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
684 (skip-chars-forward "%."))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
685 (setq save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
686 (skip-chars-forward "%")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
687 (setq save-chr (char-after (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
688 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
689 ((null save-chr) nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
690 ((= save-chr ?t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
691 (delete-region save-pos (progn (forward-char 1) (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
692 (insert (or (cdr (assoc "type" type-info)) "\"\"")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
693 ((= save-chr ?M)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
694 (delete-region save-pos (progn (forward-char 1) (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
695 (insert "\"\""))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
696 ((= save-chr ?n)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
697 (delete-region save-pos (progn (forward-char 1) (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
698 (insert "\"\""))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
699 ((= save-chr ?F)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
700 (delete-region save-pos (progn (forward-char 1) (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
701 (insert "\"\""))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
702 ((= save-chr ?{)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
703 (forward-char 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
704 (skip-chars-forward "^}")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
705 (downcase-region (+ 2 save-pos) (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
706 (setq subst (buffer-substring (+ 2 save-pos) (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
707 (delete-region save-pos (1+ (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
708 (insert (or (cdr (assoc subst type-info)) "\"\"")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
709 (t nil))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
710 (buffer-string)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
711 (t (error "Bad value to mm-unescape-mime-test. %s" test)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
712
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
713 (defun mm-viewer-passes-test (viewer-info type-info)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
714 ;; Return non-nil iff the viewer specified by VIEWER-INFO passes its
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
715 ;; test clause (if any).
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
716 (let* ((test-info (assoc "test" viewer-info))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
717 (test (cdr test-info))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
718 (viewer (cdr (assoc "viewer" viewer-info)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
719 status
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
720 parsed-test
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
721 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
722 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
723 ((not test-info) t) ; No test clause
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
724 ((not test) nil) ; Already failed test
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
725 ((eq test t) t) ; Already passed test
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
726 ((and (symbolp test) ; Lisp function as test
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
727 (fboundp test))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
728 (funcall test type-info))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
729 ((and (symbolp test) ; Lisp variable as test
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
730 (boundp test))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
731 (symbol-value test))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
732 ((and (listp test) ; List to be eval'd
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
733 (symbolp (car test)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
734 (eval test))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
735 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
736 (setq test (mm-unescape-mime-test test type-info)
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 26
diff changeset
737 test (list shell-file-name nil nil nil shell-command-switch test)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
738 status (apply 'call-process test))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
739 (= 0 status)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
740
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
741 (defun mm-add-mailcap-entry (major minor info)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
742 (let ((old-major (assoc major mm-mime-data)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
743 (if (null old-major) ; New major area
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
744 (setq mm-mime-data
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
745 (cons (cons major (list (cons minor info)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
746 mm-mime-data))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
747 (let ((cur-minor (assoc minor old-major)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
748 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
749 ((or (null cur-minor) ; New minor area, or
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
750 (assoc "test" info)) ; Has a test, insert at beginning
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
751 (setcdr old-major (cons (cons minor info) (cdr old-major))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
752 ((and (not (assoc "test" info)); No test info, replace completely
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
753 (not (assoc "test" cur-minor)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
754 (setcdr cur-minor info))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
755 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
756 (setcdr old-major (cons (cons minor info) (cdr old-major)))))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
757
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
758
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
759 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
760 ;;; The main whabbo
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
761 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
762 (defun mm-viewer-lessp (x y)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
763 ;; Return t iff viewer X is more desirable than viewer Y
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
764 (let ((x-wild (string-match "[*?]" (or (cdr-safe (assoc "type" x)) "")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
765 (y-wild (string-match "[*?]" (or (cdr-safe (assoc "type" y)) "")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
766 (x-lisp (not (stringp (or (cdr-safe (assoc "viewer" x)) ""))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
767 (y-lisp (not (stringp (or (cdr-safe (assoc "viewer" y)) "")))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
768 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
769 ((and x-lisp (not y-lisp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
770 t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
771 ((and (not y-lisp) x-wild (not y-wild))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
772 t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
773 ((and (not x-wild) y-wild)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
774 t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
775 (t nil))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
776
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
777 (defun mm-mime-info (st &optional nd request)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
778 "Get the mime viewer command for HEADERLINE, return nil if none found.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
779 Expects a complete content-type header line as its argument. This can
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
780 be simple like text/html, or complex like text/plain; charset=blah; foo=bar
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
781
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
782 Third argument REQUEST specifies what information to return. If it is
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
783 nil or the empty string, the viewer (second field of the mailcap
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
784 entry) will be returned. If it is a string, then the mailcap field
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
785 corresponding to that string will be returned (print, description,
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
786 whatever). If a number, then all the information for this specific
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
787 viewer is returned."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
788 (let (
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
789 major ; Major encoding (text, etc)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
790 minor ; Minor encoding (html, etc)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
791 info ; Other info
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
792 save-pos ; Misc. position during parse
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
793 major-info ; (assoc major mm-mime-data)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
794 minor-info ; (assoc minor major-info)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
795 test ; current test proc.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
796 viewers ; Possible viewers
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
797 passed ; Viewers that passed the test
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
798 viewer ; The one and only viewer
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
799 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
800 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
801 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
802 ((null st)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
803 (set-buffer (get-buffer-create " *mimeparse*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
804 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
805 (insert "text/plain")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
806 (setq st (point-min)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
807 ((stringp st)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
808 (set-buffer (get-buffer-create " *mimeparse*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
809 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
810 (insert st)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
811 (setq st (point-min)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
812 ((null nd)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
813 (narrow-to-region st (progn (goto-char st) (end-of-line) (point))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
814 (t (narrow-to-region st nd)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
815 (goto-char st)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
816 (skip-chars-forward ": \t\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
817 (buffer-enable-undo)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
818 (setq viewer
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
819 (catch 'mm-exit
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
820 (setq save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
821 (skip-chars-forward "^/")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
822 (downcase-region save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
823 (setq major (buffer-substring save-pos (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
824 (if (not (setq major-info (cdr (assoc major mm-mime-data))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
825 (throw 'mm-exit nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
826 (skip-chars-forward "/ \t\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
827 (setq save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
828 (skip-chars-forward "^ \t\n;")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
829 (downcase-region save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
830 (setq minor (buffer-substring save-pos (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
831 (if (not
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
832 (setq viewers (mm-possible-viewers major-info minor)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
833 (throw 'mm-exit nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
834 (skip-chars-forward "; \t")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
835 (if (eolp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
836 nil ; No qualifiers
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
837 (setq save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
838 (end-of-line)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
839 (setq info (mm-parse-args save-pos (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
840 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
841 (while viewers
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
842 (if (mm-viewer-passes-test (car viewers) info)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
843 (setq passed (cons (car viewers) passed)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
844 (setq viewers (cdr viewers)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
845 (setq passed (sort (nreverse passed) 'mm-viewer-lessp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
846 (car passed)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
847 (if (and (stringp (cdr (assoc "viewer" viewer)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
848 passed)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
849 (setq viewer (car passed)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
850 (widen)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
851 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
852 ((and (null viewer) (not (equal major "default")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
853 (mm-mime-info "default" nil request))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
854 ((or (null request) (equal request ""))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
855 (mm-unescape-mime-test (cdr (assoc "viewer" viewer)) info))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
856 ((stringp request)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
857 (if (or (string= request "test") (string= request "viewer"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
858 (mm-unescape-mime-test (cdr-safe (assoc request viewer)) info)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
859 (t
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
860 ;; MUST make a copy *sigh*, else we modify mm-mime-data
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
861 (setq viewer (mm-copy-tree viewer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
862 (let ((view (assoc "viewer" viewer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
863 (test (assoc "test" viewer)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
864 (if view (setcdr view (mm-unescape-mime-test (cdr view) info)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
865 (if test (setcdr test (mm-unescape-mime-test (cdr test) info))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
866 viewer)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
867
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
868
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
869 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
870 ;;; Experimental MIME-types parsing
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
871 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
872 (defvar mm-mime-extensions
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
873 '(
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
874 ("" . "text/plain")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
875 (".abs" . "audio/x-mpeg")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
876 (".aif" . "audio/aiff")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
877 (".aifc" . "audio/aiff")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
878 (".aiff" . "audio/aiff")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
879 (".ano" . "application/x-annotator")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
880 (".au" . "audio/ulaw")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
881 (".avi" . "video/x-msvideo")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
882 (".bcpio" . "application/x-bcpio")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
883 (".bin" . "application/octet-stream")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
884 (".cdf" . "application/x-netcdr")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
885 (".cpio" . "application/x-cpio")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
886 (".csh" . "application/x-csh")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
887 (".dvi" . "application/x-dvi")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
888 (".el" . "application/emacs-lisp")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
889 (".eps" . "application/postscript")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
890 (".etx" . "text/x-setext")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
891 (".exe" . "application/octet-stream")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
892 (".fax" . "image/x-fax")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
893 (".gif" . "image/gif")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
894 (".hdf" . "application/x-hdf")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
895 (".hqx" . "application/mac-binhex40")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
896 (".htm" . "text/html")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
897 (".html" . "text/html")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
898 (".icon" . "image/x-icon")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
899 (".ief" . "image/ief")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
900 (".jpg" . "image/jpeg")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
901 (".macp" . "image/x-macpaint")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
902 (".man" . "application/x-troff-man")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
903 (".me" . "application/x-troff-me")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
904 (".mif" . "application/mif")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
905 (".mov" . "video/quicktime")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
906 (".movie" . "video/x-sgi-movie")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
907 (".mp2" . "audio/x-mpeg")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
908 (".mp2a" . "audio/x-mpeg2")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
909 (".mpa" . "audio/x-mpeg")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
910 (".mpa2" . "audio/x-mpeg2")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
911 (".mpe" . "video/mpeg")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
912 (".mpeg" . "video/mpeg")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
913 (".mpega" . "audio/x-mpeg")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
914 (".mpegv" . "video/mpeg")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
915 (".mpg" . "video/mpeg")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
916 (".mpv" . "video/mpeg")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
917 (".ms" . "application/x-troff-ms")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
918 (".nc" . "application/x-netcdf")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
919 (".nc" . "application/x-netcdf")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
920 (".oda" . "application/oda")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
921 (".pbm" . "image/x-portable-bitmap")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
922 (".pdf" . "application/pdf")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
923 (".pgm" . "image/portable-graymap")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
924 (".pict" . "image/pict")
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
925 (".png" . "image/png")
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
926 (".pnm" . "image/x-portable-anymap")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
927 (".ppm" . "image/portable-pixmap")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
928 (".ps" . "application/postscript")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
929 (".qt" . "video/quicktime")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
930 (".ras" . "image/x-raster")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
931 (".rgb" . "image/x-rgb")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
932 (".rtf" . "application/rtf")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
933 (".rtx" . "text/richtext")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
934 (".sh" . "application/x-sh")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
935 (".sit" . "application/x-stuffit")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
936 (".snd" . "audio/basic")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
937 (".src" . "application/x-wais-source")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
938 (".tar" . "archive/tar")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
939 (".tcl" . "application/x-tcl")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
940 (".tcl" . "application/x-tcl")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
941 (".tex" . "application/x-tex")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
942 (".texi" . "application/texinfo")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
943 (".tga" . "image/x-targa")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
944 (".tif" . "image/tiff")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
945 (".tiff" . "image/tiff")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
946 (".tr" . "application/x-troff")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
947 (".troff" . "application/x-troff")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
948 (".tsv" . "text/tab-separated-values")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
949 (".txt" . "text/plain")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
950 (".vbs" . "video/mpeg")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
951 (".vox" . "audio/basic")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
952 (".vrml" . "x-world/x-vrml")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
953 (".wav" . "audio/x-wav")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
954 (".wrl" . "x-world/x-vrml")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
955 (".xbm" . "image/xbm")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
956 (".xpm" . "image/x-pixmap")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
957 (".xwd" . "image/windowdump")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
958 (".zip" . "application/zip")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
959 (".ai" . "application/postscript")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
960 (".jpe" . "image/jpeg")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
961 (".jpeg" . "image/jpeg")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
962 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
963 "*An assoc list of file extensions and the MIME content-types they
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
964 correspond to.")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
965
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
966 (defun mm-parse-mimetypes (&optional path)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
967 ;; Parse out all the mimetypes specified in a unix-style path string PATH
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
968 (cond
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
969 (path nil)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
970 ((getenv "MIMETYPES") (setq path (getenv "MIMETYPES")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
971 ((memq system-type '(ms-dos ms-windows windows-nt))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
972 (setq path (mapconcat 'expand-file-name
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
973 '("~/mime.typ" "~/etc/mime.typ") ";")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
974 (t (setq path (concat (expand-file-name "~/.mime-types") ":"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
975 "/etc/mime-types:/usr/etc/mime-types:"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
976 "/usr/local/etc/mime-types:"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
977 "/usr/local/www/conf/mime-types"))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
978 (let ((fnames (mm-string-to-tokens path
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
979 (if (memq system-type
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
980 '(ms-dos ms-windows windows-nt))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
981 ?;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
982 ?:))) fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
983 (while fnames
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
984 (setq fname (car fnames))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
985 (if (and (file-exists-p fname) (file-readable-p fname))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
986 (mm-parse-mimetype-file (car fnames)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
987 (setq fnames (cdr fnames)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
988
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
989 (defun mm-parse-mimetype-file (fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
990 ;; Parse out a mime-types file
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
991 (let (type ; The MIME type for this line
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
992 extns ; The extensions for this line
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
993 save-pos ; Misc. saved buffer positions
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
994 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
995 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
996 (set-buffer (get-buffer-create " *mime-types*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
997 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
998 (insert-file-contents fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
999 (mm-replace-regexp "#.*" "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1000 (mm-replace-regexp "\n+" "\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1001 (mm-replace-regexp "[ \t]+$" "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1002 (goto-char (point-max))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1003 (skip-chars-backward " \t\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1004 (delete-region (point) (point-max))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1005 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1006 (while (not (eobp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1007 (skip-chars-forward " \t\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1008 (setq save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1009 (skip-chars-forward "^ \t")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1010 (downcase-region save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1011 (setq type (buffer-substring save-pos (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1012 (while (not (eolp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1013 (skip-chars-forward " \t")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1014 (setq save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1015 (skip-chars-forward "^ \t\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1016 (setq extns (cons (buffer-substring save-pos (point)) extns)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1017 (while extns
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1018 (setq mm-mime-extensions
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1019 (cons
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1020 (cons (if (= (string-to-char (car extns)) ?.)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1021 (car extns)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1022 (concat "." (car extns))) type) mm-mime-extensions)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1023 extns (cdr extns)))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1024
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1025 (defun mm-extension-to-mime (extn)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1026 "Return the MIME content type of the file extensions EXTN"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1027 (if (and (stringp extn)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1028 (not (= (string-to-char extn) ?.)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1029 (setq extn (concat "." extn)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1030 (cdr (assoc (downcase extn) mm-mime-extensions)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1031
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1032
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1033 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1034 ;;; Editing/Composition of body parts
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1035 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1036 (defun mm-compose-type (type)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1037 ;; Compose a body section of MIME-type TYPE.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1038 (let* ((info (mm-mime-info type nil 5))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1039 (fnam (mm-generate-unique-filename))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1040 (comp (or (cdr (assoc "compose" info))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1041 (ctyp (cdr (assoc "composetyped" info)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1042 (buff (get-buffer-create " *mimecompose*"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1043 (typeit (not ctyp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1044 (retval "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1045 (usef nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1046 (setq comp (mm-unescape-mime-test (or comp ctyp) info))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1047 (while (string-match "\\([^\\\\]\\)%s" comp)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1048 (setq comp (concat (substring comp 0 (match-end 1)) fnam
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1049 (substring comp (match-end 0) nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1050 usef t))
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 26
diff changeset
1051 (call-process shell-file-name nil
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 26
diff changeset
1052 (if usef nil buff)
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 26
diff changeset
1053 nil shell-command-switch comp)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1054 (setq retval
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1055 (concat
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1056 (if typeit (concat "Content-type: " type "\r\n\r\n") "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1057 (if usef
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1058 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1059 (set-buffer buff)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1060 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1061 (insert-file-contents fnam)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1062 (buffer-string))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1063 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1064 (set-buffer buff)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1065 (buffer-string)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1066 "\r\n"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1067 retval))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1068
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1069 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1070 ;;; Misc.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1071 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1072 (defun mm-type-to-file (type)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1073 "Return the file extension for content-type TYPE"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1074 (rassoc type mm-mime-extensions))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1075
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1076
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1077 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1078 ;;; Miscellaneous MIME viewers written in elisp
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1079 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1080 (defun mm-play-sound-file (&optional buff)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1081 "Play a sound file in buffer BUFF (defaults to current buffer)"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1082 (setq buff (or buff (current-buffer)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1083 (let ((fname (mm-generate-unique-filename "%s.au"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1084 (synchronous-sounds t)) ; Play synchronously
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1085 (mm-write-region-no-coding-system (point-min) (point-max) fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1086 (kill-buffer (current-buffer))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1087 (play-sound-file fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1088 (condition-case ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1089 (delete-file fname)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1090 (error nil))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1091
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1092 (defun mm-parse-mime-headers (&optional no-delete)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1093 "Return a list of the MIME headers at the top of this buffer. If
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1094 optional argument NO-DELETE is non-nil, don't delete the headers."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1095 (let* ((st (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1096 (nd (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1097 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1098 (skip-chars-forward " \t\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1099 (if (re-search-forward "^\r*$" nil t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1100 (1+ (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1101 (point-max))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1102 save-pos
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1103 status
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1104 hname
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1105 hvalu
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1106 result
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1107 )
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1108 (narrow-to-region st nd)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1109 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1110 (while (not (eobp))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1111 (skip-chars-forward " \t\n\r")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1112 (setq save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1113 (skip-chars-forward "^:\n\r")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1114 (downcase-region save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1115 (setq hname (buffer-substring save-pos (point)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1116 (skip-chars-forward ": \t ")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1117 (setq save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1118 (skip-chars-forward "^\n\r")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1119 (setq hvalu (buffer-substring save-pos (point))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1120 result (cons (cons hname hvalu) result)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1121 (or no-delete (delete-region st nd))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1122 result))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1123
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1124 (defun mm-find-available-multiparts (separator &optional buf)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1125 "Return a list of mime-headers for the various body parts of a
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1126 multipart message in buffer BUF with separator SEPARATOR.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1127 The different multipart specs are put in `mm-temporary-directory'."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1128 (let ((sep (concat "^--" separator "\r*$"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1129 headers
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1130 fname
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1131 results)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1132 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1133 (and buf (set-buffer buf))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1134 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1135 (while (re-search-forward sep nil t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1136 (let ((st (set-marker (make-marker)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1137 (progn
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1138 (forward-line 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1139 (beginning-of-line)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1140 (point))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1141 (nd (set-marker (make-marker)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1142 (if (re-search-forward sep nil t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1143 (1- (match-beginning 0))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1144 (point-max)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1145 (narrow-to-region st nd)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1146 (goto-char st)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1147 (if (looking-at "^\r*$")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1148 (insert "Content-type: text/plain\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1149 "Content-length: " (int-to-string (- nd st)) "\n"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1150 (setq headers (mm-parse-mime-headers)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1151 fname (mm-generate-unique-filename))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1152 (let ((x (or (cdr (assoc "content-type" headers)) "text/plain")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1153 (if (string-match "name=\"*\\([^ \"]+\\)\"*" x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1154 (setq fname (expand-file-name
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1155 (substring x (match-beginning 1)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1156 (match-end 1))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1157 mm-temporary-directory))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1158 (widen)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1159 (if (assoc "content-transfer-encoding" headers)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1160 (let ((coding (cdr
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1161 (assoc "content-transfer-encoding" headers)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1162 (cmd nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1163 (setq coding (and coding (downcase coding))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1164 cmd (or (cdr (assoc coding
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1165 mm-content-transfer-encodings))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1166 (read-string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1167 (concat "How shall I decode " coding "? ")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1168 "cat")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1169 (if (string= cmd "") (setq cmd "cat"))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1170 (if (stringp cmd)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1171 (shell-command-on-region st nd cmd t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1172 (funcall cmd st nd))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1173 (set-marker nd (point))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1174 (write-region st nd fname nil 5)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1175 (delete-region st nd)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1176 (setq results (cons
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1177 (cons
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1178 (cons "mm-filename" fname) headers) results)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1179 results))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1180
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1181 (defun mm-format-multipart-as-html (&optional buf type)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1182 (if buf (set-buffer buf))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1183 (let* ((boundary (if (string-match
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1184 "boundary[ \t]*=[ \t\"]*\\([^ \"\t\n]+\\)"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1185 type)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1186 (regexp-quote
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1187 (substring type (match-beginning 1) (match-end 1)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1188 (parts (mm-find-available-multiparts boundary)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1189 (erase-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1190 (insert "<html>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1191 " <head>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1192 " <title>Multipart Message</title>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1193 " </head>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1194 " <body>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1195 " <h1> Multipart message encountered </h1>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1196 " <p> I have encountered a multipart MIME message.\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1197 " The following parts have been detected. Please\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1198 " select which one you want to view.\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1199 " </p>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1200 " <ul>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1201 (mapconcat
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1202 (function (lambda (x)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1203 (concat " <li> <a href=\"file:"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1204 (cdr (assoc "mm-filename" x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1205 "\">"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1206 (or (cdr (assoc "content-description" x)) "")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1207 "--"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1208 (or (cdr (assoc "content-type" x))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1209 "unknown type")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1210 "</a> </li>")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1211 parts "\n")
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1212 " </ul>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1213 " </body>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1214 "</html>\n"
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1215 "<!-- Automatically generated by MM v" mm-version "-->\n")))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1216
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1217 (defun mm-multipart-viewer ()
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1218 (mm-format-multipart-as-html
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1219 (current-buffer)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1220 (cdr (assoc "content-type" url-current-mime-headers)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1221 (let ((w3-working-buffer (current-buffer)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1222 (w3-prepare-buffer)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1223
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1224 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1225 ;;; Transfer encodings we can decrypt automatically
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1226 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1227 (defun mm-decode-quoted-printable (&optional st nd)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1228 (interactive)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1229 (setq st (or st (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1230 nd (or nd (point-max)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1231 (save-restriction
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1232 (narrow-to-region st nd)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1233 (save-excursion
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1234 (let ((buffer-read-only nil))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1235 (goto-char (point-min))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1236 (while (re-search-forward "=[0-9A-F][0-9A-F]" nil t)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1237 (replace-match
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1238 (char-to-string
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1239 (+
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1240 (* 16 (mm-hex-char-to-integer
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1241 (char-after (1+ (match-beginning 0)))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1242 (mm-hex-char-to-integer
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1243 (char-after (1- (match-end 0))))))))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1244
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1245 ;; Taken from hexl.el.
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1246 (defun mm-hex-char-to-integer (character)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1247 "Take a char and return its value as if it was a hex digit."
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1248 (if (and (>= character ?0) (<= character ?9))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1249 (- character ?0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1250 (let ((ch (logior character 32)))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1251 (if (and (>= ch ?a) (<= ch ?f))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1252 (- ch (- ?a 10))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1253 (error (format "Invalid hex digit `%c'." ch))))))
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1254
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1255
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1256 (require 'base64)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents:
diff changeset
1257 (provide 'mm)