Merge remi-1_14_2-1.
[elisp/semi.git] / mime-w3.el
1 ;;; mime-w3.el --- mime-view content filter for text
2
3 ;; Copyright (C) 1994,95,96,97,98,99,2000 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
6 ;; Keywords: HTML, MIME, multimedia, mail, news
7
8 ;; This file is part of SEMI (Suite of Emacs MIME Interfaces).
9
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
14
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 ;; General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Code:
26
27 (require 'w3)
28 (require 'mime)
29
30 (defmacro mime-put-keymap-region (start end keymap)
31   `(put-text-property ,start ,end
32                       ',(if (featurep 'xemacs)
33                             'keymap
34                           'local-map)
35                       ,keymap))
36
37 (defmacro mime-save-background-color (&rest body)
38   (if (featurep 'xemacs)
39       `(let ((color (color-name (face-background 'default))))
40          (prog1
41              (progn ,@body)
42            (font-set-face-background 'default color (current-buffer))
43            ))
44     (cons 'progn body)))
45
46 (defvar mime-w3-message-structure nil)
47
48 (defun mime-preview-text/html (entity situation)
49   (setq mime-w3-message-structure (mime-find-root-entity entity))
50   (goto-char (point-max))
51   (let ((p (point)))
52     (insert "\n")
53     (goto-char p)
54     (mime-save-background-color
55      (save-restriction
56        (narrow-to-region p p)
57        (mime-insert-text-content entity)
58        (run-hooks 'mime-text-decode-hook)
59        (condition-case err
60            (w3-region p (point-max))
61          (error (message (format "%s" err))))
62        (mime-put-keymap-region p (point-max) w3-mode-map)
63        ))))
64
65 (defun url-cid (url &optional proxy-info)
66   (let ((entity
67          (mime-find-entity-from-content-id (mime-uri-parse-cid url)
68                                            mime-w3-message-structure)))
69     (when entity
70       (mime-insert-entity-content entity)
71       (setq url-current-mime-type (mime-entity-type/subtype entity))
72       )))
73
74 (url-register-protocol "cid"
75                        'url-cid
76                        'url-identity-expander)
77
78
79 ;;; @ end
80 ;;;
81
82 (provide 'mime-w3)
83
84 ;;; mime-w3.el ends here