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 (cadr (split-string (car (mm-handle-type 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 (re-search-forward
85 w3-meta-content-type-charset-regexp nil t)
87 w3-meta-charset-content-type-regexp nil t))
88 (setq charset (w3-coding-system-for-mime-charset
89 (buffer-substring-no-properties
92 (delete-region (point-min) (point-max))
93 (insert (mm-decode-string text charset))
94 (save-window-excursion
96 (let ((w3-strict-width width)
97 (url-standalone-mode t))
99 (w3-region (point-min) (point-max))
101 ;;; (narrow-to-region (1+ (point-min)) (point-max))
102 (mm-handle-set-undisplayer
105 (let (buffer-read-only)
106 (if (functionp 'remove-specifier)
109 (face-property 'default prop) (current-buffer)))
110 '(background background-pixmap foreground)))
111 (delete-region ,(point-min-marker)
112 ,(point-max-marker)))))))))
113 ((or (equal type "enriched")
114 (equal type "richtext"))
116 (mm-with-unibyte-buffer
117 (mm-insert-part handle)
118 (save-window-excursion
119 (enriched-decode (point-min) (point-max))
120 (setq text (buffer-string)))))
121 (mm-insert-inline handle text))
122 ((equal type "x-vcard")
127 (vcard-parse-string (mm-get-part handle)
128 'vcard-standard-filter)))))
130 (setq text (mm-get-part handle))
132 (charset (mail-content-type-get
133 (mm-handle-type handle) 'charset)))
134 (insert (mm-decode-string text charset))
136 (narrow-to-region b (point))
137 (set-text-properties (point-min) (point-max) nil)
138 (mm-handle-set-undisplayer
141 (let (buffer-read-only)
142 (delete-region ,(point-min-marker)
143 ,(point-max-marker)))))))))))
145 (defun mm-insert-inline (handle text)
146 "Insert TEXT inline from HANDLE."
149 (mm-handle-set-undisplayer
152 (let (buffer-read-only)
153 (delete-region ,(set-marker (make-marker) b)
154 ,(set-marker (make-marker) (point))))))))
156 (defun mm-inline-audio (handle)
157 (message "Not implemented"))
159 (defun mm-view-sound-file ()
160 (message "Not implemented"))
162 (defun mm-w3-prepare-buffer ()
164 (let ((url-standalone-mode t))
165 (w3-prepare-buffer)))
167 (defun mm-view-message ()
168 (mm-enable-multibyte)
169 (gnus-article-prepare-display)
170 (run-hooks 'gnus-article-decode-hook)
172 (goto-char (point-min)))
174 (defun mm-inline-message (handle)
175 (let ((b (point)) gnus-displaying-mime handles)
178 (narrow-to-region b b)
179 (mm-insert-part handle)
180 (let (gnus-article-mime-handles)
181 (run-hooks 'gnus-article-decode-hook)
182 (gnus-article-prepare-display)
183 (setq handles gnus-article-mime-handles))
185 (setq gnus-article-mime-handles
186 (append gnus-article-mime-handles handles)))
187 (mm-handle-set-undisplayer
190 (let (buffer-read-only)
193 (face-property 'default prop) (current-buffer)))
194 '(background background-pixmap foreground))
195 (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
199 ;; mm-view.el ends here