-;; Emacs 18 implementations
-
-(defun mime-body-charset-chooser-for-emacs18 (begin end)
- "Return a cons of charset and encoding of a message in a given region.
-Encoding name must be a canonical name, such as `base64'."
- '("US-ASCII" . nil) ;Default charset of MIME.
- )
-
-(defun mime-string-encoder-for-emacs18 (method string)
- "For given METHOD that is a cons of charset and encoding, encode a STRING."
- (let ((charset (car method))
- (encoding (cdr method)))
- (cond ((stringp encoding)
- (mime-encode-string encoding string))
- ;; Return string without any encoding.
- (t string)
- )))
-
-\f
-;; Emacs 19 implementations
-
-(defun mime-body-charset-chooser-for-emacs19 (begin end)
- "Return a cons of charset and encoding of a message in a given region.
-Encoding name must be a canonical name, such as `base64'.
-US-ASCII and ISO-8859-1 are supported on Emacs 19."
- (cond ((save-excursion
- (goto-char begin)
- (re-search-forward "[\200-\377]" end t))
- '("ISO-8859-1" . "quoted-printable"))
- (t
- '("US-ASCII" . nil)) ;Default charset of MIME.
- ))
-
-(defun mime-string-encoder-for-emacs19 (method string)
- "For given METHOD that is a cons of charset and encoding, encode a STRING."
- (let ((charset (car method))
- (encoding (cdr method)))
- (cond ((stringp encoding)
- (mime-encode-string encoding string))
- ;; Return string without any encoding.
- (t string)
- )))
-
-\f
-;; NEmacs implementations
-
-(defun mime-body-charset-chooser-for-nemacs (begin end)
- "Return a cons of charset and encoding of a message in a given region.
-Encoding name must be a canonical name, such as `base64'.
-US-ASCII and ISO-2022-JP are supported on NEmacs."
- (cond ((check-region-kanji-code begin end)
- ;; The following are safe encoding methods for use in
- ;; USENET News systems that strip off all ESCs.
- ;; '("ISO-2022-JP" . "quoted-printable")
- ;; '("ISO-2022-JP" . "base64")
- ;; The following expects transport systems are all MIME
- ;; compliants. For instance, ESCs are never stripped off.
- '("ISO-2022-JP" . nil))
- (t
- '("US-ASCII" . nil)) ;Default charset of MIME.
- ))
-
-(defun mime-string-encoder-for-nemacs (method string)
- "For given METHOD that is a cons of charset and encoding, encode a STRING.
-US-ASCII and ISO-2022-JP are supported on NEmacs."
- (let ((charset (car method))
- (encoding (cdr method)))
- (cond ((stringp encoding)
- (mime-encode-string encoding
- ;; Convert internal (EUC) to JIS code.
- (convert-string-kanji-code string 3 2)
- ))
- ;; NEmacs can convert into ISO-2022-JP automatically,
- ;; but can do it myself as follows:
- ;;(t (convert-string-kanji-code string 3 2))
-
- ;; Return string without any encoding.
- (t string)
- )))
-
-\f
-;; Mule implementations
-;; Thanks to contributions by wkenji@flab.fujitsu.co.jp (Kenji
-;; WAKAMIYA) and handa@etl.go.jp (Kenichi Handa).
-
-(defun mime-body-charset-chooser-for-mule (begin end)
- "Return a cons of charset and encoding of a message in a given
-region. Encoding name must be a canonical name, such as `base64'.
-US-ASCII, ISO-8859-* (except for ISO-8859-6), ISO-2022-JP,
-ISO-2022-JP-2 and ISO-2022-INT-1 are supported on Mule. Either of
-charset ISO-2022-JP-2 or ISO-2022-INT-1 is used for multilingual text
-in Mule."
- (let ((lclist (find-charset-region begin end)))
- (cond ((null lclist)
- '("US-ASCII" . nil)) ;Default charset of MIME.
- ;; Multilingual capability requred.
- ((and (> (length lclist) 1)
- (boundp '*iso-2022-int-1*))
- '("ISO-2022-INT-1" . nil))
- ((> (length lclist) 1)
- '("ISO-2022-JP-2" . nil))
- ;; Simple charset.
- ((memq lc-ltn1 lclist)
- '("ISO-8859-1" . "quoted-printable"))
- ((memq lc-ltn2 lclist)
- '("ISO-8859-2" . "quoted-printable"))
- ((memq lc-ltn3 lclist)
- '("ISO-8859-3" . "quoted-printable"))
- ((memq lc-ltn4 lclist)
- '("ISO-8859-4" . "quoted-printable"))
- ((memq lc-crl lclist)
- '("ISO-8859-5" . "quoted-printable"))
- ;;((memq lc-arb lclist)
- ;; '("ISO-8859-6" . "quoted-printable"))
- ((memq lc-grk lclist)
- '("ISO-8859-7" . "quoted-printable"))
- ((memq lc-hbw lclist)
- '("ISO-8859-8" . "quoted-printable"))
- ((memq lc-ltn5 lclist)
- '("ISO-8859-9" . "quoted-printable"))
- ((memq lc-jp lclist)
- '("ISO-2022-JP" . nil))
- ((memq lc-kr lclist)
- '("ISO-2022-KR" . nil))
- ;; Unknown charset.
- ((boundp '*iso-2022-int-1*)
- '("ISO-2022-INT-1" . nil))
- (t
- '("ISO-2022-JP-2" . nil))
- )))
-
-(defun mime-string-encoder-for-mule (method string)
- "For given METHOD that is a cons of charset and encoding, encode a
-STRING. US-ASCII, ISO-8859-* (except for ISO-8859-6), ISO-2022-JP,
-ISO-2022-JP-2 and ISO-2022-INT-1 are supported on Mule. Either of
-charset ISO-2022-JP-2 or ISO-2022-INT-1 is used for multilingual
-text."
- (let* ((charset (car method))
- (encoding (cdr method))
- (coding-system
- (cdr (assoc (and (stringp charset) (upcase charset))
- '(("ISO-8859-1" . *ctext*)
- ("ISO-8859-2" . *iso-8859-2*)
- ("ISO-8859-3" . *iso-8859-3*)
- ("ISO-8859-4" . *iso-8859-4*)
- ("ISO-8859-5" . *iso-8859-5*)
- ;;("ISO-8859-6" . *iso-8859-6*)
- ("ISO-8859-7" . *iso-8859-7*)
- ("ISO-8859-8" . *iso-8859-8*)
- ("ISO-8859-9" . *iso-8859-9*)
- ("ISO-2022-JP" . *junet*)
- ("ISO-2022-JP-2" . *iso-2022-ss2-7*)
- ("ISO-2022-KR" . *korean-mail*)
- ("ISO-2022-INT-1" . *iso-2022-int-1*)
- )))))
- ;; In bilingual environment it may be unnecessary to convert the
- ;; coding system of the string unless transfer encoding is
- ;; required since such conversion may be performed by mule
- ;; automatically.
- (if (not (null coding-system))
- (setq string (code-convert-string string *internal* coding-system)))
- (if (stringp encoding)
- (setq string (mime-encode-string encoding string)))
- string
- ))
-
-\f