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.13 1997-03-15 20:54:28 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.
32 (defvar mime-text-decoder-alist
33 '((mime/show-message-mode . mime-charset/decode-buffer)
34 (mime-temp-message-mode . mime-charset/decode-buffer)
35 (t . mime-charset/maybe-decode-buffer)
38 (defun mime-charset/decode-buffer (charset &optional encoding)
39 (decode-mime-charset-region (point-min)(point-max)
40 (or charset default-mime-charset))
43 (defun mime-charset/maybe-decode-buffer (charset &optional encoding)
44 (or (member encoding '(nil "7bit" "8bit" "binary"))
45 (mime-charset/decode-buffer charset)
48 (defun mime-preview/decode-text-buffer (charset encoding)
49 (mime-decode-region (point-min) (point-max) encoding)
50 (let ((m (save-excursion
51 (set-buffer mime::preview/article-buffer)
52 (or mime::article/code-converter
53 (cdr (or (assq major-mode mime-text-decoder-alist)
54 (assq t mime-text-decoder-alist)))
57 (funcall m charset encoding)
66 (defvar mime-text-url-regexp
67 "\\(http\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]"
68 "*Regexp to match URL in text/plain body.")
70 (defun mime-text-browse-url (&optional url)
71 (if (fboundp browse-url-browser-function)
73 (funcall browse-url-browser-function url)
74 (call-interactively browse-url-browser-function))
75 (if (fboundp mime-button-mother-dispatcher)
76 (call-interactively mime-button-mother-dispatcher)
81 ;;; @ content filters for mime-text
84 (defun mime-preview/filter-for-text/plain (ctype params encoding)
85 (mime-preview/decode-text-buffer (cdr (assoc "charset" params)) encoding)
86 (goto-char (point-max))
87 (if (not (eq (char-after (1- (point))) ?\n))
90 (if browse-url-browser-function
92 (goto-char (point-min))
93 (while (re-search-forward mime-text-url-regexp nil t)
94 (let ((beg (match-beginning 0))
96 (mime-add-button beg end
97 (function mime-text-browse-url)
98 (list (buffer-substring beg end))))
100 (run-hooks 'mime-view-plain-text-preview-hook)
103 (defun mime-preview/filter-for-text/richtext (ctype params encoding)
104 (let* ((mode mime::preview/original-major-mode)
105 (charset (cdr (assoc "charset" params)))
108 (remove-text-properties beg (point-max) '(face nil))
109 (mime-preview/decode-text-buffer charset encoding)
110 (richtext-decode beg (point-max))
113 (defun mime-preview/filter-for-text/enriched (ctype params encoding)
114 (let* ((mode mime::preview/original-major-mode)
115 (charset (cdr (assoc "charset" params)))
118 (remove-text-properties beg (point-max) '(face nil))
119 (mime-preview/decode-text-buffer charset encoding)
120 (enriched-decode beg (point-max))
129 ;;; mime-text.el ends here