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 'fill-flowed "fill-flowed")
37 (autoload 'diff-mode "diff-mode"))
40 ;;; Functions for displaying various formats inline
43 (defun mm-inline-image (handle)
45 (annot (make-annotation (mm-get-image handle) nil 'text))
48 (mm-handle-set-undisplayer
51 (let (buffer-read-only)
52 (delete-annotation ,annot)
53 (delete-region ,(set-marker (make-marker) b)
54 ,(set-marker (make-marker) (point))))))
55 (set-extent-property annot 'mm t)
56 (set-extent-property annot 'duplicable t)))
58 (defvar mm-w3-setup nil)
66 (setq mm-w3-setup t)))
68 (defun mm-inline-text (handle)
69 (let ((type (mm-handle-media-subtype handle))
70 text buffer-read-only)
74 (setq text (mm-get-part handle))
76 (url-standalone-mode t)
78 (url-generic-parse-url (format "cid:%s" (mm-handle-id handle))))
79 (width (window-width))
80 (charset (mail-content-type-get
81 (mm-handle-type handle) 'charset)))
85 (narrow-to-region b (point))
86 (goto-char (point-min))
87 (if (or (and (boundp 'w3-meta-content-type-charset-regexp)
89 w3-meta-content-type-charset-regexp nil t))
90 (and (boundp 'w3-meta-charset-content-type-regexp)
92 w3-meta-charset-content-type-regexp nil t)))
93 (setq charset (w3-coding-system-for-mime-charset
94 (buffer-substring-no-properties
97 (delete-region (point-min) (point-max))
98 (insert (mm-decode-string text charset))
99 (save-window-excursion
101 (let ((w3-strict-width width)
102 (url-standalone-mode t))
104 (w3-region (point-min) (point-max))
106 (mm-handle-set-undisplayer
109 (let (buffer-read-only)
110 (if (functionp 'remove-specifier)
111 (mapcar (lambda (prop)
113 (face-property 'default prop)
115 '(background background-pixmap foreground)))
116 (delete-region ,(point-min-marker)
117 ,(point-max-marker)))))))))
118 ((or (equal type "enriched")
119 (equal type "richtext"))
121 (mm-with-unibyte-buffer
122 (mm-insert-part handle)
123 (save-window-excursion
124 (enriched-decode (point-min) (point-max))
125 (setq text (buffer-string)))))
126 (mm-insert-inline handle text))
127 ((equal type "x-vcard")
131 (if (fboundp 'vcard-pretty-print)
132 (vcard-pretty-print (mm-get-part handle))
134 (vcard-parse-string (mm-get-part handle)
135 'vcard-standard-filter))))))
137 (setq text (mm-get-part handle))
139 (charset (mail-content-type-get
140 (mm-handle-type handle) 'charset)))
141 (insert (mm-decode-string text charset))
142 (when (and (equal type "plain")
143 (equal (cdr (assoc 'format (mm-handle-type handle)))
146 (narrow-to-region b (point))
149 (goto-char (point-max))))
151 (narrow-to-region b (point))
152 (set-text-properties (point-min) (point-max) nil)
153 (mm-handle-set-undisplayer
156 (let (buffer-read-only)
157 (delete-region ,(point-min-marker)
158 ,(point-max-marker)))))))))))
160 (defun mm-insert-inline (handle text)
161 "Insert TEXT inline from HANDLE."
164 (mm-handle-set-undisplayer
167 (let (buffer-read-only)
168 (delete-region ,(set-marker (make-marker) b)
169 ,(set-marker (make-marker) (point))))))))
171 (defun mm-inline-audio (handle)
172 (message "Not implemented"))
174 (defun mm-view-sound-file ()
175 (message "Not implemented"))
177 (defun mm-w3-prepare-buffer ()
179 (let ((url-standalone-mode t))
180 (w3-prepare-buffer)))
182 (defun mm-view-message ()
183 (mm-enable-multibyte)
185 (let (gnus-article-mime-handles)
186 ;; Double decode problem may happen. See mm-inline-message.
187 (run-hooks 'gnus-article-decode-hook)
188 (gnus-article-prepare-display)
189 (setq handles gnus-article-mime-handles))
191 (setq gnus-article-mime-handles
192 (nconc gnus-article-mime-handles
193 (if (listp (car handles))
194 handles (list handles))))))
196 (goto-char (point-min)))
198 (defun mm-inline-message (handle)
200 (charset (mail-content-type-get
201 (mm-handle-type handle) 'charset))
202 gnus-displaying-mime handles)
205 (setq charset (intern (downcase charset)))
206 (when (eq charset 'us-ascii)
210 (narrow-to-region b b)
211 (mm-insert-part handle)
212 (let (gnus-article-mime-handles
213 (gnus-newsgroup-charset
214 (or charset gnus-newsgroup-charset)))
215 (run-hooks 'gnus-article-decode-hook)
216 (gnus-article-prepare-display)
217 (setq handles gnus-article-mime-handles))
218 (goto-char (point-max))
221 (insert "----------\n\n")
223 (setq gnus-article-mime-handles
224 (nconc gnus-article-mime-handles
225 (if (listp (car handles))
226 handles (list handles)))))
227 (mm-handle-set-undisplayer
230 (let (buffer-read-only)
232 ;; This is only valid on XEmacs.
233 (mapcar (lambda (prop)
235 (face-property 'default prop) (current-buffer)))
236 '(background background-pixmap foreground))
238 (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
240 (defun mm-display-patch-inline (handle)
243 (mm-insert-part handle)
245 (font-lock-fontify-buffer)
246 (when (fboundp 'extent-list)
247 (map-extents (lambda (ext ignored)
248 (set-extent-property ext 'duplicable t)
250 nil nil nil nil nil 'text-prop))
251 (setq text (buffer-string)))
252 (mm-insert-inline handle text)))
256 ;; mm-view.el ends here