comparison lisp/tm/tm-text.el @ 4:b82b59fe008d r19-15b3

Import from CVS: tag r19-15b3
author cvs
date Mon, 13 Aug 2007 08:46:56 +0200
parents
children 4b173ad71786
comparison
equal deleted inserted replaced
3:30df88044ec6 4:b82b59fe008d
1 ;;;
2 ;;; tm-text.el --- a content filter module of tm-view to display
3 ;;; text/plain, text/richtext and text/enriched
4 ;;; in Emacs buffers
5 ;;;
6 ;;; Copyright (C) 1995 Free Software Foundation, Inc.
7 ;;; Copyright (C) 1994 .. 1996 MORIOKA Tomohiko
8 ;;;
9 ;;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
10 ;;; Version:
11 ;;; $Id: tm-text.el,v 1.1.1.1 1996/12/18 03:55:32 steve Exp $
12 ;;; Keywords: mail, news, MIME, multimedia, text
13 ;;;
14 ;;; This file is part of tm (Tools for MIME).
15 ;;;
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.
20 ;;;
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.
25 ;;;
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.
29 ;;;
30 ;;; Code:
31
32 ;;; @ code conversion
33 ;;;
34
35 (defvar mime-viewer/code-converter-alist
36 '((mime/show-message-mode . mime-charset/decode-buffer)
37 (mime/temporary-message-mode . mime-charset/decode-buffer)
38 (t . mime-charset/maybe-decode-buffer)
39 ))
40
41 (defun mime-charset/decode-buffer (charset &optional encoding)
42 (decode-mime-charset-region (point-min)(point-max)
43 (or charset default-mime-charset))
44 )
45
46 (defun mime-charset/maybe-decode-buffer (charset &optional encoding)
47 (or (member encoding '(nil "7bit" "8bit" "binary"))
48 (mime-charset/decode-buffer charset)
49 ))
50
51 (defun mime-preview/decode-text-buffer (charset encoding)
52 (mime-decode-region (point-min) (point-max) encoding)
53 (let* ((mode mime::preview/original-major-mode)
54 (m (or (save-excursion
55 (set-buffer mime::preview/article-buffer)
56 mime::article/code-converter)
57 (cdr (or (assq mode mime-viewer/code-converter-alist)
58 (assq t mime-viewer/code-converter-alist)))
59 ))
60 )
61 (and (functionp m)
62 (funcall m charset encoding)
63 )))
64
65
66 ;;; @ content filters for tm-view
67 ;;;
68
69 (defun mime-preview/filter-for-text/plain (ctype params encoding)
70 (mime-preview/decode-text-buffer (cdr (assoc "charset" params)) encoding)
71 (goto-char (point-max))
72 (if (not (eq (char-after (1- (point))) ?\n))
73 (insert "\n")
74 )
75 (if browse-url-browser-function
76 (progn
77 (goto-char (point-min))
78 (while (re-search-forward tm:URL-regexp nil t)
79 (let ((beg (match-beginning 0))
80 (end (match-end 0)))
81 (tm:add-button beg end
82 (function tm:browse-url)
83 (list (buffer-substring beg end))))
84 )))
85 (run-hooks 'mime-viewer/plain-text-preview-hook)
86 )
87
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 (cdr (assoc "charset" params)))
92 (beg (point-min))
93 )
94 (remove-text-properties beg (point-max) '(face nil))
95 (mime-preview/decode-text-buffer charset encoding)
96 (richtext-decode beg (point-max))
97 ))
98
99 (defun mime-preview/filter-for-text/enriched (ctype params encoding)
100 (let* ((mode mime::preview/original-major-mode)
101 (m (assq mode mime-viewer/code-converter-alist))
102 (charset (cdr (assoc "charset" params)))
103 (beg (point-min))
104 )
105 (remove-text-properties beg (point-max) '(face nil))
106 (mime-preview/decode-text-buffer charset encoding)
107 (enriched-decode beg (point-max))
108 ))
109
110
111 ;;; @ end
112 ;;;
113
114 (provide 'tm-text)
115
116 ;;; tm-text.el ends here