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.
32 (autoload 'gnus-article-prepare-display "gnus-art")
33 (autoload 'vcard-parse-string "vcard")
34 (autoload 'vcard-format-string "vcard")
35 (autoload 'diff-mode "diff-mode"))
38 ;;; Functions for displaying various formats inline
41 (defun mm-inline-image (handle)
43 (annot (make-annotation (mm-get-image handle) nil 'text))
46 (mm-handle-set-undisplayer
49 (let (buffer-read-only)
50 (delete-annotation ,annot)
51 (delete-region ,(set-marker (make-marker) b)
52 ,(set-marker (make-marker) (point))))))
53 (set-extent-property annot 'mm t)
54 (set-extent-property annot 'duplicable t)))
56 (defvar mm-w3-setup nil)
64 (setq mm-w3-setup t)))
66 (defun mm-inline-text (handle)
67 (let ((type (mm-handle-media-subtype handle))
68 text buffer-read-only)
72 (setq text (mm-get-part handle))
74 (url-standalone-mode t)
76 (url-generic-parse-url (format "cid:%s" (mm-handle-id handle))))
77 (width (window-width))
78 (charset (mail-content-type-get
79 (mm-handle-type handle) 'charset)))
83 (narrow-to-region b (point))
84 (goto-char (point-min))
85 (if (or (and (boundp 'w3-meta-content-type-charset-regexp)
87 w3-meta-content-type-charset-regexp nil t))
88 (and (boundp 'w3-meta-charset-content-type-regexp)
90 w3-meta-charset-content-type-regexp nil t)))
91 (setq charset (w3-coding-system-for-mime-charset
92 (buffer-substring-no-properties
95 (delete-region (point-min) (point-max))
96 (insert (mm-decode-string text charset))
97 (save-window-excursion
99 (let ((w3-strict-width width)
100 (url-standalone-mode t))
102 (w3-region (point-min) (point-max))
104 (mm-handle-set-undisplayer
107 (let (buffer-read-only)
108 (if (functionp 'remove-specifier)
111 (face-property 'default prop) (current-buffer)))
112 '(background background-pixmap foreground)))
113 (delete-region ,(point-min-marker)
114 ,(point-max-marker)))))))))
115 ((or (equal type "enriched")
116 (equal type "richtext"))
118 (mm-with-unibyte-buffer
119 (mm-insert-part handle)
120 (save-window-excursion
121 (enriched-decode (point-min) (point-max))
122 (setq text (buffer-string)))))
123 (mm-insert-inline handle text))
124 ((equal type "x-vcard")
129 (vcard-parse-string (mm-get-part handle)
130 'vcard-standard-filter)))))
132 (setq text (mm-get-part handle))
134 (charset (mail-content-type-get
135 (mm-handle-type handle) 'charset)))
136 (insert (mm-decode-string text charset))
138 (narrow-to-region b (point))
139 (set-text-properties (point-min) (point-max) nil)
140 (mm-handle-set-undisplayer
143 (let (buffer-read-only)
144 (delete-region ,(point-min-marker)
145 ,(point-max-marker)))))))))))
147 (defun mm-insert-inline (handle text)
148 "Insert TEXT inline from HANDLE."
151 (mm-handle-set-undisplayer
154 (let (buffer-read-only)
155 (delete-region ,(set-marker (make-marker) b)
156 ,(set-marker (make-marker) (point))))))))
158 (defun mm-inline-audio (handle)
159 (message "Not implemented"))
161 (defun mm-view-sound-file ()
162 (message "Not implemented"))
164 (defun mm-w3-prepare-buffer ()
166 (let ((url-standalone-mode t))
167 (w3-prepare-buffer)))
169 (defun mm-view-message ()
170 (mm-enable-multibyte)
171 (gnus-article-prepare-display)
172 (run-hooks 'gnus-article-decode-hook)
174 (goto-char (point-min)))
176 (defun mm-inline-message (handle)
178 gnus-displaying-mime handles)
181 (narrow-to-region b b)
182 (mm-insert-part handle)
183 (let (gnus-article-mime-handles)
184 (run-hooks 'gnus-article-decode-hook)
185 (gnus-article-prepare-display)
186 (setq handles gnus-article-mime-handles))
187 (goto-char (point-max))
190 (insert "----------\n\n")
192 (setq gnus-article-mime-handles
193 (nconc gnus-article-mime-handles
194 (if (listp (car handles))
195 handles (list handles)))))
196 (mm-handle-set-undisplayer
199 (let (buffer-read-only)
201 ;; This is only valid on XEmacs.
204 (face-property 'default prop) (current-buffer)))
205 '(background background-pixmap foreground)))
206 (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
208 (defun mm-display-patch-inline (handle)
211 (mm-insert-part handle)
213 (font-lock-fontify-buffer)
214 (when (fboundp 'extent-list)
215 (map-extents (lambda (ext ignored)
216 (set-extent-property ext 'duplicable t)
218 nil nil nil nil nil 'text-prop))
219 (setq text (buffer-string)))
220 (mm-insert-inline handle text)))
224 ;; mm-view.el ends here