2 ;;; tm-text.el --- a tm-view content filter to display
3 ;;; text/plain, text/richtext and text/enriched
6 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
7 ;;; Copyright (C) 1994 .. 1996 MORIOKA Tomohiko
9 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
11 ;;; $Id: tm-text.el,v 7.11 1996/05/09 18:47:32 morioka Exp $
12 ;;; Keywords: mail, news, MIME, multimedia, text
14 ;;; This file is part of tm (Tools for MIME).
16 ;;; This program is free software; you can redistribute it and/or
17 ;;; modify it under the terms of the GNU General Public License as
18 ;;; published by the Free Software Foundation; either version 2, or
19 ;;; (at your option) any later version.
21 ;;; This program is distributed in the hope that it will be useful,
22 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 ;;; General Public License for more details.
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with This program. If not, write to the Free Software
28 ;;; Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
35 (defvar mime-viewer/code-converter-alist
36 '((mime/show-message-mode . mime-charset-decode-region)
37 (mime/temporary-message-mode . mime-charset-decode-region)
38 (t . mime-viewer/default-code-convert-region)
41 (defun mime-viewer/default-code-convert-region
42 (beg end charset &optional encoding)
43 (if (member encoding '("quoted-printable" "base64"))
44 (mime-charset-decode-region beg end charset)
47 (defun mime-preview/decode-text-region (beg end charset encoding)
48 (mime/decode-region encoding beg end)
49 (let* ((mode mime::preview/original-major-mode)
50 (m (or (save-excursion
51 (set-buffer mime::preview/article-buffer)
52 mime::article/code-converter)
53 (cdr (or (assq mode mime-viewer/code-converter-alist)
54 (assq t mime-viewer/code-converter-alist)))
58 (funcall m beg (point-max) charset encoding)
62 ;;; @ content filters for tm-view
65 (defun mime-preview/filter-for-text/plain (ctype params encoding)
66 (let ((charset (cdr (assoc "charset" params)))
67 (beg (point-min)) (end (point-max))
69 (mime-preview/decode-text-region beg end charset encoding)
71 (goto-char (point-max))
72 (if (not (eq (char-after (1- (point))) ?\n))
75 (if browse-url-browser-function
77 (goto-char (point-min))
78 (while (re-search-forward tm:URL-regexp nil t)
79 (let ((beg (match-beginning 0))
81 (tm:add-button beg end
82 (function tm:browse-url)
83 (list (buffer-substring beg end))))
85 (run-hooks 'mime-viewer/plain-text-preview-hook)
88 (defun mime-preview/filter-for-text/richtext (ctype params encoding)
89 (let* ((mode mime::preview/original-major-mode)
90 (m (assq mode mime-viewer/code-converter-alist))
91 (charset (assoc "charset" params))
92 ;; 1995/9/21 (c.f. tm-eng:105), 1995/10/3 (c.f. tm-eng:121)
93 ;; modified by Eric Ding <ericding@San-Jose.ate.slb.com>
94 (beg (point-min)) (end (point-max))
96 (remove-text-properties beg end '(face nil))
97 (mime/decode-region encoding beg end)
98 (if (and m (fboundp (setq m (cdr m))))
99 (funcall m beg (point-max) charset encoding)
100 (mime-viewer/default-code-convert-region beg (point-max)
103 (richtext-decode beg (point-max))
106 (defun mime-preview/filter-for-text/enriched (ctype params encoding)
107 (let* ((mode mime::preview/original-major-mode)
108 (m (assq mode mime-viewer/code-converter-alist))
109 (charset (assoc "charset" params))
110 ;; 1995/9/21 (c.f. tm-eng:105), 1995/10/3 (c.f. tm-eng:121)
111 ;; modified by Eric Ding <ericding@San-Jose.ate.slb.com>
112 (beg (point-min)) (end (point-max))
114 (remove-text-properties beg end '(face nil))
115 (mime/decode-region encoding beg end)
116 (if (and m (fboundp (setq m (cdr m))))
117 (funcall m beg (point-max) charset encoding)
118 (mime-viewer/default-code-convert-region beg (point-max)
121 (enriched-decode beg (point-max))
130 ;;; tm-text.el ends here