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"))
37 ;; Avoid byte compile warning.
38 (defvar gnus-article-mime-handles)
41 ;;; Functions for displaying various formats inline
44 (defun mm-inline-image (handle)
46 (annot (make-annotation (mm-get-image handle) nil 'text))
49 (mm-handle-set-undisplayer
52 (let (buffer-read-only)
53 (delete-annotation ,annot)
54 (delete-region ,(set-marker (make-marker) b)
55 ,(set-marker (make-marker) (point))))))
56 (set-extent-property annot 'mm t)
57 (set-extent-property annot 'duplicable t)))
59 (defvar mm-w3-setup nil)
67 (setq mm-w3-setup t)))
69 (defun mm-inline-text (handle)
70 (let ((type (mm-handle-media-subtype handle))
71 text buffer-read-only)
75 (setq text (mm-get-part handle))
77 (url-standalone-mode t)
79 (url-generic-parse-url (format "cid:%s" (mm-handle-id handle))))
80 (width (window-width))
81 (charset (mail-content-type-get
82 (mm-handle-type handle) 'charset)))
86 (narrow-to-region b (point))
87 (goto-char (point-min))
88 (if (or (and (boundp 'w3-meta-content-type-charset-regexp)
90 w3-meta-content-type-charset-regexp nil t))
91 (and (boundp 'w3-meta-charset-content-type-regexp)
93 w3-meta-charset-content-type-regexp nil t)))
94 (setq charset (w3-coding-system-for-mime-charset
95 (buffer-substring-no-properties
98 (delete-region (point-min) (point-max))
99 (insert (mm-decode-string text charset))
100 (save-window-excursion
102 (let ((w3-strict-width width)
103 (url-standalone-mode t))
105 (w3-region (point-min) (point-max))
107 (mm-handle-set-undisplayer
110 (let (buffer-read-only)
111 (if (functionp 'remove-specifier)
114 (face-property 'default prop) (current-buffer)))
115 '(background background-pixmap foreground)))
116 (delete-region ,(point-min-marker)
117 ,(point-max-marker)))))))))
118 ((or (equal type "enriched")
119 (equal type "richtext"))
121 (mm-with-unibyte-buffer
122 (mm-insert-part handle)
123 (save-window-excursion
124 (enriched-decode (point-min) (point-max))
125 (setq text (buffer-string)))))
126 (mm-insert-inline handle text))
127 ((equal type "x-vcard")
132 (vcard-parse-string (mm-get-part handle)
133 'vcard-standard-filter)))))
135 (setq text (mm-get-part handle))
137 (charset (mail-content-type-get
138 (mm-handle-type handle) 'charset)))
139 (insert (mm-decode-string text charset))
141 (narrow-to-region b (point))
142 (set-text-properties (point-min) (point-max) nil)
143 (mm-handle-set-undisplayer
146 (let (buffer-read-only)
147 (delete-region ,(point-min-marker)
148 ,(point-max-marker)))))))))))
150 (defun mm-insert-inline (handle text)
151 "Insert TEXT inline from HANDLE."
154 (mm-handle-set-undisplayer
157 (let (buffer-read-only)
158 (delete-region ,(set-marker (make-marker) b)
159 ,(set-marker (make-marker) (point))))))))
161 (defun mm-inline-audio (handle)
162 (message "Not implemented"))
164 (defun mm-view-sound-file ()
165 (message "Not implemented"))
167 (defun mm-w3-prepare-buffer ()
169 (let ((url-standalone-mode t))
170 (w3-prepare-buffer)))
172 (defun mm-view-message ()
173 (mm-enable-multibyte)
175 (let (gnus-article-mime-handles)
176 ;; Double decode problem may happen. See mm-inline-message.
177 (run-hooks 'gnus-article-decode-hook)
178 (gnus-article-prepare-display)
179 (setq handles gnus-article-mime-handles))
181 (setq gnus-article-mime-handles
182 (nconc gnus-article-mime-handles
183 (if (listp (car handles))
184 handles (list handles))))))
186 (goto-char (point-min)))
188 (defun mm-inline-message (handle)
190 (charset (mail-content-type-get
191 (mm-handle-type handle) 'charset))
192 gnus-displaying-mime handles)
195 (setq charset (intern (downcase charset)))
196 (when (eq charset 'us-ascii)
200 (narrow-to-region b b)
201 (mm-insert-part handle)
202 (let (gnus-article-mime-handles
203 (gnus-newsgroup-charset
204 (or charset gnus-newsgroup-charset)))
205 (run-hooks 'gnus-article-decode-hook)
206 (gnus-article-prepare-display)
207 (setq handles gnus-article-mime-handles))
208 (goto-char (point-max))
211 (insert "----------\n\n")
213 (setq gnus-article-mime-handles
214 (nconc gnus-article-mime-handles
215 (if (listp (car handles))
216 handles (list handles)))))
217 (mm-handle-set-undisplayer
220 (let (buffer-read-only)
222 ;; This is only valid on XEmacs.
225 (face-property 'default prop) (current-buffer)))
226 '(background background-pixmap foreground)))
227 (delete-region ,(point-min-marker) ,(point-max-marker)))))))))
229 (defun mm-display-patch-inline (handle)
232 (mm-insert-part handle)
234 (font-lock-fontify-buffer)
235 (when (fboundp 'extent-list)
236 (map-extents (lambda (ext ignored)
237 (set-extent-property ext 'duplicable t)
239 nil nil nil nil nil 'text-prop))
240 (setq text (buffer-string)))
241 (mm-insert-inline handle text)))
245 ;; mm-view.el ends here