tm 7.59.
[elisp/tm.git] / tm-text.el
diff --git a/tm-text.el b/tm-text.el
new file mode 100644 (file)
index 0000000..12bfc53
--- /dev/null
@@ -0,0 +1,130 @@
+;;;
+;;; tm-text.el --- a tm-view content filter to display
+;;;                text/plain, text/richtext and text/enriched
+;;;                in Emacs buffers
+;;;
+;;; Copyright (C) 1995 Free Software Foundation, Inc.
+;;; Copyright (C) 1994 .. 1996 MORIOKA Tomohiko
+;;;
+;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
+;;; Version:
+;;;    $Id: tm-text.el,v 7.11 1996/05/09 18:47:32 morioka Exp $
+;;; Keywords: mail, news, MIME, multimedia, text
+;;;
+;;; 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:
+
+;;; @ code conversion
+;;;
+
+(defvar mime-viewer/code-converter-alist
+  '((mime/show-message-mode      . mime-charset-decode-region)
+    (mime/temporary-message-mode . mime-charset-decode-region)
+    (t . mime-viewer/default-code-convert-region)
+    ))
+
+(defun mime-viewer/default-code-convert-region
+  (beg end charset &optional encoding)
+  (if (member encoding '("quoted-printable" "base64"))
+      (mime-charset-decode-region beg end charset)
+    ))
+
+(defun mime-preview/decode-text-region (beg end charset encoding)
+  (mime/decode-region encoding beg end)
+  (let* ((mode mime::preview/original-major-mode)
+        (m (or (save-excursion
+                 (set-buffer mime::preview/article-buffer)
+                 mime::article/code-converter)
+               (cdr (or (assq mode mime-viewer/code-converter-alist)
+                        (assq t mime-viewer/code-converter-alist)))
+               ))
+        )
+    (and (functionp m)
+        (funcall m beg (point-max) charset encoding)
+        )))
+
+
+;;; @ content filters for tm-view
+;;;
+
+(defun mime-preview/filter-for-text/plain (ctype params encoding)
+  (let ((charset (cdr (assoc "charset" params)))
+       (beg (point-min)) (end (point-max))
+       )
+    (mime-preview/decode-text-region beg end charset encoding)
+    )
+  (goto-char (point-max))
+  (if (not (eq (char-after (1- (point))) ?\n))
+      (insert "\n")
+    )
+  (if browse-url-browser-function
+      (progn
+       (goto-char (point-min))
+       (while (re-search-forward tm:URL-regexp nil t)
+         (let ((beg (match-beginning 0))
+               (end (match-end 0)))
+           (tm:add-button beg end
+                          (function tm:browse-url)
+                          (list (buffer-substring beg end))))
+         )))
+  (run-hooks 'mime-viewer/plain-text-preview-hook)
+  )
+
+(defun mime-preview/filter-for-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-preview/filter-for-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))
+    ))
+
+
+;;; @ end
+;;;
+
+(provide 'tm-text)
+
+;;; tm-text.el ends here