1 ;;; mm-view.el --- Functions for viewing MIME objects
2 ;; Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
26 (eval-when-compile (require 'cl))
33 (autoload 'gnus-article-prepare-display "gnus-art")
34 (autoload 'vcard-parse-string "vcard")
35 (autoload 'vcard-format-string "vcard")
36 (autoload 'fill-flowed "flow-fill")
37 (autoload 'diff-mode "diff-mode"))
40 ;;; Functions for displaying various formats inline
42 (defun mm-inline-image-emacs (handle)
45 (string (copy-sequence "[MM-INLINED-IMAGE]"))
49 (setq overlay (make-overlay (point) (point) (current-buffer)))
50 (put-text-property 0 (length string) 'display (mm-get-image handle) string)
51 (overlay-put overlay 'before-string string)
53 (mm-handle-set-undisplayer
56 (let (buffer-read-only)
57 (delete-overlay ,overlay)
58 (delete-region ,(set-marker (make-marker) b)
59 ,(set-marker (make-marker) (point))))))))
61 (defun mm-inline-image-xemacs (handle)
63 (annot (make-annotation (mm-get-image handle) nil 'text))
66 (mm-handle-set-undisplayer
69 (let (buffer-read-only)
70 (delete-annotation ,annot)
71 (delete-region ,(set-marker (make-marker) b)
72 ,(set-marker (make-marker) (point))))))
73 (set-extent-property annot 'mm t)
74 (set-extent-property annot 'duplicable t)))
76 (defun mm-inline-image (handle)
78 (mm-inline-image-xemacs handle)
79 (mm-inline-image-emacs handle)))
81 (defvar mm-w3-setup nil)
89 (setq mm-w3-setup t)))
91 (defun mm-inline-text (handle)
92 (let ((type (mm-handle-media-subtype handle))
93 text buffer-read-only)
97 (setq text (mm-get-part handle))
99 (url-standalone-mode t)
101 (url-generic-parse-url (format "cid:%s" (mm-handle-id handle))))
102 (width (window-width))
103 (charset (mail-content-type-get
104 (mm-handle-type handle) 'charset)))
108 (narrow-to-region b (point))
109 (goto-char (point-min))
110 (if (or (and (boundp 'w3-meta-content-type-charset-regexp)
112 w3-meta-content-type-charset-regexp nil t))
113 (and (boundp 'w3-meta-charset-content-type-regexp)
115 w3-meta-charset-content-type-regexp nil t)))
116 (setq charset (w3-coding-system-for-mime-charset
117 (buffer-substring-no-properties
120 (delete-region (point-min) (point-max))
121 (insert (mm-decode-string text charset))
122 (save-window-excursion
124 (let ((w3-strict-width width)
125 (url-standalone-mode t))
127 (w3-region (point-min) (point-max))
129 (mm-handle-set-undisplayer
132 (let (buffer-read-only)
133 (if (functionp 'remove-specifier)
134 (mapcar (lambda (prop)
136 (face-property 'default prop)
138 '(background background-pixmap foreground)))
139 (delete-region ,(point-min-marker)
140 ,(point-max-marker)))))))))
141 ((or (equal type "enriched")
142 (equal type "richtext"))
144 (mm-with-unibyte-buffer
145 (mm-insert-part handle)
146 (save-window-excursion
147 (enriched-decode (point-min) (point-max))
148 (setq text (buffer-string)))))
149 (mm-insert-inline handle text))
150 ((equal type "x-vcard")
154 (if (fboundp 'vcard-pretty-print)
155 (vcard-pretty-print (mm-get-part handle))
157 (vcard-parse-string (mm-get-part handle)
158 'vcard-standard-filter))))))
161 (charset (mail-content-type-get
162 (mm-handle-type handle) 'charset)))
163 (if (eq charset 'gnus-decoded)
164 (mm-insert-part handle)
165 (insert (mm-decode-string (mm-get-part handle) charset)))
166 (when (and (equal type "plain")
167 (equal (cdr (assoc 'format (mm-handle-type handle)))
170 (narrow-to-region b (point))
173 (goto-char (point-max))))
175 (narrow-to-region b (point))
176 (set-text-properties (point-min) (point-max) nil)
177 (mm-handle-set-undisplayer
180 (let (buffer-read-only)
181 (delete-region ,(point-min-marker)
182 ,(point-max-marker)))))))))))
184 (defun mm-insert-inline (handle text)
185 "Insert TEXT inline from HANDLE."
188 (mm-handle-set-undisplayer
191 (let (buffer-read-only)
192 (delete-region ,(set-marker (make-marker) b)
193 ,(set-marker (make-marker) (point))))))))
195 (defun mm-inline-audio (handle)
196 (message "Not implemented"))
198 (defun mm-view-sound-file ()
199 (message "Not implemented"))
201 (defun mm-w3-prepare-buffer ()
203 (let ((url-standalone-mode t))
204 (w3-prepare-buffer)))
206 (defun mm-view-message ()
207 (mm-enable-multibyte)
209 (let (gnus-article-mime-handles)
210 ;; Double decode problem may happen. See mm-inline-message.
211 (run-hooks 'gnus-article-decode-hook)
212 (gnus-article-prepare-display)
213 (setq handles gnus-article-mime-handles))
215 (setq gnus-article-mime-handles
216 (nconc gnus-article-mime-handles
217 (if (listp (car handles))
218 handles (list handles))))))
220 (goto-char (point-min)))
222 (defun mm-inline-message (handle)
224 (charset (mail-content-type-get
225 (mm-handle-type handle) 'charset))
226 gnus-displaying-mime handles)
229 (setq charset (intern (downcase charset)))
230 (when (eq charset 'us-ascii)
234 (narrow-to-region b b)
235 (mm-insert-part handle)
236 (let (gnus-article-mime-handles
237 ;; disable prepare hook
238 gnus-article-prepare-hook
239 (gnus-newsgroup-charset
240 (or charset gnus-newsgroup-charset)))
241 (run-hooks 'gnus-article-decode-hook)
242 (gnus-article-prepare-display)
243 (setq handles gnus-article-mime-handles))
244 (goto-char (point-max))
247 (insert "----------\n\n")
249 (setq gnus-article-mime-handles
250 (nconc gnus-article-mime-handles
251 (if (listp (car handles))
252 handles (list handles)))))
253 (mm-handle-set-undisplayer
256 (let (buffer-read-only)
258 ;; This is only valid on XEmacs.
259 (mapcar (lambda (prop)
261 (face-property 'default prop) (current-buffer)))
262 '(background background-pixmap foreground))
264 (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
266 (defun mm-display-patch-inline (handle)
269 (mm-insert-part handle)
271 (font-lock-fontify-buffer)
272 (when (fboundp 'extent-list)
273 (map-extents (lambda (ext ignored)
274 (set-extent-property ext 'duplicable t)
276 nil nil nil nil nil 'text-prop))
277 (setq text (buffer-string)))
278 (mm-insert-inline handle text)))
282 ;; mm-view.el ends here