1 ;;; mailcap.el --- MIME media types configuration
2 ;; Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: William M. Perry <wmperry@aventail.com>
5 ;; Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news, mail, multimedia
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; Provides configuration of MIME media types from directly from Lisp
28 ;; and via the usual mailcap mechanism (RFC 1524). Deals with
29 ;; mime.types similarly.
33 (eval-when-compile (require 'cl
))
38 "Definition of viewers for MIME types."
42 (defvar mailcap-parse-args-syntax-table
43 (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table
)))
44 (modify-syntax-entry ?
' "\"" table
)
45 (modify-syntax-entry ?
` "\"" table
)
46 (modify-syntax-entry ?
{ "(" table
)
47 (modify-syntax-entry ?
} ")" table
)
49 "A syntax table for parsing sgml attributes.")
51 ;; Postpone using defcustom for this as it's so big and we essentially
52 ;; have to have two copies of the data around then. Perhaps just
53 ;; customize the Lisp viewers and rely on the normal configuration
54 ;; files for the rest? -- fx
55 (defvar mailcap-mime-data
58 (viewer . ssl-view-site-cert
)
59 (test .
(fboundp 'ssl-view-site-cert
))
60 (type .
"application/x-x509-ca-cert"))
62 (viewer . ssl-view-user-cert
)
63 (test .
(fboundp 'ssl-view-user-cert
))
64 (type .
"application/x-x509-user-cert"))
66 (viewer . mailcap-save-binary-file
)
68 (type .
"application/octet-stream"))
69 ;;; XEmacs says `ns' device-type not implemented.
71 ;; (viewer . "open %s")
72 ;; (type . "application/dvi")
73 ;; (test . (eq (mm-device-type) 'ns)))
76 (test .
(eq (mm-device-type) 'x
))
78 (type .
"application/dvi"))
80 (viewer .
"dvitty %s")
81 (test .
(not (getenv "DISPLAY")))
82 (type .
"application/dvi"))
84 (viewer . mailcap-maybe-eval
)
85 (type .
"application/emacs-lisp"))
87 (viewer . mailcap-save-binary-file
)
89 (type .
"application/x-tar"))
92 (test .
(fboundp 'tex-mode
))
93 (type .
"application/x-latex"))
96 (test .
(fboundp 'tex-mode
))
97 (type .
"application/x-tex"))
100 (test .
(fboundp 'tex-mode
))
101 (type .
"application/latex"))
104 (test .
(fboundp 'tex-mode
))
105 (type .
"application/tex"))
107 (viewer . texinfo-mode
)
108 (test .
(fboundp 'texinfo-mode
))
109 (type .
"application/tex"))
111 (viewer . mailcap-save-binary-file
)
113 (type .
"application/zip")
115 ;; Prefer free viewers.
118 (type .
"application/pdf")
119 (test . window-system
))
122 (type .
"application/pdf")
123 (test .
(eq (mm-device-type) 'x
)))
125 (viewer .
"acroread %s")
126 (type .
"application/pdf"))
127 ;;; XEmacs says `ns' device-type not implemented.
129 ;; (viewer . "open %s")
130 ;; (type . "application/postscript")
131 ;; (test . (eq (mm-device-type) 'ns)))
133 (viewer .
"gv -safer %s")
134 (type .
"application/postscript")
135 (test . window-system
)
138 (viewer .
"ghostview -dSAFER %s")
139 (type .
"application/postscript")
140 (test .
(eq (mm-device-type) 'x
))
143 (viewer .
"ps2ascii %s")
144 (type .
"application/postscript")
145 (test .
(not (getenv "DISPLAY")))
149 (viewer .
"maplay %s")
150 (type .
"audio/x-mpeg"))
152 (viewer .
"showaudio")
156 (viewer . mm-view-message
)
157 (test .
(and (featurep 'gnus
)
159 (type .
"message/rfc822"))
162 (test .
(fboundp 'vm-mode
))
163 (type .
"message/rfc822"))
166 (test .
(fboundp 'w3-mode
))
167 (type .
"message/rfc822"))
170 (type .
"message/rfc822")))
173 (viewer .
"xwud -in %s")
174 (type .
"image/x-xwd")
175 ("compose" .
"xwd -frame > %s")
176 (test .
(eq (mm-device-type) 'x
))
179 (viewer .
"xwud -in %s")
180 (type .
"image/x-xwd")
181 ("compose" .
"xwd -frame > %s")
182 (test .
(eq (mm-device-type) 'x
))
185 (viewer .
"xwud -in %s")
186 (type .
"image/x-xwd")
187 ("compose" .
"xwd -frame > %s")
188 (test .
(eq (mm-device-type) 'x
))
190 ;;; XEmacs says `ns' device-type not implemented.
192 ;; (viewer . "aopen %s")
193 ;; (type . "image/*")
194 ;; (test . (eq (mm-device-type) 'ns)))
196 (viewer .
"display %s")
198 (test .
(eq (mm-device-type) 'x
))
203 (test .
(eq (mm-device-type) 'x
))
208 (test .
(fboundp 'w3-mode
))
209 (type .
"text/plain"))
212 (test .
(fboundp 'view-mode
))
213 (type .
"text/plain"))
215 (viewer . fundamental-mode
)
216 (type .
"text/plain"))
218 (viewer . enriched-decode-region
)
219 (test .
(fboundp 'enriched-decode
))
220 (type .
"text/enriched"))
222 (viewer . mm-w3-prepare-buffer
)
223 (test .
(fboundp 'w3-prepare-buffer
))
224 (type .
"text/html")))
227 (viewer .
"mpeg_play %s")
228 (type .
"video/mpeg")
229 (test .
(eq (mm-device-type) 'x
))
233 (viewer .
"webspace -remote %s -URL %u")
234 (type .
"x-world/x-vrml")
240 (type .
"archive/tar")
241 (test .
(fboundp 'tar-mode
)))))
242 "The mailcap structure is an assoc list of assoc lists.
243 1st assoc list is keyed on the major content-type
244 2nd assoc list is keyed on the minor content-type (which can be a regexp)
249 (\"postscript\" . <info>))
251 (\"plain\" . <info>)))
253 Where <info> is another assoc list of the various information
254 related to the mailcap RFC 1524. This is keyed on the lowercase
255 attribute name (viewer, test, etc). This looks like:
256 ((viewer . VIEWERINFO)
261 Where VIEWERINFO specifies how the content-type is viewed. Can be
262 a string, in which case it is run through a shell, with
263 appropriate parameters, or a symbol, in which case the symbol is
264 `funcall'ed, with the buffer as an argument.
266 TESTINFO is a test for the viewer's applicability, or nil. If nil, it
267 means the viewer is always valid. If it is a Lisp function, it is
268 called with a list of items from any extra fields from the
269 Content-Type header as argument to return a boolean value for the
270 validity. Otherwise, if it is a non-function Lisp symbol or list
271 whose car is a symbol, it is `eval'led to yield the validity. If it
272 is a string or list of strings, it represents a shell command to run
273 to return a true or false shell value for the validity.")
275 (defcustom mailcap-download-directory nil
276 "*Directory to which `mailcap-save-binary-file' downloads files by default.
277 nil means your home directory."
278 :type
'(choice (const :tag
"Home directory" nil
)
283 ;;; Utility functions
286 (defun mailcap-save-binary-file ()
287 (goto-char (point-min))
289 (let ((file (read-file-name
290 "Filename to save as: "
291 (or mailcap-download-directory
"~/")))
292 (require-final-newline nil
))
293 (write-region (point-min) (point-max) file
))
294 (kill-buffer (current-buffer))))
296 (defvar mailcap-maybe-eval-warning
299 This MIME part contains untrusted and possibly harmful content.
300 If you evaluate the Emacs Lisp code contained in it, a lot of nasty
301 things can happen. Please examine the code very carefully before you
302 instruct Emacs to evaluate it. You can browse the buffer containing
303 the code using \\[scroll-other-window].
305 If you are unsure what to do, please answer \"no\"."
306 "Text of warning message displayed by `mailcap-maybe-eval'.
307 Make sure that this text consists only of few text lines. Otherwise,
308 Gnus might fail to display all of it.")
310 (defun mailcap-maybe-eval ()
311 "Maybe evaluate a buffer of Emacs Lisp code."
312 (let ((lisp-buffer (current-buffer)))
313 (goto-char (point-min))
315 (save-window-excursion
316 (delete-other-windows)
317 (let ((buffer (get-buffer-create (generate-new-buffer-name
320 (with-current-buffer buffer
321 (insert (substitute-command-keys
322 mailcap-maybe-eval-warning
))
323 (goto-char (point-min))
324 (display-buffer buffer
)
325 (yes-or-no-p "This is potentially dangerous emacs-lisp code, evaluate it? "))
326 (kill-buffer buffer
))))
327 (eval-buffer (current-buffer)))
328 (when (buffer-live-p lisp-buffer
)
329 (with-current-buffer lisp-buffer
330 (emacs-lisp-mode)))))
334 ;;; The mailcap parser
337 (defun mailcap-replace-regexp (regexp to-string
)
338 ;; Quiet replace-regexp.
339 (goto-char (point-min))
340 (while (re-search-forward regexp nil t
)
341 (replace-match to-string t nil
)))
343 (defvar mailcap-parsed-p nil
)
345 (defun mailcap-parse-mailcaps (&optional path force
)
346 "Parse out all the mailcaps specified in a path string PATH.
347 Components of PATH are separated by the `path-separator' character
348 appropriate for this system. If FORCE, re-parse even if already
349 parsed. If PATH is omitted, use the value of environment variable
350 MAILCAPS if set; otherwise (on Unix) use the path from RFC 1524, plus
351 /usr/local/etc/mailcap."
352 (interactive (list nil t
))
353 (when (or (not mailcap-parsed-p
)
357 ((getenv "MAILCAPS") (setq path
(getenv "MAILCAPS")))
358 ((memq system-type
'(ms-dos ms-windows windows-nt
))
359 (setq path
'("~/.mailcap" "~/mail.cap" "~/etc/mail.cap")))
361 ;; This is per RFC 1524, specifically
362 ;; with /usr before /usr/local.
363 '("~/.mailcap" "/etc/mailcap" "/usr/etc/mailcap"
364 "/usr/local/etc/mailcap"))))
365 (let ((fnames (reverse
367 (delete "" (split-string path path-separator
))
371 (setq fname
(car fnames
))
372 (if (and (file-readable-p fname
)
373 (file-regular-p fname
))
374 (mailcap-parse-mailcap fname
))
375 (setq fnames
(cdr fnames
))))
376 (setq mailcap-parsed-p t
)))
378 (defun mailcap-parse-mailcap (fname)
379 "Parse out the mailcap file specified by FNAME."
380 (let (major ; The major mime type (image/audio/etc)
381 minor
; The minor mime type (gif, basic, etc)
382 save-pos
; Misc saved positions used in parsing
383 viewer
; How to view this mime type
384 info
; Misc info about this mime type
387 (insert-file-contents fname
)
388 (set-syntax-table mailcap-parse-args-syntax-table
)
389 (mailcap-replace-regexp "#.*" "") ; Remove all comments
390 (mailcap-replace-regexp "\\\\[ \t]*\n" " ") ; And collapse spaces
391 (mailcap-replace-regexp "\n+" "\n") ; And blank lines
392 (goto-char (point-max))
393 (skip-chars-backward " \t\n")
394 (delete-region (point) (point-max))
396 (skip-chars-backward " \t\n")
398 (setq save-pos
(point)
400 (skip-chars-forward "^/; \t\n")
401 (downcase-region save-pos
(point))
402 (setq major
(buffer-substring save-pos
(point)))
403 (skip-chars-forward " \t")
405 (when (eq (char-after) ?
/)
407 (skip-chars-forward " \t")
408 (setq save-pos
(point))
409 (skip-chars-forward "^; \t\n")
410 (downcase-region save-pos
(point))
413 ((eq ?
* (or (char-after save-pos
) 0)) ".*")
414 ((= (point) save-pos
) ".*")
415 (t (regexp-quote (buffer-substring save-pos
(point)))))))
416 (skip-chars-forward " \t")
417 ;;; Got the major/minor chunks, now for the viewers/etc
418 ;;; The first item _must_ be a viewer, according to the
419 ;;; RFC for mailcap files (#1524)
421 (when (eq (char-after) ?\
;)
423 (skip-chars-forward " \t")
424 (setq save-pos
(point))
425 (skip-chars-forward "^;\n")
427 (while (eq (char-before) ?
\\)
428 (backward-delete-char 1)
430 (skip-chars-forward "^;\n"))
431 (if (eq (or (char-after save-pos
) 0) ?
')
433 (narrow-to-region (1+ save-pos
) (point))
434 (goto-char (point-min))
436 (read (current-buffer))
437 (goto-char (point-max))
439 (setq viewer
(buffer-substring save-pos
(point)))))
440 (setq save-pos
(point))
442 (unless (equal viewer
"")
443 (setq info
(nconc (list (cons 'viewer viewer
)
444 (cons 'type
(concat major
"/"
445 (if (string= minor
".*")
447 (mailcap-parse-mailcap-extras save-pos
(point))))
448 (mailcap-mailcap-entry-passes-test info
)
449 (mailcap-add-mailcap-entry major minor info
))
450 (beginning-of-line)))))
452 (defun mailcap-parse-mailcap-extras (st nd
)
453 "Grab all the extra stuff from a mailcap entry."
457 results
; Assoc list of results
458 name-pos
; Start of XXXX= position
459 val-pos
; Start of value position
460 done
; Found end of \'d ;s?
463 (narrow-to-region st nd
)
464 (goto-char (point-min))
465 (skip-chars-forward " \n\t;")
468 (setq name-pos
(point))
469 (skip-chars-forward "^ \n\t=;")
470 (downcase-region name-pos
(point))
471 (setq name
(buffer-substring name-pos
(point)))
472 (skip-chars-forward " \t\n")
473 (if (not (eq (char-after (point)) ?
=)) ; There is no value
475 (skip-chars-forward " \t\n=")
476 (setq val-pos
(point))
477 (if (memq (char-after val-pos
) '(?
\" ?
'))
479 (setq val-pos
(1+ val-pos
))
484 (error (goto-char (point-max)))))
486 (skip-chars-forward "^;")
487 (if (eq (char-after (1- (point))) ?
\\ )
489 (subst-char-in-region (1- (point)) (point) ?
\\ ?
)
490 (skip-chars-forward ";"))
492 (setq value
(buffer-substring val-pos
(point))))
493 (setq results
(cons (cons name value
) results
))
494 (skip-chars-forward " \";\n\t"))
497 (defun mailcap-mailcap-entry-passes-test (info)
498 "Return non-nil iff mailcap entry INFO passes its test clause.
499 Also return non-nil if no test clause is present."
500 (let ((test (assq 'test info
)) ; The test clause
502 (setq status
(and test
(split-string (cdr test
) " ")))
503 (if (and (or (assoc "needsterm" info
)
504 (assoc "needsterminal" info
)
505 (assoc "needsx11" info
))
506 (not (getenv "DISPLAY")))
509 ((and (equal (nth 0 status
) "test")
510 (equal (nth 1 status
) "-n")
511 (or (equal (nth 2 status
) "$DISPLAY")
512 (equal (nth 2 status
) "\"$DISPLAY\"")))
513 (setq status
(if (getenv "DISPLAY") t nil
)))
514 ((and (equal (nth 0 status
) "test")
515 (equal (nth 1 status
) "-z")
516 (or (equal (nth 2 status
) "$DISPLAY")
517 (equal (nth 2 status
) "\"$DISPLAY\"")))
518 (setq status
(if (getenv "DISPLAY") nil t
)))
521 (and test
(listp test
) (setcdr test status
))))
524 ;;; The action routines.
527 (defun mailcap-possible-viewers (major minor
)
528 "Return a list of possible viewers from MAJOR for minor type MINOR."
533 ((equal (car (car major
)) minor
)
534 (setq exact
(cons (cdr (car major
)) exact
)))
535 ((and minor
(string-match (car (car major
)) minor
))
536 (setq wildcard
(cons (cdr (car major
)) wildcard
))))
537 (setq major
(cdr major
)))
538 (nconc exact wildcard
)))
540 (defun mailcap-unescape-mime-test (test type-info
)
541 (let (save-pos save-chr subst
)
543 ((symbolp test
) test
)
544 ((and (listp test
) (symbolp (car test
))) test
)
546 (and (listp test
) (stringp (car test
))
547 (setq test
(mapconcat 'identity test
" "))))
550 (goto-char (point-min))
552 (skip-chars-forward "^%")
554 (progn (skip-chars-backward "\\\\")
556 0) ; It is an escaped %
559 (skip-chars-forward "%."))
560 (setq save-pos
(point))
561 (skip-chars-forward "%")
562 (setq save-chr
(char-after (point)))
564 ;; %s: name of a file for the body data
566 ;; %{<parameter name}: value of parameter in mailcap entry
567 ;; %n: number of sub-parts for multipart content-type
568 ;; %F: a set of content-type/filename pairs for multiparts
570 ((null save-chr
) nil
)
572 (delete-region save-pos
(progn (forward-char 1) (point)))
573 (insert (or (cdr (assq 'type type-info
)) "\"\"")))
574 ((memq save-chr
'(?M ?n ?F
))
575 (delete-region save-pos
(progn (forward-char 1) (point)))
579 (skip-chars-forward "^}")
580 (downcase-region (+ 2 save-pos
) (point))
581 (setq subst
(buffer-substring (+ 2 save-pos
) (point)))
582 (delete-region save-pos
(1+ (point)))
583 (insert (or (cdr (assoc subst type-info
)) "\"\"")))
586 (t (error "Bad value to mailcap-unescape-mime-test: %s" test
)))))
588 (defvar mailcap-viewer-test-cache nil
)
590 (defun mailcap-viewer-passes-test (viewer-info type-info
)
591 "Return non-nil iff viewer specified by VIEWER-INFO passes its test clause.
592 Also retun non-nil if it has no test clause. TYPE-INFO is an argument
593 to supply to the test."
594 (let* ((test-info (assq 'test viewer-info
))
595 (test (cdr test-info
))
597 (viewer (cdr (assoc 'viewer viewer-info
)))
598 (default-directory (expand-file-name "~/"))
599 status parsed-test cache result
)
600 (if (setq cache
(assoc test mailcap-viewer-test-cache
))
605 ((not test-info
) t
) ; No test clause
606 ((not test
) nil
) ; Already failed test
607 ((eq test t
) t
) ; Already passed test
608 ((functionp test
) ; Lisp function as test
609 (funcall test type-info
))
610 ((and (symbolp test
) ; Lisp variable as test
613 ((and (listp test
) ; List to be eval'd
614 (symbolp (car test
)))
617 (setq test
(mailcap-unescape-mime-test test type-info
)
618 test
(list shell-file-name nil nil nil
619 shell-command-switch test
)
620 status
(apply 'call-process test
))
622 (push (list otest result
) mailcap-viewer-test-cache
)
625 (defun mailcap-add-mailcap-entry (major minor info
)
626 (let ((old-major (assoc major mailcap-mime-data
)))
627 (if (null old-major
) ; New major area
628 (setq mailcap-mime-data
629 (cons (cons major
(list (cons minor info
)))
631 (let ((cur-minor (assoc minor old-major
)))
633 ((or (null cur-minor
) ; New minor area, or
634 (assq 'test info
)) ; Has a test, insert at beginning
635 (setcdr old-major
(cons (cons minor info
) (cdr old-major
))))
636 ((and (not (assq 'test info
)) ; No test info, replace completely
637 (not (assq 'test cur-minor
))
638 (equal (assq 'viewer info
) ; Keep alternative viewer
639 (assq 'viewer cur-minor
)))
640 (setcdr cur-minor info
))
642 (setcdr old-major
(cons (cons minor info
) (cdr old-major
))))))
645 (defun mailcap-add (type viewer
&optional test
)
646 "Add VIEWER as a handler for TYPE.
647 If TEST is not given, it defaults to t."
648 (let ((tl (split-string type
"/")))
649 (when (or (not (car tl
))
651 (error "%s is not a valid MIME type" type
))
652 (mailcap-add-mailcap-entry
655 (test .
,(if test test t
))
662 (defun mailcap-viewer-lessp (x y
)
663 "Return t iff viewer X is more desirable than viewer Y."
664 (let ((x-wild (string-match "[*?]" (or (cdr-safe (assq 'type x
)) "")))
665 (y-wild (string-match "[*?]" (or (cdr-safe (assq 'type y
)) "")))
666 (x-lisp (not (stringp (or (cdr-safe (assq 'viewer x
)) ""))))
667 (y-lisp (not (stringp (or (cdr-safe (assq 'viewer y
)) "")))))
669 ((and x-wild
(not y-wild
))
671 ((and (not x-wild
) y-wild
)
673 ((and (not y-lisp
) x-lisp
)
677 (defun mailcap-mime-info (string &optional request
)
678 "Get the MIME viewer command for STRING, return nil if none found.
679 Expects a complete content-type header line as its argument.
681 Second argument REQUEST specifies what information to return. If it is
682 nil or the empty string, the viewer (second field of the mailcap
683 entry) will be returned. If it is a string, then the mailcap field
684 corresponding to that string will be returned (print, description,
685 whatever). If a number, then all the information for this specific
686 viewer is returned. If `all', then all possible viewers for
687 this type is returned."
689 major
; Major encoding (text, etc)
690 minor
; Minor encoding (html, etc)
692 save-pos
; Misc. position during parse
693 major-info
; (assoc major mailcap-mime-data)
694 minor-info
; (assoc minor major-info)
695 test
; current test proc.
696 viewers
; Possible viewers
697 passed
; Viewers that passed the test
698 viewer
; The one and only viewer
701 (setq ctl
(mail-header-parse-content-type (or string
"text/plain")))
702 (setq major
(split-string (car ctl
) "/"))
703 (setq minor
(cadr major
)
705 (when (setq major-info
(cdr (assoc major mailcap-mime-data
)))
706 (when (setq viewers
(mailcap-possible-viewers major-info minor
))
707 (setq info
(mapcar (lambda (a) (cons (symbol-name (car a
))
711 (if (mailcap-viewer-passes-test (car viewers
) info
)
712 (setq passed
(cons (car viewers
) passed
)))
713 (setq viewers
(cdr viewers
)))
714 (setq passed
(sort passed
'mailcap-viewer-lessp
))
715 (setq viewer
(car passed
))))
716 (when (and (stringp (cdr (assq 'viewer viewer
)))
718 (setq viewer
(car passed
)))
720 ((and (null viewer
) (not (equal major
"default")) request
)
721 (mailcap-mime-info "default" request
))
722 ((or (null request
) (equal request
""))
723 (mailcap-unescape-mime-test (cdr (assq 'viewer viewer
)) info
))
725 (if (or (eq request
'test
) (eq request
'viewer
))
726 (mailcap-unescape-mime-test
727 (cdr-safe (assoc request viewer
)) info
)))
731 ;; MUST make a copy *sigh*, else we modify mailcap-mime-data
732 (setq viewer
(copy-sequence viewer
))
733 (let ((view (assq 'viewer viewer
))
734 (test (assq 'test viewer
)))
735 (if view
(setcdr view
(mailcap-unescape-mime-test (cdr view
) info
)))
736 (if test
(setcdr test
(mailcap-unescape-mime-test (cdr test
) info
))))
740 ;;; Experimental MIME-types parsing
743 (defvar mailcap-mime-extensions
744 '(("" .
"text/plain")
745 (".abs" .
"audio/x-mpeg")
746 (".aif" .
"audio/aiff")
747 (".aifc" .
"audio/aiff")
748 (".aiff" .
"audio/aiff")
749 (".ano" .
"application/x-annotator")
750 (".au" .
"audio/ulaw")
751 (".avi" .
"video/x-msvideo")
752 (".bcpio" .
"application/x-bcpio")
753 (".bin" .
"application/octet-stream")
754 (".cdf" .
"application/x-netcdr")
755 (".cpio" .
"application/x-cpio")
756 (".csh" .
"application/x-csh")
757 (".css" .
"text/css")
758 (".dvi" .
"application/x-dvi")
759 (".diff" .
"text/x-patch")
760 (".el" .
"application/emacs-lisp")
761 (".eps" .
"application/postscript")
762 (".etx" .
"text/x-setext")
763 (".exe" .
"application/octet-stream")
764 (".fax" .
"image/x-fax")
765 (".gif" .
"image/gif")
766 (".hdf" .
"application/x-hdf")
767 (".hqx" .
"application/mac-binhex40")
768 (".htm" .
"text/html")
769 (".html" .
"text/html")
770 (".icon" .
"image/x-icon")
771 (".ief" .
"image/ief")
772 (".jpg" .
"image/jpeg")
773 (".macp" .
"image/x-macpaint")
774 (".man" .
"application/x-troff-man")
775 (".me" .
"application/x-troff-me")
776 (".mif" .
"application/mif")
777 (".mov" .
"video/quicktime")
778 (".movie" .
"video/x-sgi-movie")
779 (".mp2" .
"audio/x-mpeg")
780 (".mp3" .
"audio/x-mpeg")
781 (".mp2a" .
"audio/x-mpeg2")
782 (".mpa" .
"audio/x-mpeg")
783 (".mpa2" .
"audio/x-mpeg2")
784 (".mpe" .
"video/mpeg")
785 (".mpeg" .
"video/mpeg")
786 (".mpega" .
"audio/x-mpeg")
787 (".mpegv" .
"video/mpeg")
788 (".mpg" .
"video/mpeg")
789 (".mpv" .
"video/mpeg")
790 (".ms" .
"application/x-troff-ms")
791 (".nc" .
"application/x-netcdf")
792 (".nc" .
"application/x-netcdf")
793 (".oda" .
"application/oda")
794 (".patch" .
"text/x-patch")
795 (".pbm" .
"image/x-portable-bitmap")
796 (".pdf" .
"application/pdf")
797 (".pgm" .
"image/portable-graymap")
798 (".pict" .
"image/pict")
799 (".png" .
"image/png")
800 (".pnm" .
"image/x-portable-anymap")
801 (".ppm" .
"image/portable-pixmap")
802 (".ps" .
"application/postscript")
803 (".qt" .
"video/quicktime")
804 (".ras" .
"image/x-raster")
805 (".rgb" .
"image/x-rgb")
806 (".rtf" .
"application/rtf")
807 (".rtx" .
"text/richtext")
808 (".sh" .
"application/x-sh")
809 (".sit" .
"application/x-stuffit")
810 (".snd" .
"audio/basic")
811 (".src" .
"application/x-wais-source")
812 (".tar" .
"archive/tar")
813 (".tcl" .
"application/x-tcl")
814 (".tex" .
"application/x-tex")
815 (".texi" .
"application/texinfo")
816 (".tga" .
"image/x-targa")
817 (".tif" .
"image/tiff")
818 (".tiff" .
"image/tiff")
819 (".tr" .
"application/x-troff")
820 (".troff" .
"application/x-troff")
821 (".tsv" .
"text/tab-separated-values")
822 (".txt" .
"text/plain")
823 (".vbs" .
"video/mpeg")
824 (".vox" .
"audio/basic")
825 (".vrml" .
"x-world/x-vrml")
826 (".wav" .
"audio/x-wav")
827 (".wrl" .
"x-world/x-vrml")
828 (".xbm" .
"image/xbm")
829 (".xpm" .
"image/xpm")
830 (".xwd" .
"image/windowdump")
831 (".zip" .
"application/zip")
832 (".ai" .
"application/postscript")
833 (".jpe" .
"image/jpeg")
834 (".jpeg" .
"image/jpeg"))
835 "An alist of file extensions and corresponding MIME content-types.
836 This exists for you to customize the information in Lisp. It is
837 merged with values from mailcap files by `mailcap-parse-mimetypes'.")
839 (defvar mailcap-mimetypes-parsed-p nil
)
841 (defun mailcap-parse-mimetypes (&optional path force
)
842 "Parse out all the mimetypes specified in a Unix-style path string PATH.
843 Components of PATH are separated by the `path-separator' character
844 appropriate for this system. If PATH is omitted, use the value of
845 environment variable MIMETYPES if set; otherwise use a default path.
846 If FORCE, re-parse even if already parsed."
847 (interactive (list nil t
))
848 (when (or (not mailcap-mimetypes-parsed-p
)
852 ((getenv "MIMETYPES") (setq path
(getenv "MIMETYPES")))
853 ((memq system-type
'(ms-dos ms-windows windows-nt
))
854 (setq path
'("~/mime.typ" "~/etc/mime.typ")))
856 ;; mime.types seems to be the normal name, definitely so
857 ;; on current GNUish systems. The search order follows
861 "/usr/etc/mime.types"
862 "/usr/local/etc/mime.types"
863 "/usr/local/www/conf/mime.types"
866 "/usr/etc/mime-types"
867 "/usr/local/etc/mime-types"
868 "/usr/local/www/conf/mime-types"))))
869 (let ((fnames (reverse (if (stringp path
)
870 (delete "" (split-string path path-separator
))
874 (setq fname
(car fnames
))
875 (if (and (file-readable-p fname
))
876 (mailcap-parse-mimetype-file fname
))
877 (setq fnames
(cdr fnames
))))
878 (setq mailcap-mimetypes-parsed-p t
)))
880 (defun mailcap-parse-mimetype-file (fname)
881 "Parse out a mime-types file FNAME."
882 (let (type ; The MIME type for this line
883 extns
; The extensions for this line
884 save-pos
; Misc. saved buffer positions
887 (insert-file-contents fname
)
888 (mailcap-replace-regexp "#.*" "")
889 (mailcap-replace-regexp "\n+" "\n")
890 (mailcap-replace-regexp "[ \t]+$" "")
891 (goto-char (point-max))
892 (skip-chars-backward " \t\n")
893 (delete-region (point) (point-max))
894 (goto-char (point-min))
896 (skip-chars-forward " \t\n")
897 (setq save-pos
(point))
898 (skip-chars-forward "^ \t\n")
899 (downcase-region save-pos
(point))
900 (setq type
(buffer-substring save-pos
(point)))
902 (skip-chars-forward " \t")
903 (setq save-pos
(point))
904 (skip-chars-forward "^ \t\n")
905 (setq extns
(cons (buffer-substring save-pos
(point)) extns
)))
907 (setq mailcap-mime-extensions
909 (cons (if (= (string-to-char (car extns
)) ?.
)
911 (concat "." (car extns
))) type
)
912 mailcap-mime-extensions
)
913 extns
(cdr extns
)))))))
915 (defun mailcap-extension-to-mime (extn)
916 "Return the MIME content type of the file extensions EXTN."
917 (mailcap-parse-mimetypes)
918 (if (and (stringp extn
)
919 (not (eq (string-to-char extn
) ?.
)))
920 (setq extn
(concat "." extn
)))
921 (cdr (assoc (downcase extn
) mailcap-mime-extensions
)))
924 (defalias 'mailcap-command-p
'executable-find
)
926 (defun mailcap-mime-types ()
927 "Return a list of MIME media types."
928 (mailcap-parse-mimetypes)
929 (mm-delete-duplicates
931 (mapcar 'cdr mailcap-mime-extensions
)
939 (let ((type (cdr (assq 'type
(cdr m
)))))
940 (if (equal (cadr (split-string type
"/"))
945 mailcap-mime-data
)))))
949 ;;; mailcap.el ends here