* lisp/simple.el (blink-matching-open): Use syntax-class.
[emacs.git] / lisp / mh-e / mh-gnus.el
blob3c12821853465338ce6e5f44be97e06460e6e940
1 ;;; mh-gnus.el --- make MH-E compatible with various versions of Gnus
3 ;; Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010
4 ;; Free Software Foundation, Inc.
6 ;; Author: Satyaki Das <satyaki@theforce.stanford.edu>
7 ;; Maintainer: Bill Wohler <wohler@newt.com>
8 ;; Keywords: mail
9 ;; See: mh-e.el
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;;; Commentary:
28 ;;; Change Log:
30 ;;; Code:
32 (require 'mh-e)
34 (mh-require 'gnus-util nil t)
35 (mh-require 'mm-bodies nil t)
36 (mh-require 'mm-decode nil t)
37 (mh-require 'mm-view nil t)
38 (mh-require 'mml nil t)
40 ;; Copy of function from gnus-util.el.
41 ;; TODO This is not in Gnus 5.11.
42 (defun-mh mh-gnus-local-map-property gnus-local-map-property (map)
43 "Return a list suitable for a text property list specifying keymap MAP."
44 (cond ((featurep 'xemacs) (list 'keymap map))
45 ((>= emacs-major-version 21) (list 'keymap map))
46 (t (list 'local-map map))))
48 ;; Copy of function from mm-decode.el.
49 (defun-mh mh-mm-merge-handles mm-merge-handles (handles1 handles2)
50 (append
51 (if (listp (car handles1))
52 handles1
53 (list handles1))
54 (if (listp (car handles2))
55 handles2
56 (list handles2))))
58 ;; Copy of function from mm-decode.el.
59 (defun-mh mh-mm-set-handle-multipart-parameter
60 mm-set-handle-multipart-parameter (handle parameter value)
61 ;; HANDLE could be a CTL.
62 (when handle
63 (put-text-property 0 (length (car handle)) parameter value
64 (car handle))))
66 ;; Copy of function from mm-view.el.
67 (defun-mh mh-mm-inline-text-vcard mm-inline-text-vcard (handle)
68 (let ((inhibit-read-only t))
69 (mm-insert-inline
70 handle
71 (concat "\n-- \n"
72 (ignore-errors
73 (if (fboundp 'vcard-pretty-print)
74 (vcard-pretty-print (mm-get-part handle))
75 (vcard-format-string
76 (vcard-parse-string (mm-get-part handle)
77 'vcard-standard-filter))))))))
79 ;; Function from mm-decode.el used in PGP messages. Just define it with older
80 ;; Gnus to avoid compiler warning.
81 (defun-mh mh-mm-possibly-verify-or-decrypt
82 mm-possibly-verify-or-decrypt (parts ctl)
83 nil)
85 ;; Copy of macro in mm-decode.el.
86 (defmacro-mh mh-mm-handle-multipart-ctl-parameter
87 mm-handle-multipart-ctl-parameter (handle parameter)
88 `(get-text-property 0 ,parameter (car ,handle)))
90 ;; Copy of function in mm-decode.el.
91 (defun-mh mh-mm-readable-p mm-readable-p (handle)
92 "Say whether the content of HANDLE is readable."
93 (and (< (with-current-buffer (mm-handle-buffer handle)
94 (buffer-size)) 10000)
95 (mm-with-unibyte-buffer
96 (mm-insert-part handle)
97 (and (eq (mm-body-7-or-8) '7bit)
98 (not (mh-mm-long-lines-p 76))))))
100 ;; Copy of function in mm-bodies.el.
101 (defun-mh mh-mm-long-lines-p mm-long-lines-p (length)
102 "Say whether any of the lines in the buffer is longer than LENGTH."
103 (save-excursion
104 (goto-char (point-min))
105 (end-of-line)
106 (while (and (not (eobp))
107 (not (> (current-column) length)))
108 (forward-line 1)
109 (end-of-line))
110 (and (> (current-column) length)
111 (current-column))))
113 (defun-mh mh-mm-keep-viewer-alive-p mm-keep-viewer-alive-p (handle)
114 ;; Released Gnus doesn't keep handles associated with externally displayed
115 ;; MIME parts. So this will always return nil.
116 nil)
118 (defun-mh mh-mm-destroy-parts mm-destroy-parts (list)
119 "Older versions of Emacs don't have this function."
120 nil)
122 (defun-mh mh-mm-uu-dissect-text-parts mm-uu-dissect-text-parts (handles)
123 "Emacs 21 and XEmacs don't have this function."
124 nil)
126 ;; Copy of function in mml.el.
127 (defun-mh mh-mml-minibuffer-read-disposition
128 mml-minibuffer-read-disposition (type &optional default filename)
129 (unless default
130 (setq default (mml-content-disposition type filename)))
131 (let ((disposition (completing-read
132 (format "Disposition (default %s): " default)
133 '(("attachment") ("inline") (""))
134 nil t nil nil default)))
135 (if (not (equal disposition ""))
136 disposition
137 default)))
139 ;; This is mm-save-part from Gnus 5.11 since that function in Emacs
140 ;; 21.2 is buggy (the args to read-file-name are incorrect) and the
141 ;; version in Emacs 22 is not consistent with C-x C-w in that you
142 ;; can't just specify a directory and have the right thing happen.
143 (defun mh-mm-save-part (handle &optional prompt)
144 "Write HANDLE to a file.
145 PROMPT overrides the default one used to ask user for a file name."
146 (let ((filename (or (mail-content-type-get
147 (mm-handle-disposition handle) 'filename)
148 (mail-content-type-get
149 (mm-handle-type handle) 'name)))
150 file)
151 (when filename
152 (setq filename (gnus-map-function mm-file-name-rewrite-functions
153 (file-name-nondirectory filename))))
154 (setq file
155 (read-file-name (or prompt "Save MIME part to: ")
156 (or mm-default-directory default-directory)
157 nil nil (or filename "")))
158 (setq mm-default-directory (file-name-directory file))
159 (and (or (not (file-exists-p file))
160 (yes-or-no-p (format "File %s already exists; overwrite? "
161 file)))
162 (progn
163 (mm-save-part-to-file handle file)
164 file))))
166 (defun mh-mm-text-html-renderer ()
167 "Find the renderer Gnus is using to display text/html MIME parts."
168 (or (and (boundp 'mm-inline-text-html-renderer) mm-inline-text-html-renderer)
169 (and (boundp 'mm-text-html-renderer) mm-text-html-renderer)))
171 (provide 'mh-gnus)
173 ;; Local Variables:
174 ;; no-byte-compile: t
175 ;; no-update-autoloads: t
176 ;; indent-tabs-mode: nil
177 ;; sentence-end-double-space: nil
178 ;; End:
180 ;; arch-tag: 1e3638af-cad3-4c69-8427-bc8eb6e5e4fa
181 ;;; mh-gnus.el ends here