+(require 'mail-prsvr)
+
+(eval-and-compile
+ (mapcar
+ (lambda (elem)
+ (let ((nfunc (intern (format "mm-%s" (car elem)))))
+ (if (fboundp (car elem))
+ (defalias nfunc (car elem))
+ (defalias nfunc (cdr elem)))))
+ '((decode-coding-string . (lambda (s a) s))
+ (encode-coding-string . (lambda (s a) s))
+ (encode-coding-region . ignore)
+ (coding-system-list . ignore)
+ (decode-coding-region . ignore)
+ (char-int . identity)
+ (coding-system-equal . equal)
+ (annotationp . ignore)
+ (set-buffer-file-coding-system . ignore)
+ (read-charset
+ . (lambda (prompt)
+ "Return a charset."
+ (intern
+ (completing-read
+ prompt
+ (mapcar (lambda (e) (list (symbol-name (car e))))
+ mm-mime-mule-charset-alist)
+ nil t))))
+ (subst-char-in-string
+ . (lambda (from to string &optional inplace) ;; stolen (and renamed) from nnheader.el
+ "Replace characters in STRING from FROM to TO.
+ Unless optional argument INPLACE is non-nil, return a new string."
+ (let ((string (if inplace string (copy-sequence string)))
+ (len (length string))
+ (idx 0))
+ ;; Replace all occurrences of FROM with TO.
+ (while (< idx len)
+ (when (= (aref string idx) from)
+ (aset string idx to))
+ (setq idx (1+ idx)))
+ string)))
+ (replace-in-string
+ . (lambda (string regexp rep &optional literal)
+ "See `replace-regexp-in-string', only the order of args differs."
+ (replace-regexp-in-string regexp rep string nil literal)))
+ (string-as-unibyte . identity)
+ (string-make-unibyte . identity)
+ (string-as-multibyte . identity)
+ (multibyte-string-p . ignore)
+ ;; It is not a MIME function, but some MIME functions use it.
+ (make-temp-file . (lambda (prefix &optional dir-flag)
+ (let ((file (expand-file-name
+ (make-temp-name prefix)
+ (if (fboundp 'temp-directory)
+ (temp-directory)
+ temporary-file-directory))))
+ (if dir-flag
+ (make-directory file))
+ file)))
+ (insert-byte . insert-char)
+ (multibyte-char-to-unibyte . identity))))
+
+(eval-and-compile
+ (defalias 'mm-char-or-char-int-p
+ (cond
+ ((fboundp 'char-or-char-int-p) 'char-or-char-int-p)
+ ((fboundp 'char-valid-p) 'char-valid-p)
+ (t 'identity))))
+
+;; Fixme: This seems always to be used to read a MIME charset, so it
+;; should be re-named and fixed (in Emacs) to offer completion only on
+;; proper charset names (base coding systems which have a
+;; mime-charset defined). XEmacs doesn't believe in mime-charset;
+;; test with
+;; `(or (coding-system-get 'iso-8859-1 'mime-charset)
+;; (coding-system-get 'iso-8859-1 :mime-charset))'
+;; Actually, there should be an `mm-coding-system-mime-charset'.
+(eval-and-compile
+ (defalias 'mm-read-coding-system
+ (cond
+ ((fboundp 'read-coding-system)
+ (if (and (featurep 'xemacs)
+ (<= (string-to-number emacs-version) 21.1))
+ (lambda (prompt &optional default-coding-system)
+ (read-coding-system prompt))
+ 'read-coding-system))
+ (t (lambda (prompt &optional default-coding-system)
+ "Prompt the user for a coding system."
+ (completing-read
+ prompt (mapcar (lambda (s) (list (symbol-name (car s))))
+ mm-mime-mule-charset-alist)))))))
+
+(defvar mm-coding-system-list nil)
+(defun mm-get-coding-system-list ()
+ "Get the coding system list."
+ (or mm-coding-system-list
+ (setq mm-coding-system-list (mm-coding-system-list))))
+
+(defun mm-coding-system-p (cs)
+ "Return non-nil if CS is a symbol naming a coding system.
+In XEmacs, also return non-nil if CS is a coding system object.
+If CS is available, return CS itself in Emacs, and return a coding
+system object in XEmacs."
+ (if (fboundp 'find-coding-system)
+ (find-coding-system cs)
+ (if (fboundp 'coding-system-p)
+ (when (coding-system-p cs)
+ cs)
+ ;; Is this branch ever actually useful?
+ (car (memq cs (mm-get-coding-system-list))))))
+
+(defvar mm-charset-synonym-alist
+ `(
+ ;; Not in XEmacs, but it's not a proper MIME charset anyhow.
+ ,@(unless (mm-coding-system-p 'x-ctext)
+ '((x-ctext . ctext)))
+ ;; ISO-8859-15 is very similar to ISO-8859-1. But it's _different_!
+ ,@(unless (mm-coding-system-p 'iso-8859-15)
+ '((iso-8859-15 . iso-8859-1)))
+ ;; BIG-5HKSCS is similar to, but different than, BIG-5.
+ ,@(unless (mm-coding-system-p 'big5-hkscs)
+ '((big5-hkscs . big5)))
+ ;; Windows-1252 is actually a superset of Latin-1. See also
+ ;; `gnus-article-dumbquotes-map'.
+ ,@(unless (mm-coding-system-p 'windows-1252)
+ (if (mm-coding-system-p 'cp1252)
+ '((windows-1252 . cp1252))
+ '((windows-1252 . iso-8859-1))))
+ ;; Windows-1250 is a variant of Latin-2 heavily used by Microsoft
+ ;; Outlook users in Czech republic. Use this to allow reading of their
+ ;; e-mails. cp1250 should be defined by M-x codepage-setup.
+ ,@(if (and (not (mm-coding-system-p 'windows-1250))
+ (mm-coding-system-p 'cp1250))
+ '((windows-1250 . cp1250)))
+ ;; A Microsoft misunderstanding.
+ ,@(unless (mm-coding-system-p 'ks_c_5601-1987)
+ (if (mm-coding-system-p 'cp949)
+ '((ks_c_5601-1987 . cp949))
+ '((ks_c_5601-1987 . euc-kr))))
+ )
+ "A mapping from invalid charset names to the real charset names.")