*** empty log message ***
[gnus] / lisp / mm-view.el
1 ;;; mm-view.el --- Functions for viewing MIME objects
2 ;; Copyright (C) 1998,99 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     (require 'w3)
46     (w3-do-setup)
47     (require 'url)
48     (require 'w3-vars)
49     (require 'url-vars)
50     (setq mm-w3-setup t)))
51
52 (defun mm-inline-text (handle)
53   (let ((type (cadr (split-string (car (mm-handle-type handle)) "/")))
54         text buffer-read-only)
55     (cond
56      ((equal type "html")
57       (mm-setup-w3)
58       (setq text (mm-get-part handle))
59       (let ((b (point))
60             (url-standalone-mode t)
61             (url-current-object
62              (url-generic-parse-url (format "cid:%s" (mm-handle-id handle))))
63             (width (window-width)))
64         (save-excursion
65           (insert text)
66           (save-restriction
67             (narrow-to-region b (point))
68             (save-window-excursion
69               (let ((w3-strict-width width))
70                 (w3-region (point-min) (point-max)))))
71           (mm-handle-set-undisplayer
72            handle
73            `(lambda ()
74               (let (buffer-read-only)
75               (mapc (lambda (prop)
76                       (remove-specifier
77                        (face-property 'default prop) (current-buffer)))
78                     '(background background-pixmap foreground))
79                 (delete-region ,(point-min-marker) ,(point-max-marker))))))))
80      ((or (equal type "enriched")
81           (equal type "richtext"))
82       (save-excursion
83         (mm-with-unibyte-buffer
84           (mm-insert-part handle)
85           (save-window-excursion
86             (enriched-decode (point-min) (point-max))
87             (setq text (buffer-string)))))
88       (mm-insert-inline handle text))
89      (t
90       (setq text (mm-get-part handle))
91       (let ((b (point))
92             (charset (mail-content-type-get
93                       (mm-handle-type handle) 'charset)))
94         (insert (mm-decode-string text charset))
95         (save-restriction
96           (narrow-to-region b (point))
97           (mm-handle-set-undisplayer
98            handle
99            `(lambda ()
100               (let (buffer-read-only)
101                 (delete-region ,(point-min-marker)
102                                ,(point-max-marker)))))))))))
103
104 (defun mm-insert-inline (handle text)
105   "Insert TEXT inline from HANDLE."
106   (let ((b (point)))
107     (insert text)
108     (mm-handle-set-undisplayer
109      handle
110      `(lambda ()
111         (let (buffer-read-only)
112           (delete-region ,(set-marker (make-marker) b)
113                          ,(set-marker (make-marker) (point))))))))
114   
115 (defun mm-inline-audio (handle)
116   (message "Not implemented"))
117
118 (defun mm-view-sound-file ()
119   (message "Not implemented"))
120
121 (defun mm-w3-prepare-buffer ()
122   (require 'w3)
123   (w3-prepare-buffer))
124
125 (eval-and-compile
126   (autoload 'gnus-article-prepare-display "gnus-art"))
127
128 (defun mm-view-message ()
129   (gnus-article-prepare-display)
130   (run-hooks 'gnus-article-decode-hook)
131   (fundamental-mode)
132   (goto-char (point-min)))
133
134 (provide 'mm-view)
135
136 ;; mm-view.el ends here