1 ;;; mime-text.el --- mime-view content filter for text
3 ;; Copyright (C) 1994,1995,1996,1997 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; $Id: mime-text.el,v 0.17 1997-03-15 23:58:06 morioka Exp $
8 ;; Keywords: text, MIME, multimedia, mail, news
10 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
17 ;; This program is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;;; @ buffer local variables in raw-buffer
32 (defvar mime-text-decoder nil
33 "Function to decode text in current buffer.
34 Interface of the function is (CHARSET &optional ENCODING).
35 CHARSET is symbol of MIME charset and ENCODING is value of
36 Content-Transfer-Encoding.
38 Notice that this variable is usually used as buffer local variable in
41 (make-variable-buffer-local 'mime-text-decoder)
47 (defvar mime-text-decoder-alist
48 '((mime/show-message-mode . mime-charset/decode-buffer)
49 (mime-temp-message-mode . mime-charset/decode-buffer)
50 (t . mime-charset/maybe-decode-buffer)
53 (defun mime-charset/decode-buffer (charset &optional encoding)
54 (decode-mime-charset-region (point-min)(point-max)
55 (or charset default-mime-charset))
58 (defun mime-charset/maybe-decode-buffer (charset &optional encoding)
59 (or (member encoding '(nil "7bit" "8bit" "binary"))
60 (mime-charset/decode-buffer charset)
63 (defun mime-preview/decode-text-buffer (charset encoding)
64 (mime-decode-region (point-min) (point-max) encoding)
67 (set-buffer mime::preview/article-buffer)
69 (cdr (or (assq major-mode mime-text-decoder-alist)
70 (assq t mime-text-decoder-alist)))
72 (and (functionp text-decoder)
73 (funcall text-decoder charset encoding)
82 (defvar mime-text-url-regexp
83 "\\(http\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]"
84 "*Regexp to match URL in text/plain body.")
86 (defun mime-text-browse-url (&optional url)
87 (if (fboundp browse-url-browser-function)
89 (funcall browse-url-browser-function url)
90 (call-interactively browse-url-browser-function))
91 (if (fboundp mime-button-mother-dispatcher)
92 (call-interactively mime-button-mother-dispatcher)
97 ;;; @ content filters for mime-text
100 (defun mime-preview/filter-for-text/plain (ctype params encoding)
101 (mime-preview/decode-text-buffer (cdr (assoc "charset" params)) encoding)
102 (goto-char (point-max))
103 (if (not (eq (char-after (1- (point))) ?\n))
106 (if browse-url-browser-function
108 (goto-char (point-min))
109 (while (re-search-forward mime-text-url-regexp nil t)
110 (let ((beg (match-beginning 0))
112 (mime-add-button beg end
113 (function mime-text-browse-url)
114 (list (buffer-substring beg end))))
116 (run-hooks 'mime-view-plain-text-preview-hook)
119 (defun mime-preview/filter-for-text/richtext (ctype params encoding)
120 (let* ((charset (cdr (assoc "charset" params)))
123 (remove-text-properties beg (point-max) '(face nil))
124 (mime-preview/decode-text-buffer charset encoding)
125 (richtext-decode beg (point-max))
128 (defun mime-preview/filter-for-text/enriched (ctype params encoding)
129 (let* ((charset (cdr (assoc "charset" params)))
132 (remove-text-properties beg (point-max) '(face nil))
133 (mime-preview/decode-text-buffer charset encoding)
134 (enriched-decode beg (point-max))
143 ;;; mime-text.el ends here