1 ;;; mm-view.el --- Functions for viewing MIME objects
2 ;; Copyright (C) 1998,99 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 'diff-mode "diff-mode"))
39 ;;; Functions for displaying various formats inline
42 (defun mm-inline-image (handle)
44 (annot (make-annotation (mm-get-image handle) nil 'text))
47 (mm-handle-set-undisplayer
50 (let (buffer-read-only)
51 (delete-annotation ,annot)
52 (delete-region ,(set-marker (make-marker) b)
53 ,(set-marker (make-marker) (point))))))
54 (set-extent-property annot 'mm t)
55 (set-extent-property annot 'duplicable t)))
57 (defvar mm-w3-setup nil)
65 (setq mm-w3-setup t)))
67 (defun mm-inline-text (handle)
68 (let ((type (mm-handle-media-subtype handle))
69 text buffer-read-only)
73 (setq text (mm-get-part handle))
75 (url-standalone-mode t)
77 (url-generic-parse-url (format "cid:%s" (mm-handle-id handle))))
78 (width (window-width))
79 (charset (mail-content-type-get
80 (mm-handle-type handle) 'charset)))
84 (narrow-to-region b (point))
85 (goto-char (point-min))
86 (if (or (and (boundp 'w3-meta-content-type-charset-regexp)
88 w3-meta-content-type-charset-regexp nil t))
89 (and (boundp 'w3-meta-charset-content-type-regexp)
91 w3-meta-charset-content-type-regexp nil t)))
92 (setq charset (w3-coding-system-for-mime-charset
93 (buffer-substring-no-properties
96 (delete-region (point-min) (point-max))
97 (insert (mm-decode-string text charset))
98 (save-window-excursion
100 (let ((w3-strict-width width)
101 (url-standalone-mode t))
103 (w3-region (point-min) (point-max))
105 (mm-handle-set-undisplayer
108 (let (buffer-read-only)
109 (if (functionp 'remove-specifier)
110 (mapcar (lambda (prop)
112 (face-property 'default prop)
114 '(background background-pixmap foreground)))
115 (delete-region ,(point-min-marker)
116 ,(point-max-marker)))))))))
117 ((or (equal type "enriched")
118 (equal type "richtext"))
120 (mm-with-unibyte-buffer
121 (mm-insert-part handle)
122 (save-window-excursion
123 (enriched-decode (point-min) (point-max))
124 (setq text (buffer-string)))))
125 (mm-insert-inline handle text))
126 ((equal type "x-vcard")
131 (vcard-parse-string (mm-get-part handle)
132 'vcard-standard-filter)))))
134 (setq text (mm-get-part handle))
136 (charset (mail-content-type-get
137 (mm-handle-type handle) 'charset)))
138 (insert (mm-decode-string text charset))
140 (narrow-to-region b (point))
141 (set-text-properties (point-min) (point-max) nil)
142 (mm-handle-set-undisplayer
145 (let (buffer-read-only)
146 (delete-region ,(point-min-marker)
147 ,(point-max-marker)))))))))))
149 (defun mm-insert-inline (handle text)
150 "Insert TEXT inline from HANDLE."
153 (mm-handle-set-undisplayer
156 (let (buffer-read-only)
157 (delete-region ,(set-marker (make-marker) b)
158 ,(set-marker (make-marker) (point))))))))
160 (defun mm-inline-audio (handle)
161 (message "Not implemented"))
163 (defun mm-view-sound-file ()
164 (message "Not implemented"))
166 (defun mm-w3-prepare-buffer ()
168 (let ((url-standalone-mode t))
169 (w3-prepare-buffer)))
171 (defun mm-view-message ()
172 (mm-enable-multibyte)
174 (let (gnus-article-mime-handles)
175 ;; Double decode problem may happen. See mm-inline-message.
176 (run-hooks 'gnus-article-decode-hook)
177 (gnus-article-prepare-display)
178 (setq handles gnus-article-mime-handles))
180 (setq gnus-article-mime-handles
181 (nconc gnus-article-mime-handles
182 (if (listp (car handles))
183 handles (list handles))))))
185 (goto-char (point-min)))
187 (defun mm-inline-message (handle)
189 (charset (mail-content-type-get
190 (mm-handle-type handle) 'charset))
191 gnus-displaying-mime handles)
194 (setq charset (intern (downcase charset)))
195 (when (eq charset 'us-ascii)
199 (narrow-to-region b b)
200 (mm-insert-part handle)
201 (let (gnus-article-mime-handles
202 (gnus-newsgroup-charset
203 (or charset gnus-newsgroup-charset)))
204 (run-hooks 'gnus-article-decode-hook)
205 (gnus-article-prepare-display)
206 (setq handles gnus-article-mime-handles))
207 (goto-char (point-max))
210 (insert "----------\n\n")
212 (setq gnus-article-mime-handles
213 (nconc gnus-article-mime-handles
214 (if (listp (car handles))
215 handles (list handles)))))
216 (mm-handle-set-undisplayer
219 (let (buffer-read-only)
221 ;; This is only valid on XEmacs.
222 (mapcar (lambda (prop)
224 (face-property 'default prop) (current-buffer)))
225 '(background background-pixmap foreground))
227 (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
229 (defun mm-display-patch-inline (handle)
232 (mm-insert-part handle)
234 (font-lock-fontify-buffer)
235 (when (fboundp 'extent-list)
236 (map-extents (lambda (ext ignored)
237 (set-extent-property ext 'duplicable t)
239 nil nil nil nil nil 'text-prop))
240 (setq text (buffer-string)))
241 (mm-insert-inline handle text)))
245 ;; mm-view.el ends here