1 ;;; mcs-e20.el --- MIME charset implementation for Emacs 20.1 and 20.2
3 ;; Copyright (C) 1996,1997,1998,1999 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.
36 (defsubst encode-mime-charset-region (start end charset &optional lbt)
37 "Encode the text between START and END as MIME CHARSET."
39 (if (and enable-multibyte-characters
40 (setq cs (mime-charset-to-coding-system charset lbt)))
41 (encode-coding-region start end cs)
44 (defsubst decode-mime-charset-region (start end charset &optional lbt)
45 "Decode the text between START and END as MIME CHARSET."
47 (if (and enable-multibyte-characters
48 (setq cs (mime-charset-to-coding-system charset lbt)))
49 (decode-coding-region start end cs)
53 (defsubst encode-mime-charset-string (string charset &optional lbt)
54 "Encode the STRING as MIME CHARSET."
56 (if (and enable-multibyte-characters
57 (setq cs (mime-charset-to-coding-system charset lbt)))
58 (encode-coding-string string cs)
61 (defsubst decode-mime-charset-string (string charset &optional lbt)
62 "Decode the STRING as MIME CHARSET."
64 (if (and enable-multibyte-characters
65 (setq cs (mime-charset-to-coding-system charset lbt)))
66 (decode-coding-string string cs)
70 (defvar charsets-mime-charset-alist
71 '(((ascii) . us-ascii)
72 ((ascii latin-iso8859-1) . iso-8859-1)
73 ((ascii latin-iso8859-2) . iso-8859-2)
74 ((ascii latin-iso8859-3) . iso-8859-3)
75 ((ascii latin-iso8859-4) . iso-8859-4)
76 ;;; ((ascii cyrillic-iso8859-5) . iso-8859-5)
77 ((ascii cyrillic-iso8859-5) . koi8-r)
78 ((ascii arabic-iso8859-6) . iso-8859-6)
79 ((ascii greek-iso8859-7) . iso-8859-7)
80 ((ascii hebrew-iso8859-8) . iso-8859-8)
81 ((ascii latin-iso8859-9) . iso-8859-9)
82 ((ascii latin-jisx0201
83 japanese-jisx0208-1978 japanese-jisx0208) . iso-2022-jp)
84 ((ascii latin-jisx0201
85 katakana-jisx0201 japanese-jisx0208) . shift_jis)
86 ((ascii korean-ksc5601) . euc-kr)
87 ((ascii chinese-gb2312) . gb2312)
88 ((ascii chinese-big5-1 chinese-big5-2) . big5)
89 ((ascii thai-tis620 composition) . tis-620)
90 ((ascii latin-iso8859-1 greek-iso8859-7
91 latin-jisx0201 japanese-jisx0208-1978
92 chinese-gb2312 japanese-jisx0208
93 korean-ksc5601 japanese-jisx0212) . iso-2022-jp-2)
94 ; ((ascii latin-iso8859-1 greek-iso8859-7
95 ; latin-jisx0201 japanese-jisx0208-1978
96 ; chinese-gb2312 japanese-jisx0208
97 ; korean-ksc5601 japanese-jisx0212
98 ; chinese-cns11643-1 chinese-cns11643-2) . iso-2022-int-1)
99 ; ((ascii latin-iso8859-1 latin-iso8859-2
100 ; cyrillic-iso8859-5 greek-iso8859-7
101 ; latin-jisx0201 japanese-jisx0208-1978
102 ; chinese-gb2312 japanese-jisx0208
103 ; korean-ksc5601 japanese-jisx0212
104 ; chinese-cns11643-1 chinese-cns11643-2
105 ; chinese-cns11643-3 chinese-cns11643-4
106 ; chinese-cns11643-5 chinese-cns11643-6
107 ; chinese-cns11643-7) . iso-2022-int-1)
110 (defun-maybe coding-system-get (coding-system prop)
111 "Extract a value from CODING-SYSTEM's property list for property PROP."
112 (plist-get (coding-system-plist coding-system) prop)
115 (defun coding-system-to-mime-charset (coding-system)
116 "Convert CODING-SYSTEM to a MIME-charset.
117 Return nil if corresponding MIME-charset is not found."
118 (or (car (rassq coding-system mime-charset-coding-system-alist))
119 (coding-system-get coding-system 'mime-charset)
122 (defun-maybe-cond mime-charset-list ()
123 "Return a list of all existing MIME-charset."
124 ((boundp 'coding-system-list)
125 (let ((dest (mapcar (function car) mime-charset-coding-system-alist))
126 (rest coding-system-list)
130 (unless (rassq cs mime-charset-coding-system-alist)
131 (if (setq cs (coding-system-get cs 'mime-charset))
132 (or (rassq cs mime-charset-coding-system-alist)
134 (setq dest (cons cs dest))
136 (setq rest (cdr rest)))
139 (let ((dest (mapcar (function car) mime-charset-coding-system-alist))
140 (rest (coding-system-list))
144 (unless (rassq cs mime-charset-coding-system-alist)
145 (when (setq cs (or (coding-system-get cs 'mime-charset)
148 (coding-system-get cs 'coding-spec)
150 (string-match "(MIME:[ \t]*\\([^,)]+\\)" cs)
151 (match-string 1 cs))))
152 (setq cs (intern (downcase cs)))
153 (or (rassq cs mime-charset-coding-system-alist)
155 (setq dest (cons cs dest))
157 (setq rest (cdr rest)))
161 (static-when (and (string= (decode-coding-string "\e.A\eN!" 'ctext) "\eN!")
162 (or (not (find-coding-system 'x-ctext))
163 (coding-system-get 'x-ctext 'apel)))
164 (unless (find-coding-system 'x-ctext)
167 "Compound text based generic encoding for decoding unknown messages."
168 '((ascii t) (latin-iso8859-1 t) t t
169 nil ascii-eol ascii-cntl nil locking-shift single-shift nil nil nil
171 '((safe-charsets . t)
172 (mime-charset . x-ctext)))
173 (coding-system-put 'x-ctext 'apel t)
184 ;;; mcs-e20.el ends here