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>
6 ;; Version: $Id: mime-text.el,v 0.24 1997-07-02 16:20:22 morioka Exp $
7 ;; Keywords: text, MIME, multimedia, mail, news
9 ;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;;; @ buffer local variables in raw-buffer
31 (defvar mime-text-decoder nil
32 "Function to decode text in current buffer.
33 Interface of the function is (CHARSET &optional ENCODING).
34 CHARSET is symbol of MIME charset and ENCODING is value of
35 Content-Transfer-Encoding.
37 Notice that this variable is usually used as buffer local variable in
40 (make-variable-buffer-local 'mime-text-decoder)
46 (defvar mime-text-decoder-alist
47 '((mime-show-message-mode . mime-text-decode-buffer)
48 (mime-temp-message-mode . mime-text-decode-buffer)
49 (t . mime-text-decode-buffer-maybe)
51 "Alist of major-mode vs. mime-text-decoder.
52 Each element looks like (SYMBOL . FUNCTION). SYMBOL is major-mode or
55 Specification of FUNCTION is described in DOC-string of variable
58 This value is overridden by buffer local variable `mime-text-decoder'
61 (defun mime-text-decode-buffer (charset &optional encoding)
62 "Decode text of current buffer as CHARSET.
63 It code-converts current buffer from network representation specified
64 by MIME CHARSET to internal code. CHARSET is symbol of MIME charset.
65 See also variable `mime-charset-coding-system-alist'."
66 (decode-mime-charset-region (point-min)(point-max)
67 (or charset default-mime-charset))
70 (defun mime-text-decode-buffer-maybe (charset &optional encoding)
71 "Decode text of current buffer as CHARSET if ENCODING is actual encoding.
72 It code-converts current buffer from network representation specified
73 by MIME CHARSET to internal code if ENCODING is not nil, \"7bit\",
74 \"8bit\" or \"binary\". CHARSET is symbol of MIME charset.
75 See also variable `mime-charset-coding-system-alist'."
76 (or (member encoding '(nil "7bit" "8bit" "binary"))
77 (mime-text-decode-buffer charset)
80 (defun mime-decode-text-body (charset encoding)
81 "Decode current buffer as text body.
82 It decodes MIME-encoding as ENCODING then code-converts as MIME
83 CHARSET. CHARSET is SYMBOL and ENCODING is nil or STRING.
85 It calls text decoder for MIME charset specified by buffer local
86 variable `mime-text-decoder' and variable `mime-text-decoder-alist'."
87 (mime-decode-region (point-min) (point-max) encoding)
88 (goto-char (point-min))
89 (while (search-forward "\r\n" nil t)
94 (set-buffer mime-raw-buffer)
96 (cdr (or (assq major-mode mime-text-decoder-alist)
97 (assq t mime-text-decoder-alist)))
99 (and (functionp text-decoder)
100 (funcall text-decoder charset encoding)
107 (require 'browse-url)
109 (defvar mime-text-url-regexp
110 "\\(http\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]"
111 "*Regexp to match URL in text/plain body.")
113 (defun mime-text-browse-url (&optional url)
114 (if (fboundp browse-url-browser-function)
116 (funcall browse-url-browser-function url)
117 (call-interactively browse-url-browser-function))
118 (if (fboundp mime-button-mother-dispatcher)
119 (call-interactively mime-button-mother-dispatcher)
124 ;;; @ content filters for mime-text
127 (defun mime-view-filter-for-text/plain (ctype params encoding)
128 (mime-decode-text-body (cdr (assoc "charset" params)) encoding)
129 (goto-char (point-max))
130 (if (not (eq (char-after (1- (point))) ?\n))
133 (if browse-url-browser-function
135 (goto-char (point-min))
136 (while (re-search-forward mime-text-url-regexp nil t)
137 (let ((beg (match-beginning 0))
139 (mime-add-button beg end
140 (function mime-text-browse-url)
141 (list (buffer-substring beg end))))
143 (run-hooks 'mime-view-plain-text-preview-hook)
146 (defun mime-view-filter-for-text/richtext (ctype params encoding)
147 (let* ((charset (cdr (assoc "charset" params)))
150 (remove-text-properties beg (point-max) '(face nil))
151 (mime-decode-text-body charset encoding)
152 (richtext-decode beg (point-max))
155 (defun mime-view-filter-for-text/enriched (ctype params encoding)
156 (let* ((charset (cdr (assoc "charset" params)))
159 (remove-text-properties beg (point-max) '(face nil))
160 (mime-decode-text-body charset encoding)
161 (enriched-decode beg (point-max))
170 ;;; mime-text.el ends here