annotate lisp/url/mm.el @ 7:c153ca296910

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