*** empty log message ***
[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 (require 'mm-decode)
30
31 ;;;
32 ;;; Functions for displaying various formats inline
33 ;;;
34
35 (defun mm-inline-image (handle)
36   (let ((type (cadr (split-string (car (mm-handle-type handle)) "/")))
37         buffer-read-only image)
38     (mm-with-unibyte-buffer
39       (insert-buffer-substring (mm-handle-buffer handle))
40       (mm-decode-content-transfer-encoding
41        (mm-handle-encoding handle)
42        (car (mm-handle-type handle)))
43       (setq image (make-image-specifier
44                    (vector (intern type) :data (buffer-string)))))
45     (let ((annot (make-annotation image nil 'text)))
46       (set-extent-property annot 'mm t)
47       (set-extent-property annot 'duplicable t)
48       (mm-handle-set-undisplayer handle annot))
49     (insert " \n")))
50
51 (defun mm-inline-text (handle)
52   (let ((type (cadr (split-string (car (mm-handle-type handle)) "/")))
53         text buffer-read-only)
54     (cond
55      ((equal type "plain")
56       (with-temp-buffer
57         (insert-buffer-substring (mm-handle-buffer handle))
58         (mm-decode-content-transfer-encoding
59          (mm-handle-encoding handle)
60          (car (mm-handle-type handle)))
61         (setq text (buffer-string)))
62       (let ((b (point)))
63         (insert text)
64         (save-restriction
65           (narrow-to-region b (point))
66           (let ((charset (mail-content-type-get
67                           (mm-handle-type handle) 'charset)))
68             (when charset
69               (mm-decode-body charset nil)))
70           (mm-handle-set-undisplayer
71            handle
72            `(lambda ()
73               (let (buffer-read-only)
74                 (delete-region
75                  ,(set-marker (make-marker) (point-min))
76                  ,(set-marker (make-marker) (point-max)))))))))
77      ((equal type "html")
78       (let ((width (window-width)))
79         (save-excursion
80           (w3-do-setup)
81           (mm-with-unibyte-buffer
82             (insert-buffer-substring (mm-handle-buffer handle))
83             (mm-decode-content-transfer-encoding
84              (mm-handle-encoding handle)
85              (car (mm-handle-type handle)))
86             (require 'url)
87             (save-window-excursion
88               (let ((w3-strict-width width))
89                 (w3-region (point-min) (point-max)))
90               (setq text (buffer-string))))))
91       (mm-insert-inline handle text))
92      ((or (equal type "enriched")
93           (equal type "richtext"))
94       (save-excursion
95         (mm-with-unibyte-buffer
96           (insert-buffer-substring (mm-handle-buffer handle))
97           (mm-decode-content-transfer-encoding
98            (mm-handle-encoding handle)
99            (car (mm-handle-type handle)))
100           (save-window-excursion
101             (enriched-decode (point-min) (point-max))
102             (setq text (buffer-string)))))
103       (mm-insert-inline handle text))
104      (t
105       (save-excursion
106         (mm-with-unibyte-buffer
107           (insert-buffer-substring (mm-handle-buffer handle))
108           (mm-decode-content-transfer-encoding
109            (mm-handle-encoding handle)
110            (car (mm-handle-type handle)))
111           (setq text (buffer-string))))
112       (mm-insert-inline handle text)))))
113
114 (defun mm-insert-inline (handle text)
115   "Insert TEXT inline from HANDLE."
116   (let ((b (point)))
117     (insert text)
118     (mm-handle-set-undisplayer
119      handle
120      `(lambda ()
121         (let (buffer-read-only)
122           (delete-region ,(set-marker (make-marker) b)
123                          ,(set-marker (make-marker) (point))))))))
124   
125 (defun mm-inline-audio (handle)
126   (message "Not implemented"))
127
128 (defun mm-view-sound-file ()
129   (message "Not implemented"))
130
131 (defun mm-w3-prepare-buffer ()
132   (require 'w3)
133   (w3-prepare-buffer))
134
135 (provide 'mm-view)
136
137 ;; mm-view.el ends here