Merge semi-1_9_1.
[elisp/semi.git] / mime-text.el
1 ;;; mime-text.el --- mime-view content filter for text
2
3 ;; Copyright (C) 1994,1995,1996,1997,1998 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: text, MIME, multimedia, mail, news
7
8 ;; This file is part of SEMI (Suite of Emacs MIME Interfaces).
9
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.
14
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.
19
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.
24
25 ;;; Code:
26
27 (require 'mime-view)
28
29
30 ;;; @ code conversion
31 ;;;
32
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 ((str (mime-entity-content entity)))
40     (insert
41      (if (and (mime-entity-cooked-p entity)
42               (member (mime-entity-encoding entity)
43                       '(nil "7bit" "8bit" "binary")))
44          str
45        (decode-mime-charset-string str
46                                    (or (mime-content-type-parameter
47                                         (mime-entity-content-type entity)
48                                         "charset")
49                                        default-mime-charset)
50                                    'CRLF)
51        )))
52   (run-hooks 'mime-text-decode-hook)
53   )
54
55
56 ;;; @ content filters for mime-text
57 ;;;
58
59 (defun mime-display-text/plain (entity situation)
60   (save-restriction
61     (narrow-to-region (point-max)(point-max))
62     (mime-text-insert-decoded-body entity)
63     (goto-char (point-max))
64     (if (not (eq (char-after (1- (point))) ?\n))
65         (insert "\n")
66       )
67     (mime-add-url-buttons)
68     (run-hooks 'mime-display-text/plain-hook)
69     ))
70
71 (defun mime-display-text/richtext (entity situation)
72   (save-restriction
73     (narrow-to-region (point-max)(point-max))
74     (mime-text-insert-decoded-body entity)
75     (let ((beg (point-min)))
76       (remove-text-properties beg (point-max) '(face nil))
77       (richtext-decode beg (point-max))
78       )))
79
80 (defun mime-display-text/enriched (entity situation)
81   (save-restriction
82     (narrow-to-region (point-max)(point-max))
83     (mime-text-insert-decoded-body entity)
84     (let ((beg (point-min)))
85       (remove-text-properties beg (point-max) '(face nil))
86       (enriched-decode beg (point-max))
87       )))
88
89
90 ;;; @ end
91 ;;;
92
93 (provide 'mime-text)
94
95 ;;; mime-text.el ends here