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)
43 (let ((b (point-marker))
46 (put-image (mm-get-image handle
) b
)
47 (mm-handle-set-undisplayer
49 `(lambda () (remove-images ,b
(1+ ,b
))))))
51 (defun mm-inline-image-xemacs (handle)
53 (annot (make-annotation (mm-get-image handle
) nil
'text
))
56 (mm-handle-set-undisplayer
59 (let (buffer-read-only)
60 (delete-annotation ,annot
)
61 (delete-region ,(set-marker (make-marker) b
)
62 ,(set-marker (make-marker) (point))))))
63 (set-extent-property annot
'mm t
)
64 (set-extent-property annot
'duplicable t
)))
67 (if (featurep 'xemacs
)
68 (defalias 'mm-inline-image
'mm-inline-image-xemacs
)
69 (defalias 'mm-inline-image
'mm-inline-image-emacs
)))
71 (defvar mm-w3-setup nil
)
79 (setq mm-w3-setup t
)))
81 (defun mm-inline-text (handle)
82 (let ((type (mm-handle-media-subtype handle
))
83 text buffer-read-only
)
87 (setq text
(mm-get-part handle
))
89 (url-standalone-mode t
)
91 (url-generic-parse-url (format "cid:%s" (mm-handle-id handle
))))
92 (width (window-width))
93 (charset (mail-content-type-get
94 (mm-handle-type handle
) 'charset
)))
98 (narrow-to-region b
(point))
99 (goto-char (point-min))
100 (if (or (and (boundp 'w3-meta-content-type-charset-regexp
)
102 w3-meta-content-type-charset-regexp nil t
))
103 (and (boundp 'w3-meta-charset-content-type-regexp
)
105 w3-meta-charset-content-type-regexp nil t
)))
106 (setq charset
(or (w3-coding-system-for-mime-charset
107 (buffer-substring-no-properties
111 (delete-region (point-min) (point-max))
112 (insert (mm-decode-string text charset
))
113 (save-window-excursion
115 (let ((w3-strict-width width
)
116 ;; Don't let w3 set the global version of
118 (fill-column fill-column
)
119 (url-standalone-mode t
))
121 (w3-region (point-min) (point-max))
123 (mm-handle-set-undisplayer
126 (let (buffer-read-only)
127 (if (functionp 'remove-specifier
)
128 (mapcar (lambda (prop)
130 (face-property 'default prop
)
132 '(background background-pixmap foreground
)))
133 (delete-region ,(point-min-marker)
134 ,(point-max-marker)))))))))
135 ((or (equal type
"enriched")
136 (equal type
"richtext"))
138 (mm-with-unibyte-buffer
139 (mm-insert-part handle
)
140 (save-window-excursion
141 (enriched-decode (point-min) (point-max))
142 (setq text
(buffer-string)))))
143 (mm-insert-inline handle text
))
144 ((equal type
"x-vcard")
148 (if (fboundp 'vcard-pretty-print
)
149 (vcard-pretty-print (mm-get-part handle
))
151 (vcard-parse-string (mm-get-part handle
)
152 'vcard-standard-filter
))))))
155 (charset (mail-content-type-get
156 (mm-handle-type handle
) 'charset
)))
157 (if (or (eq charset
'gnus-decoded
)
158 ;; This is probably not entirely correct, but
159 ;; makes rfc822 parts with embedded multiparts work.
160 (eq mail-parse-charset
'gnus-decoded
))
161 (mm-insert-part handle
)
162 (insert (mm-decode-string (mm-get-part handle
) charset
)))
163 (when (and (equal type
"plain")
164 (equal (cdr (assoc 'format
(mm-handle-type handle
)))
167 (narrow-to-region b
(point))
170 (goto-char (point-max))))
172 (narrow-to-region b
(point))
173 (set-text-properties (point-min) (point-max) nil
)
174 (mm-handle-set-undisplayer
177 (let (buffer-read-only)
178 (delete-region ,(point-min-marker)
179 ,(point-max-marker)))))))))))
181 (defun mm-insert-inline (handle text
)
182 "Insert TEXT inline from HANDLE."
185 (mm-handle-set-undisplayer
188 (let (buffer-read-only)
189 (delete-region ,(set-marker (make-marker) b
)
190 ,(set-marker (make-marker) (point))))))))
192 (defun mm-inline-audio (handle)
193 (message "Not implemented"))
195 (defun mm-view-sound-file ()
196 (message "Not implemented"))
198 (defun mm-w3-prepare-buffer ()
200 (let ((url-standalone-mode t
))
201 (w3-prepare-buffer)))
203 (defun mm-view-message ()
204 (mm-enable-multibyte)
206 (let (gnus-article-mime-handles)
207 ;; Double decode problem may happen. See mm-inline-message.
208 (run-hooks 'gnus-article-decode-hook
)
209 (gnus-article-prepare-display)
210 (setq handles gnus-article-mime-handles
))
212 (setq gnus-article-mime-handles
213 (nconc gnus-article-mime-handles
214 (if (listp (car handles
))
215 handles
(list handles
))))))
217 (goto-char (point-min)))
219 (defun mm-inline-message (handle)
221 (charset (mail-content-type-get
222 (mm-handle-type handle
) 'charset
))
223 gnus-displaying-mime handles
)
226 (setq charset
(intern (downcase charset
)))
227 (when (eq charset
'us-ascii
)
231 (narrow-to-region b b
)
232 (mm-insert-part handle
)
233 (let (gnus-article-mime-handles
234 ;; disable prepare hook
235 gnus-article-prepare-hook
236 (gnus-newsgroup-charset
237 (or charset gnus-newsgroup-charset
)))
238 (run-hooks 'gnus-article-decode-hook
)
239 (gnus-article-prepare-display)
240 (setq handles gnus-article-mime-handles
))
241 (goto-char (point-max))
244 (insert "----------\n\n")
246 (setq gnus-article-mime-handles
247 (nconc gnus-article-mime-handles
248 (if (listp (car handles
))
249 handles
(list handles
)))))
250 (mm-handle-set-undisplayer
253 (let (buffer-read-only)
254 (if (fboundp 'remove-specifier
)
255 ;; This is only valid on XEmacs.
256 (mapcar (lambda (prop)
258 (face-property 'default prop
) (current-buffer)))
259 '(background background-pixmap foreground
)))
260 (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
262 (defun mm-display-inline-fontify (handle mode
)
265 (mm-insert-part handle
)
267 (font-lock-fontify-buffer)
268 (when (fboundp 'extent-list
)
269 (map-extents (lambda (ext ignored
)
270 (set-extent-property ext
'duplicable t
)
272 nil nil nil nil nil
'text-prop
))
273 (setq text
(buffer-string)))
274 (mm-insert-inline handle text
)))
276 (defun mm-display-patch-inline (handle)
277 (mm-display-inline-fontify handle
'diff-mode
))
279 (defun mm-display-elisp-inline (handle)
280 (mm-display-inline-fontify handle
'emacs-lisp-mode
))
284 ;; mm-view.el ends here