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)))
47 (let ((str (mime-entity-content entity)))
49 (if (or (eq presentation-type 'binary)
50 (not (member (mime-entity-encoding entity)
51 '(nil "7bit" "8bit" "binary"))))
52 (decode-mime-charset-string
54 (or (mime-content-type-parameter
55 (mime-entity-content-type entity) "charset")
56 default-mime-charset))
59 (run-hooks 'mime-text-decode-hook)
68 (defvar mime-text-url-regexp
69 "\\(http\\|ftp\\|file\\|gopher\\|news\\|telnet\\|wais\\|mailto\\):\\(//[-a-zA-Z0-9_.]+:[0-9]*\\)?[-a-zA-Z0-9_=?#$@~`%&*+|\\/.,]*[-a-zA-Z0-9_=#$@~`%&*+|\\/]"
70 "*Regexp to match URL in text/plain body.")
72 (defun mime-text-browse-url (&optional url)
73 (if (fboundp browse-url-browser-function)
75 (funcall browse-url-browser-function url)
76 (call-interactively browse-url-browser-function))
77 (if (fboundp mime-button-mother-dispatcher)
78 (call-interactively mime-button-mother-dispatcher)
82 (defsubst mime-text-add-url-buttons ()
83 "Add URL-buttons for text body."
84 (goto-char (point-min))
85 (while (re-search-forward mime-text-url-regexp nil t)
86 (let ((beg (match-beginning 0))
88 (mime-add-button beg end #'mime-text-browse-url
89 (list (buffer-substring beg end)))
92 (defun mime-text-add-url-buttons-maybe ()
93 "Add URL-buttons if 'browse-url-browser-function is not 'nil."
94 (if browse-url-browser-function
95 (mime-text-add-url-buttons)
99 ;;; @ content filters for mime-text
102 (defun mime-display-text/plain (entity situation)
104 (narrow-to-region (point-max)(point-max))
105 (mime-text-insert-decoded-body entity)
106 (goto-char (point-max))
107 (if (not (eq (char-after (1- (point))) ?\n))
110 (mime-text-add-url-buttons)
111 (run-hooks 'mime-display-text/plain-hook)
114 (defun mime-display-text/richtext (entity situation)
116 (narrow-to-region (point-max)(point-max))
117 (mime-text-insert-decoded-body entity)
118 (let ((beg (point-min)))
119 (remove-text-properties beg (point-max) '(face nil))
120 (richtext-decode beg (point-max))
123 (defun mime-display-text/enriched (entity situation)
125 (narrow-to-region (point-max)(point-max))
126 (mime-text-insert-decoded-body entity)
127 (let ((beg (point-min)))
128 (remove-text-properties beg (point-max) '(face nil))
129 (enriched-decode beg (point-max))
138 ;;; mime-text.el ends here