+(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)
+ (device-type . ignore)
+ (coding-system-equal . equal)
+ (annotationp . ignore)
+ (set-buffer-file-coding-system . ignore)
+ (make-char
+ . (lambda (charset int)
+ (int-to-char int)))
+ (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) ;; stolen (and renamed) from nnheader.el
+ "Replace characters in STRING from FROM to TO."
+ (let ((string (substring string 0)) ;Copy 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)))
+ (string-as-unibyte . identity)
+ (string-as-multibyte . identity)
+ (multibyte-string-p . ignore))))
+
+(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))))
+
+(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 (sym)
+ "Return non-nil if SYM is a coding system."
+ (or (and (fboundp 'coding-system-p) (coding-system-p sym))
+ (memq sym (mm-get-coding-system-list))))
+
+(defvar mm-charset-synonym-alist
+ `(
+ ;; Perfectly fine? A valid MIME name, anyhow.
+ ,@(unless (mm-coding-system-p 'big5)
+ '((big5 . cn-big5)))
+ ;; Not in XEmacs, but it's not a proper MIME charset anyhow.
+ ,@(unless (mm-coding-system-p 'x-ctext)
+ '((x-ctext . ctext)))
+ ;; Apparently not defined in Emacs 20, but is a valid MIME name.
+ ,@(unless (mm-coding-system-p 'gb2312)
+ '((gb2312 . cn-gb-2312)))
+ ;; ISO-8859-15 is very similar to ISO-8859-1.
+ ,@(unless (mm-coding-system-p 'iso-8859-15) ; Emacs 21 defines it.
+ '((iso-8859-15 . iso-8859-1)))
+ ;; 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 mapping from invalid charset names to the real charset names.")
+
+(defvar mm-binary-coding-system
+ (cond
+ ((mm-coding-system-p 'binary) 'binary)
+ ((mm-coding-system-p 'no-conversion) 'no-conversion)
+ (t nil))
+ "100% binary coding system.")
+
+(defvar mm-text-coding-system
+ (or (if (memq system-type '(windows-nt ms-dos ms-windows))
+ (and (mm-coding-system-p 'raw-text-dos) 'raw-text-dos)
+ (and (mm-coding-system-p 'raw-text) 'raw-text))
+ mm-binary-coding-system)
+ "Text-safe coding system (For removing ^M).")
+
+(defvar mm-text-coding-system-for-write nil
+ "Text coding system for write.")
+
+(defvar mm-auto-save-coding-system
+ (cond
+ ((mm-coding-system-p 'emacs-mule)
+ (if (memq system-type '(windows-nt ms-dos ms-windows))
+ (if (mm-coding-system-p 'emacs-mule-dos)
+ 'emacs-mule-dos mm-binary-coding-system)
+ 'emacs-mule))
+ ((mm-coding-system-p 'escape-quoted) 'escape-quoted)
+ (t mm-binary-coding-system))
+ "Coding system of auto save file.")
+
+(defvar mm-universal-coding-system mm-auto-save-coding-system
+ "The universal coding system.")
+
+;; Fixme: some of the cars here aren't valid MIME charsets. That
+;; should only matter with XEmacs, though.