1 ;;; mcs-nemacs.el --- MIME charset implementation for Nemacs
3 ;; Copyright (C) 1995,1996,1997,1998 MORIOKA Tomohiko
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: emulation, compatibility, Mule
8 ;; This file is part of APEL (A Portable Emacs Library).
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.
27 (defvar charsets-mime-charset-alist
28 '(((ascii) . us-ascii)))
30 (defvar default-mime-charset 'iso-2022-jp)
32 (defvar mime-charset-coding-system-alist
37 (defun mime-charset-to-coding-system (charset)
39 (setq charset (intern (downcase charset)))
41 (cdr (assq charset mime-charset-coding-system-alist)))
43 (defun detect-mime-charset-region (start end)
44 "Return MIME charset for region between START and END.
48 (narrow-to-region start end)
50 (re-search-forward "[\200-\377]" nil t)))
54 (defun encode-mime-charset-region (start end charset)
55 "Encode the text between START and END as MIME CHARSET.
57 (let ((cs (mime-charset-to-coding-system charset)))
62 (narrow-to-region start end)
63 (convert-region-kanji-code start end 3 cs))))
66 (defun decode-mime-charset-region (start end charset &optional lbt)
67 "Decode the text between START and END as MIME CHARSET.
69 (let ((cs (mime-charset-to-coding-system charset))
70 (nl (cdr (assq lbt '((CRLF . "\r\n") (CR . "\r")
71 (dos . "\r\n") (mac . "\r"))))))
76 (narrow-to-region start end)
77 (convert-region-kanji-code start end cs 3)
80 (goto-char (point-min))
81 (while (search-forward nl nil t)
82 (replace-match "\n")))
86 (defun encode-mime-charset-string (string charset)
87 "Encode the STRING as MIME CHARSET. [emu-nemacs.el]"
88 (let ((cs (mime-charset-to-coding-system charset)))
90 (convert-string-kanji-code string 3 cs)
93 (defun decode-mime-charset-string (string charset &optional lbt)
94 "Decode the STRING as MIME CHARSET. [emu-nemacs.el]"
97 (decode-mime-charset-region (point-min)(point-max) charset lbt)
100 (defun write-region-as-mime-charset (charset start end filename)
101 "Like `write-region', q.v., but code-convert by MIME CHARSET.
103 (let ((kanji-fileio-code
104 (or (mime-charset-to-coding-system charset) 0)))
105 (write-region start end filename)))
111 (provide 'mcs-nemacs)
113 ;;; mcs-nemacs.el ends here