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 "x")
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 (string-match "XEmacs" (emacs-version))
68 (fset 'mm-inline-image 'mm-inline-image-xemacs)
69 (fset '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 (url-standalone-mode t))
118 (w3-region (point-min) (point-max))
120 (mm-handle-set-undisplayer
123 (let (buffer-read-only)
124 (if (functionp 'remove-specifier)
125 (mapcar (lambda (prop)
127 (face-property 'default prop)
129 '(background background-pixmap foreground)))
130 (delete-region ,(point-min-marker)
131 ,(point-max-marker)))))))))
132 ((or (equal type "enriched")
133 (equal type "richtext"))
135 (mm-with-unibyte-buffer
136 (mm-insert-part handle)
137 (save-window-excursion
138 (enriched-decode (point-min) (point-max))
139 (setq text (buffer-string)))))
140 (mm-insert-inline handle text))
141 ((equal type "x-vcard")
145 (if (fboundp 'vcard-pretty-print)
146 (vcard-pretty-print (mm-get-part handle))
148 (vcard-parse-string (mm-get-part handle)
149 'vcard-standard-filter))))))
152 (charset (mail-content-type-get
153 (mm-handle-type handle) 'charset)))
154 (if (eq charset 'gnus-decoded)
155 (mm-insert-part handle)
156 (insert (mm-decode-string (mm-get-part handle) charset)))
157 (when (and (equal type "plain")
158 (equal (cdr (assoc 'format (mm-handle-type handle)))
161 (narrow-to-region b (point))
164 (goto-char (point-max))))
166 (narrow-to-region b (point))
167 (set-text-properties (point-min) (point-max) nil)
168 (mm-handle-set-undisplayer
171 (let (buffer-read-only)
172 (delete-region ,(point-min-marker)
173 ,(point-max-marker)))))))))))
175 (defun mm-insert-inline (handle text)
176 "Insert TEXT inline from HANDLE."
179 (mm-handle-set-undisplayer
182 (let (buffer-read-only)
183 (delete-region ,(set-marker (make-marker) b)
184 ,(set-marker (make-marker) (point))))))))
186 (defun mm-inline-audio (handle)
187 (message "Not implemented"))
189 (defun mm-view-sound-file ()
190 (message "Not implemented"))
192 (defun mm-w3-prepare-buffer ()
194 (let ((url-standalone-mode t))
195 (w3-prepare-buffer)))
197 (defun mm-view-message ()
198 (mm-enable-multibyte)
200 (let (gnus-article-mime-handles)
201 ;; Double decode problem may happen. See mm-inline-message.
202 (run-hooks 'gnus-article-decode-hook)
203 (gnus-article-prepare-display)
204 (setq handles gnus-article-mime-handles))
206 (setq gnus-article-mime-handles
207 (nconc gnus-article-mime-handles
208 (if (listp (car handles))
209 handles (list handles))))))
211 (goto-char (point-min)))
213 (defun mm-inline-message (handle)
215 (charset (mail-content-type-get
216 (mm-handle-type handle) 'charset))
217 gnus-displaying-mime handles)
220 (setq charset (intern (downcase charset)))
221 (when (eq charset 'us-ascii)
225 (narrow-to-region b b)
226 (mm-insert-part handle)
227 (let (gnus-article-mime-handles
228 ;; disable prepare hook
229 gnus-article-prepare-hook
230 (gnus-newsgroup-charset
231 (or charset gnus-newsgroup-charset)))
232 (run-hooks 'gnus-article-decode-hook)
233 (gnus-article-prepare-display)
234 (setq handles gnus-article-mime-handles))
235 (goto-char (point-max))
238 (insert "----------\n\n")
240 (setq gnus-article-mime-handles
241 (nconc gnus-article-mime-handles
242 (if (listp (car handles))
243 handles (list handles)))))
244 (mm-handle-set-undisplayer
247 (let (buffer-read-only)
249 ;; This is only valid on XEmacs.
250 (mapcar (lambda (prop)
252 (face-property 'default prop) (current-buffer)))
253 '(background background-pixmap foreground))
255 (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
257 (defun mm-display-patch-inline (handle)
260 (mm-insert-part handle)
262 (font-lock-fontify-buffer)
263 (when (fboundp 'extent-list)
264 (map-extents (lambda (ext ignored)
265 (set-extent-property ext 'duplicable t)
267 nil nil nil nil nil 'text-prop))
268 (setq text (buffer-string)))
269 (mm-insert-inline handle text)))
273 ;; mm-view.el ends here