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"))
37 ;;; Functions for displaying various formats inline
40 (defun mm-inline-image (handle)
42 (annot (make-annotation (mm-get-image handle) nil 'text))
45 (mm-handle-set-undisplayer
48 (let (buffer-read-only)
49 (delete-annotation ,annot)
50 (delete-region ,(set-marker (make-marker) b)
51 ,(set-marker (make-marker) (point))))))
52 (set-extent-property annot 'mm t)
53 (set-extent-property annot 'duplicable t)))
55 (defvar mm-w3-setup nil)
63 (setq mm-w3-setup t)))
65 (defun mm-inline-text (handle)
66 (let ((type (mm-handle-media-subtype handle))
67 text buffer-read-only)
71 (setq text (mm-get-part handle))
73 (url-standalone-mode t)
75 (url-generic-parse-url (format "cid:%s" (mm-handle-id handle))))
76 (width (window-width))
77 (charset (mail-content-type-get
78 (mm-handle-type handle) 'charset)))
82 (narrow-to-region b (point))
83 (goto-char (point-min))
84 (if (or (and (boundp 'w3-meta-content-type-charset-regexp)
86 w3-meta-content-type-charset-regexp nil t))
87 (and (boundp 'w3-meta-charset-content-type-regexp)
89 w3-meta-charset-content-type-regexp nil t)))
90 (setq charset (w3-coding-system-for-mime-charset
91 (buffer-substring-no-properties
94 (delete-region (point-min) (point-max))
95 (insert (mm-decode-string text charset))
96 (save-window-excursion
98 (let ((w3-strict-width width)
99 (url-standalone-mode t))
101 (w3-region (point-min) (point-max))
103 (mm-handle-set-undisplayer
106 (let (buffer-read-only)
107 (if (functionp 'remove-specifier)
110 (face-property 'default prop) (current-buffer)))
111 '(background background-pixmap foreground)))
112 (delete-region ,(point-min-marker)
113 ,(point-max-marker)))))))))
114 ((or (equal type "enriched")
115 (equal type "richtext"))
117 (mm-with-unibyte-buffer
118 (mm-insert-part handle)
119 (save-window-excursion
120 (enriched-decode (point-min) (point-max))
121 (setq text (buffer-string)))))
122 (mm-insert-inline handle text))
123 ((equal type "x-vcard")
128 (vcard-parse-string (mm-get-part handle)
129 'vcard-standard-filter)))))
131 (setq text (mm-get-part handle))
133 (charset (mail-content-type-get
134 (mm-handle-type handle) 'charset)))
135 (insert (mm-decode-string text charset))
137 (narrow-to-region b (point))
138 (set-text-properties (point-min) (point-max) nil)
139 (mm-handle-set-undisplayer
142 (let (buffer-read-only)
143 (delete-region ,(point-min-marker)
144 ,(point-max-marker)))))))))))
146 (defun mm-insert-inline (handle text)
147 "Insert TEXT inline from HANDLE."
150 (mm-handle-set-undisplayer
153 (let (buffer-read-only)
154 (delete-region ,(set-marker (make-marker) b)
155 ,(set-marker (make-marker) (point))))))))
157 (defun mm-inline-audio (handle)
158 (message "Not implemented"))
160 (defun mm-view-sound-file ()
161 (message "Not implemented"))
163 (defun mm-w3-prepare-buffer ()
165 (let ((url-standalone-mode t))
166 (w3-prepare-buffer)))
168 (defun mm-view-message ()
169 (mm-enable-multibyte)
170 (gnus-article-prepare-display)
171 (run-hooks 'gnus-article-decode-hook)
173 (goto-char (point-min)))
175 (defun mm-inline-message (handle)
177 gnus-displaying-mime handles)
180 (narrow-to-region b b)
181 (mm-insert-part handle)
182 (let (gnus-article-mime-handles)
183 (run-hooks 'gnus-article-decode-hook)
184 (gnus-article-prepare-display)
185 (setq handles gnus-article-mime-handles))
187 (setq gnus-article-mime-handles
188 (nconc gnus-article-mime-handles
189 (if (listp (car handles))
190 handles (list handles)))))
191 (mm-handle-set-undisplayer
194 (let (buffer-read-only)
196 ;; This is only valid on XEmacs.
199 (face-property 'default prop) (current-buffer)))
200 '(background background-pixmap foreground)))
201 (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
205 ;; mm-view.el ends here