10ab086d1e1493b02e7230368ab2022f6659df40
[gnus] / lisp / mm-view.el
1 ;;; mm-view.el --- Functions for viewing MIME objects
2 ;; Copyright (C) 1998 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; This file is part of GNU Emacs.
6
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)
10 ;; any later version.
11
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.
16
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.
21
22 ;;; Commentary:
23
24 ;;; Code:
25
26 (require 'mail-parse)
27 (require 'mailcap)
28 (require 'mm-bodies)
29
30 ;;;
31 ;;; Functions for displaying various formats inline
32 ;;;
33
34 (defun mm-inline-image (handle)
35   (let ((type (cadr (split-string (car (mm-handle-type handle)) "/")))
36         buffer-read-only image)
37     (mm-with-unibyte-buffer
38       (insert-buffer-substring (mm-handle-buffer handle))
39       (mm-decode-content-transfer-encoding (mm-handle-encoding handle))
40       (setq image (make-image-specifier
41                    (vector (intern type) :data (buffer-string)))))
42     (let ((annot (make-annotation image nil 'text)))
43       (set-extent-property annot 'mm t)
44       (set-extent-property annot 'duplicable t)
45       (mm-handle-set-undisplayer handle annot))
46     (insert " ")))
47
48 (defun mm-inline-text (handle)
49   (let ((type (cadr (split-string (car (mm-handle-type handle)) "/")))
50         text buffer-read-only)
51     (cond
52      ((equal type "plain")
53       (with-temp-buffer
54         (insert-buffer-substring (mm-handle-buffer handle))
55         (mm-decode-content-transfer-encoding (mm-handle-encoding handle))
56         (setq text (buffer-string)))
57       (let ((b (point)))
58         (insert text)
59         (save-restriction
60           (narrow-to-region b (point))
61           (let ((charset (mail-content-type-get
62                           (mm-handle-type handle) 'charset)))
63             (when charset
64               (mm-decode-body charset nil)))
65           (mm-handle-set-undisplayer
66            handle
67            `(lambda ()
68               (let (buffer-read-only)
69                 (delete-region
70                  ,(set-marker (make-marker) (point-min))
71                  ,(set-marker (make-marker) (point-max)))))))))
72      ((equal type "html")
73       (save-excursion
74         (w3-do-setup)
75         (mm-with-unibyte-buffer
76           (insert-buffer-substring (mm-handle-buffer handle))
77           (mm-decode-content-transfer-encoding (mm-handle-encoding handle))
78           (require 'url)
79           (save-window-excursion
80             (w3-region (point-min) (point-max))
81             (setq text (buffer-string))))
82         (mm-insert-inline handle text)))
83      ((or (equal type "enriched")
84           (equal type "richtext"))
85       (save-excursion
86         (mm-with-unibyte-buffer
87           (insert-buffer-substring (mm-handle-buffer handle))
88           (mm-decode-content-transfer-encoding (mm-handle-encoding handle))
89           (save-window-excursion
90             (enriched-decode (point-min) (point-max))
91             (setq text (buffer-string))))
92         (mm-insert-inline handle text)))
93      )))
94
95 (defun mm-insert-inline (handle text)
96   "Insert TEXT inline from HANDLE."
97   (let ((b (point)))
98     (insert text)
99     (mm-handle-set-undisplayer
100      handle
101      `(lambda ()
102         (let (buffer-read-only)
103           (delete-region ,(set-marker (make-marker) b)
104                          ,(set-marker (make-marker) (point))))))))
105   
106 (defun mm-inline-audio (handle)
107   (message "Not implemented"))
108
109 (defun mm-view-sound-file ()
110   (message "Not implemented"))
111
112 (defun mm-w3-prepare-buffer ()
113   (require 'w3)
114   (w3-prepare-buffer))
115
116 (provide 'mm-view)
117
118 ;; mm-view.el ends here