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.
33 (defun mime-text-insert-decoded-body (entity)
34 "Insert text body of ENTITY in SITUATION.
35 It decodes MIME-encoding then code-converts as MIME-charset.
36 MIME-encoding is value of field 'encoding of SITUATION. It must be
37 'nil or string. MIME-charset is value of field \"charset\" of
38 SITUATION. It must be symbol."
39 (let* ((buffer (mime-entity-buffer entity))
43 (or mime-raw-representation-type
44 (cdr (or (assq major-mode mime-raw-representation-type-alist)
45 (assq t mime-raw-representation-type-alist)))
48 (insert-buffer-substring buffer
49 (mime-entity-body-start entity)
50 (mime-entity-body-end entity))
51 (let ((encoding (mime-entity-encoding entity)))
52 (mime-decode-region (point-min) (point-max) encoding)
53 (if (or (eq presentation-type 'binary)
54 (not (member encoding '(nil "7bit" "8bit" "binary"))))
55 (decode-mime-charset-region (point-min)(point-max)
56 (or (mime-content-type-parameter
57 (mime-entity-content-type entity)
59 default-mime-charset))
61 (run-hooks 'mime-text-decode-hook)
70 (defvar mime-text-url-regexp
71 "\\(http\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]"
72 "*Regexp to match URL in text/plain body.")
74 (defun mime-text-browse-url (&optional url)
75 (if (fboundp browse-url-browser-function)
77 (funcall browse-url-browser-function url)
78 (call-interactively browse-url-browser-function))
79 (if (fboundp mime-button-mother-dispatcher)
80 (call-interactively mime-button-mother-dispatcher)
84 (defsubst mime-text-add-url-buttons ()
85 "Add URL-buttons for text body."
86 (goto-char (point-min))
87 (while (re-search-forward mime-text-url-regexp nil t)
88 (let ((beg (match-beginning 0))
90 (mime-add-button beg end #'mime-text-browse-url
91 (list (buffer-substring beg end)))
94 (defun mime-text-add-url-buttons-maybe ()
95 "Add URL-buttons if 'browse-url-browser-function is not 'nil."
96 (if browse-url-browser-function
97 (mime-text-add-url-buttons)
101 ;;; @ content filters for mime-text
104 (defun mime-preview-text/plain (entity situation)
106 (narrow-to-region (point-max)(point-max))
107 (mime-text-insert-decoded-body entity)
108 (goto-char (point-max))
109 (if (not (eq (char-after (1- (point))) ?\n))
112 (mime-text-add-url-buttons)
113 (run-hooks 'mime-preview-text/plain-hook)
116 (defun mime-preview-text/richtext (entity situation)
118 (narrow-to-region (point-max)(point-max))
119 (mime-text-insert-decoded-body entity)
120 (let ((beg (point-min)))
121 (remove-text-properties beg (point-max) '(face nil))
122 (richtext-decode beg (point-max))
125 (defun mime-preview-text/enriched (entity situation)
127 (narrow-to-region (point-max)(point-max))
128 (mime-text-insert-decoded-body entity)
129 (let ((beg (point-min)))
130 (remove-text-properties beg (point-max) '(face nil))
131 (enriched-decode beg (point-max))
140 ;;; mime-text.el ends here