1 ;;; mime-text.el --- mime-view content filter for text
3 ;; Copyright (C) 1994,1995,1996,1997,1998 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: text, MIME, multimedia, mail, news
8 ;; This file is part of SEMI (Suite of Emacs MIME Interfaces).
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
30 ;;; @ buffer local variables in raw-buffer
33 (defvar mime-raw-representation-type nil
34 "Representation-type of mime-raw-buffer.
35 It must be nil, `binary' or `cooked'.
36 If it is nil, `mime-raw-representation-type-alist' is used as default
38 Notice that this variable is usually used as buffer local variable in
41 (make-variable-buffer-local 'mime-raw-representation-type)
47 (defun mime-text-insert-decoded-body (entity)
48 "Insert text body of ENTITY in SITUATION.
49 It decodes MIME-encoding then code-converts as MIME-charset.
50 MIME-encoding is value of field 'encoding of SITUATION. It must be
51 'nil or string. MIME-charset is value of field \"charset\" of
52 SITUATION. It must be symbol."
53 (let ((presentation-type
55 (set-buffer mime-raw-buffer)
56 (or mime-raw-representation-type
57 (cdr (or (assq major-mode mime-raw-representation-type-alist)
58 (assq t mime-raw-representation-type-alist)))
61 (insert-buffer-substring mime-raw-buffer
62 (mime-entity-body-start entity)
63 (mime-entity-body-end entity))
64 (let ((encoding (mime-entity-encoding entity)))
65 (mime-decode-region (point-min) (point-max) encoding)
66 (if (or (eq presentation-type 'binary)
67 (not (member encoding '(nil "7bit" "8bit" "binary"))))
68 (decode-mime-charset-region (point-min)(point-max)
69 (or (mime-content-type-parameter
70 (mime-entity-content-type entity)
72 default-mime-charset))
74 (run-hooks 'mime-text-decode-hook)
83 (defvar mime-text-url-regexp
84 "\\(http\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]"
85 "*Regexp to match URL in text/plain body.")
87 (defun mime-text-browse-url (&optional url)
88 (if (fboundp browse-url-browser-function)
90 (funcall browse-url-browser-function url)
91 (call-interactively browse-url-browser-function))
92 (if (fboundp mime-button-mother-dispatcher)
93 (call-interactively mime-button-mother-dispatcher)
97 (defsubst mime-text-add-url-buttons ()
98 "Add URL-buttons for text body."
99 (goto-char (point-min))
100 (while (re-search-forward mime-text-url-regexp nil t)
101 (let ((beg (match-beginning 0))
103 (mime-add-button beg end #'mime-text-browse-url
104 (list (buffer-substring beg end)))
107 (defun mime-text-add-url-buttons-maybe ()
108 "Add URL-buttons if 'browse-url-browser-function is not 'nil."
109 (if browse-url-browser-function
110 (mime-text-add-url-buttons)
114 ;;; @ content filters for mime-text
117 (defun mime-preview-text/plain (entity situation)
119 (narrow-to-region (point-max)(point-max))
120 (mime-text-insert-decoded-body entity)
121 (goto-char (point-max))
122 (if (not (eq (char-after (1- (point))) ?\n))
125 (mime-text-add-url-buttons)
126 (run-hooks 'mime-preview-text/plain-hook)
129 (defun mime-preview-text/richtext (entity situation)
131 (narrow-to-region (point-max)(point-max))
132 (mime-text-insert-decoded-body entity)
133 (let ((beg (point-min)))
134 (remove-text-properties beg (point-max) '(face nil))
135 (richtext-decode beg (point-max))
138 (defun mime-preview-text/enriched (entity situation)
140 (narrow-to-region (point-max)(point-max))
141 (mime-text-insert-decoded-body entity)
142 (let ((beg (point-min)))
143 (remove-text-properties beg (point-max) '(face nil))
144 (enriched-decode beg (point-max))
153 ;;; mime-text.el ends here