1 ;;; mcs-e20.el --- MIME charset implementation for Emacs 20.1 and 20.2
3 ;; Copyright (C) 1996,1997,1998,1999,2000 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <tomo@m17n.org>
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 ;; This module requires Emacs 20.1 and 20.2.
31 (eval-when-compile (require 'static))
33 (defsubst find-coding-system (obj)
34 "Return OBJ if it is a coding-system."
35 (if (coding-system-p obj)
38 (defsubst encode-mime-charset-region (start end charset &optional lbt)
39 "Encode the text between START and END as MIME CHARSET."
41 (if (and enable-multibyte-characters
42 (setq cs (mime-charset-to-coding-system charset lbt)))
43 (encode-coding-region start end cs)
46 (defsubst decode-mime-charset-region (start end charset &optional lbt)
47 "Decode the text between START and END as MIME CHARSET."
49 (if (and enable-multibyte-characters
50 (setq cs (mime-charset-to-coding-system charset lbt)))
51 (decode-coding-region start end cs)
55 (defsubst encode-mime-charset-string (string charset &optional lbt)
56 "Encode the STRING as MIME CHARSET."
58 (if (and enable-multibyte-characters
59 (setq cs (mime-charset-to-coding-system charset lbt)))
60 (encode-coding-string string cs)
63 (defsubst decode-mime-charset-string (string charset &optional lbt)
64 "Decode the STRING as MIME CHARSET."
66 (if (and enable-multibyte-characters
67 (setq cs (mime-charset-to-coding-system charset lbt)))
68 (decode-coding-string string cs)
72 (defvar charsets-mime-charset-alist
73 '(((ascii) . us-ascii)
74 ((ascii latin-iso8859-1) . iso-8859-1)
75 ((ascii latin-iso8859-2) . iso-8859-2)
76 ((ascii latin-iso8859-3) . iso-8859-3)
77 ((ascii latin-iso8859-4) . iso-8859-4)
78 ;;; ((ascii cyrillic-iso8859-5) . iso-8859-5)
79 ((ascii cyrillic-iso8859-5) . koi8-r)
80 ((ascii arabic-iso8859-6) . iso-8859-6)
81 ((ascii greek-iso8859-7) . iso-8859-7)
82 ((ascii hebrew-iso8859-8) . iso-8859-8)
83 ((ascii latin-iso8859-9) . iso-8859-9)
84 ((ascii latin-jisx0201
85 japanese-jisx0208-1978 japanese-jisx0208) . iso-2022-jp)
86 ((ascii latin-jisx0201
87 katakana-jisx0201 japanese-jisx0208) . shift_jis)
88 ((ascii korean-ksc5601) . euc-kr)
89 ((ascii chinese-gb2312) . gb2312)
90 ((ascii chinese-big5-1 chinese-big5-2) . big5)
91 ((ascii thai-tis620 composition) . tis-620)
92 ((ascii latin-iso8859-1 greek-iso8859-7
93 latin-jisx0201 japanese-jisx0208-1978
94 chinese-gb2312 japanese-jisx0208
95 korean-ksc5601 japanese-jisx0212) . iso-2022-jp-2)
96 ; ((ascii latin-iso8859-1 greek-iso8859-7
97 ; latin-jisx0201 japanese-jisx0208-1978
98 ; chinese-gb2312 japanese-jisx0208
99 ; korean-ksc5601 japanese-jisx0212
100 ; chinese-cns11643-1 chinese-cns11643-2) . iso-2022-int-1)
101 ; ((ascii latin-iso8859-1 latin-iso8859-2
102 ; cyrillic-iso8859-5 greek-iso8859-7
103 ; latin-jisx0201 japanese-jisx0208-1978
104 ; chinese-gb2312 japanese-jisx0208
105 ; korean-ksc5601 japanese-jisx0212
106 ; chinese-cns11643-1 chinese-cns11643-2
107 ; chinese-cns11643-3 chinese-cns11643-4
108 ; chinese-cns11643-5 chinese-cns11643-6
109 ; chinese-cns11643-7) . iso-2022-int-1)
112 (defun coding-system-to-mime-charset (coding-system)
113 "Convert CODING-SYSTEM to a MIME-charset.
114 Return nil if corresponding MIME-charset is not found."
115 (or (car (rassq coding-system mime-charset-coding-system-alist))
116 (coding-system-get coding-system 'mime-charset)
119 (defun mime-charset-list ()
120 "Return a list of all existing MIME-charset."
121 (let ((dest (mapcar (function car) mime-charset-coding-system-alist))
122 (rest coding-system-list)
126 (unless (rassq cs mime-charset-coding-system-alist)
127 (if (setq cs (coding-system-get cs 'mime-charset))
128 (or (rassq cs mime-charset-coding-system-alist)
130 (setq dest (cons cs dest))
132 (setq rest (cdr rest)))
135 (static-when (and (string= (decode-coding-string "\e.A\eN!" 'ctext) "\eN!")
136 (or (not (find-coding-system 'x-ctext))
137 (coding-system-get 'x-ctext 'apel)))
138 (unless (find-coding-system 'x-ctext)
141 "Compound text based generic encoding for decoding unknown messages."
142 '((ascii t) (latin-iso8859-1 t) t t
143 nil ascii-eol ascii-cntl nil locking-shift single-shift nil nil nil
145 '((safe-charsets . t)
146 (mime-charset . x-ctext)))
147 (coding-system-put 'x-ctext 'apel t)
155 (product-provide (provide 'mcs-e20) (require 'apel-ver))
157 ;;; mcs-e20.el ends here