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