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 (cadr (split-string (car (mm-handle-type 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 (re-search-forward
88 w3-meta-content-type-charset-regexp nil t)
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))
188 (setq gnus-article-mime-handles
189 (append gnus-article-mime-handles handles)))
190 (mm-handle-set-undisplayer
193 (let (buffer-read-only)
195 ;; This is only valid on XEmacs.
198 (face-property 'default prop) (current-buffer)))
199 '(background background-pixmap foreground)))
200 (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
204 ;; mm-view.el ends here