Sync up with Pteroductyl Gnus 0.64
[elisp/gnus.git-] / 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 (defvar mm-w3-setup nil)
43 (defun mm-setup-w3 ()
44   (unless mm-w3-setup
45     (w3-do-setup)
46     (require 'url)
47     (require 'w3-vars)
48     (require 'url-vars)
49     (setq mm-w3-setup t)))
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       (setq text (mm-get-part handle))
57       (let ((b (point))
58             (charset (mail-content-type-get
59                       (mm-handle-type handle) 'charset)))
60         (insert (mm-decode-string text charset))
61         (save-restriction
62           (narrow-to-region b (point))
63           (mm-handle-set-undisplayer
64            handle
65            `(lambda ()
66               (let (buffer-read-only)
67                 (delete-region ,(point-min-marker) ,(point-max-marker))))))))
68      ((equal type "html")
69       (mm-setup-w3)
70       (setq text (mm-get-part handle))
71       (let ((b (point))
72             (width (window-width)))
73         (save-excursion
74           (insert text)
75           (save-restriction
76             (narrow-to-region b (point))
77             (save-window-excursion
78               (let ((w3-strict-width width))
79                 (w3-region (point-min) (point-max)))))
80           (mm-handle-set-undisplayer
81            handle
82            `(lambda ()
83               (let (buffer-read-only)
84               (mapc (lambda (prop)
85                       (remove-specifier
86                        (face-property 'default prop) (current-buffer)))
87                     '(background background-pixmap foreground))
88                 (delete-region ,(point-min-marker) ,(point-max-marker))))))))
89      ((or (equal type "enriched")
90           (equal type "richtext"))
91       (save-excursion
92         (mm-with-unibyte-buffer
93           (insert-buffer-substring (mm-handle-buffer handle))
94           (mm-decode-content-transfer-encoding
95            (mm-handle-encoding handle)
96            (car (mm-handle-type handle)))
97           (save-window-excursion
98             (enriched-decode (point-min) (point-max))
99             (setq text (buffer-string)))))
100       (mm-insert-inline handle text))
101      (t
102       (save-excursion
103         (mm-with-unibyte-buffer
104           (insert-buffer-substring (mm-handle-buffer handle))
105           (mm-decode-content-transfer-encoding
106            (mm-handle-encoding handle)
107            (car (mm-handle-type handle)))
108           (setq text (buffer-string))))
109       (mm-insert-inline handle text)))))
110
111 (defun mm-insert-inline (handle text)
112   "Insert TEXT inline from HANDLE."
113   (let ((b (point)))
114     (insert text)
115     (mm-handle-set-undisplayer
116      handle
117      `(lambda ()
118         (let (buffer-read-only)
119           (delete-region ,(set-marker (make-marker) b)
120                          ,(set-marker (make-marker) (point))))))))
121   
122 (defun mm-inline-audio (handle)
123   (message "Not implemented"))
124
125 (defun mm-view-sound-file ()
126   (message "Not implemented"))
127
128 (defun mm-w3-prepare-buffer ()
129   (require 'w3)
130   (w3-prepare-buffer))
131
132 (provide 'mm-view)
133
134 ;; mm-view.el ends here