tm 7.59.
[elisp/tm.git] / tm-rich.el
index 33246d7..447f61b 100644 (file)
@@ -1,78 +1,91 @@
 ;;;
-;;; $Id: tm-rich.el,v 1.1 1994/09/05 14:34:06 morioka Exp morioka $
+;;; tm-rich.el --- text/enriched and text/richtext style
+;;;                richtext filter for tm-view
 ;;;
-
-(provide 'tm-rich)
+;;; Copyright (C) 1995 Free Software Foundation, Inc.
+;;; Copyright (C) 1994 .. 1996 MORIOKA Tomohiko
+;;;
+;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
+;;; Version:
+;;;    $Id: tm-rich.el,v 7.5 1996/05/07 06:28:36 morioka Exp $
+;;; Keywords: mail, news, MIME, multimedia, richtext, enriched
+;;;
+;;; This file is part of tm (Tools for MIME).
+;;;
+;;; This program is free software; you can redistribute it and/or
+;;; modify it under the terms of the GNU General Public License as
+;;; published by the Free Software Foundation; either version 2, or
+;;; (at your option) any later version.
+;;;
+;;; This program is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;;; General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with This program.  If not, write to the Free Software
+;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;;;
+;;; Code:
 
 (require 'tm-view)
-(require 'assoc)
-(require 'hilit19)
 
-      
-(defun mime/get-text/enriched-face (str)
-  (let ((sym (intern str)))
-    (if (eq sym 'italic)
-       'modeline
-      sym)))
 
-(defun mime/decode-text/enriched-region (beg end)
-  (interactive "*r")
-  (save-excursion
-    (save-restriction
-      (narrow-to-region beg end)
-      (goto-char beg)
-      (let (cmd sym (fb (point)) fe b e)
-       (while (re-search-forward
-               "[ \t\n\r]*<[^<>\n\r \t]+>[ \t\n\r]*" nil t)
-         (setq cmd (buffer-substring (match-beginning 0) (match-end 0)))
-         (replace-match "")
-         (string-match "^[ \t\n\r]*<" cmd)
-         (setq cmd (substring cmd (match-end 0)))
-         (string-match ">[ \t\n\r]*$" cmd)
-         (setq cmd (substring cmd 0 (match-beginning 0)))
-         (setq sym (mime/get-text/enriched-face cmd))
-         (cond ((string= cmd "nl")
-                (fill-region fb (point) t)
-                (insert "\n")
-                (setq fb (point))
-                )
-               ((member sym (face-list))
-                (if (not (bolp))
-                    (insert " ")
-                  )
-                (setq b (point))
-                (save-excursion
-                  (save-restriction
-                    (if (re-search-forward (concat "[ \t\n\r]*</"
-                                                   cmd ">[ \t\n\r]*")
-                                           nil t)
-                        (progn
-                          (replace-match " ")
-                          (setq e (- (point) 1))
-                          )
-                      (setq e end)
-                      )))
-                (hilit-unhighlight-region b e)
-                (hilit-region-set-face b e sym)
-                )))
-       (fill-region fb (point) t)
-       ))))
+;;; @ content filters for tm-view
+;;;
+
+(defun mime-viewer/filter-text/richtext (ctype params encoding)
+  (let* ((mode mime::preview/original-major-mode)
+        (m (assq mode mime-viewer/code-converter-alist))
+        (charset (assoc "charset" params))
+        ;; 1995/9/21 (c.f. tm-eng:105), 1995/10/3 (c.f. tm-eng:121)
+        ;;   modified by Eric Ding <ericding@San-Jose.ate.slb.com>
+        (beg (point-min)) (end (point-max))
+        )
+    (remove-text-properties beg end '(face nil))
+    (mime/decode-region encoding beg end)
+    (if (and m (fboundp (setq m (cdr m))))
+       (funcall m beg (point-max) charset encoding)
+      (mime-viewer/default-code-convert-region beg (point-max)
+                                              charset encoding)
+      )
+    (richtext-decode beg (point-max))
+    ))
 
-(defun mime/decode-text/enriched-body ()
-  (interactive)
-  (save-excursion
-    (save-restriction
-      (let ((beg (point-min)) (end (point-max)))
-       (goto-char (point-min))
-       (if (search-forward "\n\n" nil t)
-           (setq beg (match-end 0))
-         )
-       (mime/decode-text/enriched-region beg end)
-       ))))
+(defun mime-viewer/filter-text/enriched (ctype params encoding)
+  (let* ((mode mime::preview/original-major-mode)
+        (m (assq mode mime-viewer/code-converter-alist))
+        (charset (assoc "charset" params))
+        ;; 1995/9/21 (c.f. tm-eng:105), 1995/10/3 (c.f. tm-eng:121)
+        ;;   modified by Eric Ding <ericding@San-Jose.ate.slb.com>
+        (beg (point-min)) (end (point-max))
+        )
+    (remove-text-properties beg end '(face nil))
+    (mime/decode-region encoding beg end)
+    (if (and m (fboundp (setq m (cdr m))))
+       (funcall m beg (point-max) charset encoding)
+      (mime-viewer/default-code-convert-region beg (point-max)
+                                              charset encoding)
+      )
+    (enriched-decode beg (point-max))
+    ))
 
 
-(aput 'mime/content-filter-alist
-      "text/enriched" (function mime/decode-text/enriched-body))
+;;; @ setting
+;;;
+
+(set-alist 'mime-viewer/content-filter-alist
+          "text/richtext" (function mime-viewer/filter-text/richtext))
+
+(set-alist 'mime-viewer/content-filter-alist
+          "text/enriched" (function mime-viewer/filter-text/enriched))
+
+
+;;; @ end
+;;;
+
+(provide 'tm-rich)
+
+(run-hooks 'tm-rich-load-hook)
 
-(aput 'mime/content-filter-alist
-      "text/richtext" (function mime/decode-text/enriched-body))
+;;; tm-rich.el ends here