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.
32 (eval-when-compile (require 'static))
34 (defsubst encode-mime-charset-region (start end charset &optional lbt)
35 "Encode the text between START and END as MIME CHARSET."
37 (if (and enable-multibyte-characters
38 (setq cs (mime-charset-to-coding-system charset lbt)))
39 (encode-coding-region start end cs)
42 (defsubst decode-mime-charset-region (start end charset &optional lbt)
43 "Decode the text between START and END as MIME CHARSET."
45 (if (and enable-multibyte-characters
46 (setq cs (mime-charset-to-coding-system charset lbt)))
47 (decode-coding-region start end cs)
51 (defsubst encode-mime-charset-string (string charset &optional lbt)
52 "Encode the STRING as MIME CHARSET."
54 (if (and enable-multibyte-characters
55 (setq cs (mime-charset-to-coding-system charset lbt)))
56 (encode-coding-string string cs)
59 (defsubst decode-mime-charset-string (string charset &optional lbt)
60 "Decode the STRING as MIME CHARSET."
62 (if (and enable-multibyte-characters
63 (setq cs (mime-charset-to-coding-system charset lbt)))
64 (decode-coding-string string cs)
68 (defvar charsets-mime-charset-alist
69 `(((ascii) . us-ascii)
70 ((ascii latin-iso8859-1) . iso-8859-1)
71 ((ascii latin-iso8859-2) . iso-8859-2)
72 ((ascii latin-iso8859-3) . iso-8859-3)
73 ((ascii latin-iso8859-4) . iso-8859-4)
74 ;;; ((ascii cyrillic-iso8859-5) . iso-8859-5)
75 ((ascii cyrillic-iso8859-5) . koi8-r)
76 ((ascii arabic-iso8859-6) . iso-8859-6)
77 ((ascii greek-iso8859-7) . iso-8859-7)
78 ((ascii hebrew-iso8859-8) . iso-8859-8)
79 ((ascii latin-iso8859-9) . iso-8859-9)
80 ,(if (find-coding-system 'iso-8859-14)
81 '((ascii latin-iso8859-14) . iso-8859-14))
82 ,(if (find-coding-system 'iso-8859-15)
83 '((ascii latin-iso8859-15) . iso-8859-15))
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-maybe coding-system-get (coding-system prop)
113 "Extract a value from CODING-SYSTEM's property list for property PROP."
114 (plist-get (coding-system-plist coding-system) prop)
117 (defun coding-system-to-mime-charset (coding-system)
118 "Convert CODING-SYSTEM to a MIME-charset.
119 Return nil if corresponding MIME-charset is not found."
120 (or (car (rassq coding-system mime-charset-coding-system-alist))
121 (coding-system-get coding-system 'mime-charset)
124 (defun-maybe-cond mime-charset-list ()
125 "Return a list of all existing MIME-charset."
126 ((boundp 'coding-system-list)
127 (let ((dest (mapcar (function car) mime-charset-coding-system-alist))
128 (rest coding-system-list)
132 (unless (rassq cs mime-charset-coding-system-alist)
133 (if (setq cs (coding-system-get cs 'mime-charset))
134 (or (rassq cs mime-charset-coding-system-alist)
136 (setq dest (cons cs dest))
138 (setq rest (cdr rest)))
141 (let ((dest (mapcar (function car) mime-charset-coding-system-alist))
142 (rest (coding-system-list))
146 (unless (rassq cs mime-charset-coding-system-alist)
147 (when (setq cs (or (coding-system-get cs 'mime-charset)
150 (coding-system-get cs 'coding-spec)
152 (string-match "(MIME:[ \t]*\\([^,)]+\\)" cs)
153 (match-string 1 cs))))
154 (setq cs (intern (downcase cs)))
155 (or (rassq cs mime-charset-coding-system-alist)
157 (setq dest (cons cs dest))
159 (setq rest (cdr rest)))
163 (static-when (and (string= (decode-coding-string "\e.A\eN!" 'ctext) "\eN!")
164 (or (not (find-coding-system 'x-ctext))
165 (coding-system-get 'x-ctext 'apel)))
166 (unless (find-coding-system 'x-ctext)
169 "Compound text based generic encoding for decoding unknown messages."
170 '((ascii t) (latin-iso8859-1 t) t t
171 nil ascii-eol ascii-cntl nil locking-shift single-shift nil nil nil
173 '((safe-charsets . t)
174 (mime-charset . x-ctext)))
175 (coding-system-put 'x-ctext 'apel t)
183 (product-provide (provide 'mcs-e20) (require 'apel-ver))
185 ;;; mcs-e20.el ends here