annotate lisp/w3/mm.el @ 102:a145efe76779 r20-1b3

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