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"))
36 ;; Avoid byte compile warning.
37 (defvar gnus-article-mime-handles)
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)
113 (face-property 'default prop) (current-buffer)))
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)
173 (gnus-article-prepare-display)
174 (run-hooks 'gnus-article-decode-hook)
176 (goto-char (point-min)))
178 (defun mm-inline-message (handle)
180 gnus-displaying-mime handles)
183 (narrow-to-region b b)
184 (mm-insert-part handle)
185 (let (gnus-article-mime-handles)
186 (run-hooks 'gnus-article-decode-hook)
187 (gnus-article-prepare-display)
188 (setq handles gnus-article-mime-handles))
190 (setq gnus-article-mime-handles
191 (append gnus-article-mime-handles handles)))
192 (mm-handle-set-undisplayer
195 (let (buffer-read-only)
197 ;; This is only valid on XEmacs.
200 (face-property 'default prop) (current-buffer)))
201 '(background background-pixmap foreground)))
202 (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
206 ;; mm-view.el ends here