annotate lisp/url/mm.el @ 0:376386a54a3c r19-14

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