Merge poe.
[elisp/apel.git] / mcs-ltn1.el
1 ;;; mcs-ltn1.el --- MIME charset implementation for Emacs 19
2 ;;;                 and XEmacs without MULE
3
4 ;; Copyright (C) 1995,1996,1997,1998 MORIOKA Tomohiko
5
6 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
7 ;; Keywords: emulation, compatibility, Mule
8
9 ;; This file is part of APEL (A Portable Emacs Library).
10
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.
15
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.
20
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.
25
26 ;;; Code:
27
28 (defvar charsets-mime-charset-alist
29   '(((ascii) . us-ascii)))
30
31 (defvar default-mime-charset 'iso-8859-1)
32
33 (defun mime-charset-to-coding-system (charset)
34   (if (stringp charset)
35       (setq charset (intern (downcase charset)))
36     )
37   (if (memq charset (list 'us-ascii default-mime-charset))
38       charset
39     ))
40
41 (defun detect-mime-charset-region (start end)
42   "Return MIME charset for region between START and END."
43   (if (save-excursion
44         (goto-char start)
45         (re-search-forward "[\200-\377]" end t))
46       default-mime-charset
47     'us-ascii))
48
49 (defun encode-mime-charset-region (start end charset)
50   "Encode the text between START and END as MIME CHARSET."
51   )
52
53 (defun decode-mime-charset-region (start end charset &optional lbt)
54   "Decode the text between START and END as MIME CHARSET."
55   (cond ((eq lbt 'CRLF)
56          (save-excursion
57            (save-restriction
58              (narrow-to-region start end)
59              (goto-char (point-min))
60              (while (search-forward "\r\n" nil t)
61                (replace-match "\n"))
62              ))
63          )))
64
65 (defun encode-mime-charset-string (string charset)
66   "Encode the STRING as MIME CHARSET."
67   string)
68
69 (defun decode-mime-charset-string (string charset &optional lbt)
70   "Decode the STRING as MIME CHARSET."
71   (if lbt
72       (with-temp-buffer
73         (insert string)
74         (decode-mime-charset-region (point-min)(point-max) charset lbt)
75         (buffer-string))
76     string))
77
78 (defalias 'write-region-as-mime-charset 'write-region)
79
80
81 ;;; @ end
82 ;;;
83
84 (provide 'mcs-ltn1)
85
86 ;;; mcs-ltn1.el ends here