nntp.el (nntp-open-connection): Set TCP keepalive option.
[gnus] / lisp / mailcap.el
1 ;;; mailcap.el --- MIME media types configuration
2
3 ;; Copyright (C) 1998-2011 Free Software Foundation, Inc.
4
5 ;; Author: William M. Perry <wmperry@aventail.com>
6 ;;      Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; Keywords: news, mail, multimedia
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;; Provides configuration of MIME media types from directly from Lisp
27 ;; and via the usual mailcap mechanism (RFC 1524).  Deals with
28 ;; mime.types similarly.
29
30 ;;; Code:
31
32 (eval-when-compile (require 'cl))
33 (autoload 'mail-header-parse-content-type "mail-parse")
34
35 ;; `mm-delete-duplicates' is an alias for `delete-dups' in Emacs 22.
36 (defalias 'mailcap-delete-duplicates
37   (if (fboundp 'delete-dups)
38       'delete-dups
39     (autoload 'mm-delete-duplicates "mm-util")
40     'mm-delete-duplicates))
41
42 ;; `mailcap-replace-in-string' is an alias like `gnus-replace-in-string'.
43 (eval-and-compile
44   (cond
45    ((fboundp 'replace-regexp-in-string)
46     (defun mailcap-replace-in-string  (string regexp newtext &optional literal)
47       "Replace all matches for REGEXP with NEWTEXT in STRING.
48 If LITERAL is non-nil, insert NEWTEXT literally.  Return a new
49 string containing the replacements.
50 This is a compatibility function for different Emacsen."
51       (replace-regexp-in-string regexp newtext string nil literal)))
52    ((fboundp 'replace-in-string)
53     (defalias 'mailcap-replace-in-string 'replace-in-string))))
54
55 (defgroup mailcap nil
56   "Definition of viewers for MIME types."
57   :version "21.1"
58   :group 'mime)
59
60 (defvar mailcap-parse-args-syntax-table
61   (let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
62     (modify-syntax-entry ?' "\"" table)
63     (modify-syntax-entry ?` "\"" table)
64     (modify-syntax-entry ?{ "(" table)
65     (modify-syntax-entry ?} ")" table)
66     table)
67   "A syntax table for parsing SGML attributes.")
68
69 (eval-and-compile
70   (when (featurep 'xemacs)
71     (condition-case nil
72         (require 'lpr)
73       (error nil))))
74
75 (defvar mailcap-print-command
76   (mapconcat 'identity
77              (cons (if (boundp 'lpr-command)
78                        lpr-command
79                      "lpr")
80                    (when (boundp 'lpr-switches)
81                      (if (stringp lpr-switches)
82                          (list lpr-switches)
83                        lpr-switches)))
84              " ")
85   "Shell command (including switches) used to print Postscript files.")
86
87 ;; Postpone using defcustom for this as it's so big and we essentially
88 ;; have to have two copies of the data around then.  Perhaps just
89 ;; customize the Lisp viewers and rely on the normal configuration
90 ;; files for the rest?  -- fx
91 (defvar mailcap-mime-data
92   `(("application"
93      ("vnd.ms-excel"
94       (viewer . "gnumeric %s")
95       (test   . (getenv "DISPLAY"))
96       (type . "application/vnd.ms-excel"))
97      ("x-x509-ca-cert"
98       (viewer . ssl-view-site-cert)
99       (test . (fboundp 'ssl-view-site-cert))
100       (type . "application/x-x509-ca-cert"))
101      ("x-x509-user-cert"
102       (viewer . ssl-view-user-cert)
103       (test . (fboundp 'ssl-view-user-cert))
104       (type . "application/x-x509-user-cert"))
105      ("octet-stream"
106       (viewer . mailcap-save-binary-file)
107       (non-viewer . t)
108       (type . "application/octet-stream"))
109      ("dvi"
110       (viewer . "xdvi -safer %s")
111       (test   . (eq window-system 'x))
112       ("needsx11")
113       (type   . "application/dvi")
114       ("print" . "dvips -qRP %s"))
115      ("dvi"
116       (viewer . "dvitty %s")
117       (test   . (not (getenv "DISPLAY")))
118       (type   . "application/dvi")
119       ("print" . "dvips -qRP %s"))
120      ("emacs-lisp"
121       (viewer . mailcap-maybe-eval)
122       (type   . "application/emacs-lisp"))
123      ("x-emacs-lisp"
124       (viewer . mailcap-maybe-eval)
125       (type   . "application/x-emacs-lisp"))
126      ("x-tar"
127       (viewer . mailcap-save-binary-file)
128       (non-viewer . t)
129       (type   . "application/x-tar"))
130      ("x-latex"
131       (viewer . tex-mode)
132       (test   . (fboundp 'tex-mode))
133       (type   . "application/x-latex"))
134      ("x-tex"
135       (viewer . tex-mode)
136       (test   . (fboundp 'tex-mode))
137       (type   . "application/x-tex"))
138      ("latex"
139       (viewer . tex-mode)
140       (test   . (fboundp 'tex-mode))
141       (type   . "application/latex"))
142      ("tex"
143       (viewer . tex-mode)
144       (test   . (fboundp 'tex-mode))
145       (type   . "application/tex"))
146      ("texinfo"
147       (viewer . texinfo-mode)
148       (test   . (fboundp 'texinfo-mode))
149       (type   . "application/tex"))
150      ("zip"
151       (viewer . mailcap-save-binary-file)
152       (non-viewer . t)
153       (type   . "application/zip")
154       ("copiousoutput"))
155      ("pdf"
156       (viewer . "gv -safer %s")
157       (type . "application/pdf")
158       (test . window-system)
159       ("print" . ,(concat "pdf2ps %s - | " mailcap-print-command)))
160      ("pdf"
161       (viewer . "gpdf %s")
162       (type . "application/pdf")
163       ("print" . ,(concat "pdftops %s - | " mailcap-print-command))
164       (test . (eq window-system 'x)))
165      ("pdf"
166       (viewer . "xpdf %s")
167       (type . "application/pdf")
168       ("print" . ,(concat "pdftops %s - | " mailcap-print-command))
169       (test . (eq window-system 'x)))
170      ("pdf"
171       (viewer . ,(concat "pdftotext %s -"))
172       (type   . "application/pdf")
173       ("print" . ,(concat "pdftops %s - | " mailcap-print-command))
174       ("copiousoutput"))
175      ("postscript"
176       (viewer . "gv -safer %s")
177       (type . "application/postscript")
178       (test   . window-system)
179       ("print" . ,(concat mailcap-print-command " %s"))
180       ("needsx11"))
181      ("postscript"
182       (viewer . "ghostview -dSAFER %s")
183       (type . "application/postscript")
184       (test   . (eq window-system 'x))
185       ("print" . ,(concat mailcap-print-command " %s"))
186       ("needsx11"))
187      ("postscript"
188       (viewer . "ps2ascii %s")
189       (type . "application/postscript")
190       (test . (not (getenv "DISPLAY")))
191       ("print" . ,(concat mailcap-print-command " %s"))
192       ("copiousoutput"))
193      ("sieve"
194       (viewer . sieve-mode)
195       (test   . (fboundp 'sieve-mode))
196       (type   . "application/sieve"))
197      ("pgp-keys"
198       (viewer . "gpg --import --interactive --verbose")
199       (type   . "application/pgp-keys")
200       ("needsterminal")))
201     ("audio"
202      ("x-mpeg"
203       (viewer . "maplay %s")
204       (type   . "audio/x-mpeg"))
205      (".*"
206       (viewer . "showaudio")
207       (type   . "audio/*")))
208     ("message"