Importing Pterodactyl Gnus v0.54.
[elisp/gnus.git-] / lisp / mm-util.el
index eeff82f..51ab0f0 100644 (file)
     dest)
   "Charset/coding system alist.")
 
     dest)
   "Charset/coding system alist.")
 
+;;;Internal variable
+(defvar mm-charset-iso-8859-1-forced nil)
+
 (defun mm-mule-charset-to-mime-charset (charset)
   "Return the MIME charset corresponding to MULE CHARSET."
   (let ((alist mm-mime-mule-charset-alist)
 (defun mm-mule-charset-to-mime-charset (charset)
   "Return the MIME charset corresponding to MULE CHARSET."
   (let ((alist mm-mime-mule-charset-alist)
@@ -134,6 +137,9 @@ If optional argument LBT (`unix', `dos' or `mac') is specified, it is
 used as the line break code type of the coding system."
   (when (stringp charset)
     (setq charset (intern (downcase charset))))
 used as the line break code type of the coding system."
   (when (stringp charset)
     (setq charset (intern (downcase charset))))
+  (if (and mm-charset-iso-8859-1-forced 
+          (eq charset 'iso-8859-1))
+      (setq charset mm-charset-iso-8859-1-forced))
   (setq charset
        (or (cdr (assq charset mm-charset-coding-system-alist))
            charset))
   (setq charset
        (or (cdr (assq charset mm-charset-coding-system-alist))
            charset))
@@ -169,7 +175,7 @@ used as the line break code type of the coding system."
 (defsubst mm-enable-multibyte ()
   "Enable multibyte in the current buffer."
   (when (and (fboundp 'set-buffer-multibyte)
 (defsubst mm-enable-multibyte ()
   "Enable multibyte in the current buffer."
   (when (and (fboundp 'set-buffer-multibyte)
-            (default-value enable-multibyte-characters))
+            (default-value 'enable-multibyte-characters))
     (set-buffer-multibyte t)))
 
 (defsubst mm-disable-multibyte ()
     (set-buffer-multibyte t)))
 
 (defsubst mm-disable-multibyte ()
@@ -205,7 +211,7 @@ See also `with-temp-file' and `with-output-to-string'."
        (multibyte (make-symbol "multibyte")))
     `(if (not (boundp 'enable-multibyte-characters))
         (with-temp-buffer ,@forms)
        (multibyte (make-symbol "multibyte")))
     `(if (not (boundp 'enable-multibyte-characters))
         (with-temp-buffer ,@forms)
-       (let ((,multibyte (default-value enable-multibyte-characters))
+       (let ((,multibyte (default-value 'enable-multibyte-characters))
             ,temp-buffer)
         (unwind-protect
             (progn
             ,temp-buffer)
         (unwind-protect
             (progn
@@ -214,7 +220,7 @@ See also `with-temp-file' and `with-output-to-string'."
                     (get-buffer-create (generate-new-buffer-name " *temp*")))
               (unwind-protect
                   (with-current-buffer ,temp-buffer
                     (get-buffer-create (generate-new-buffer-name " *temp*")))
               (unwind-protect
                   (with-current-buffer ,temp-buffer
-                    (let (buffer-file-coding-system)
+                    (let ((buffer-file-coding-system 'binary))
                       ,@forms))
                 (and (buffer-name ,temp-buffer)
                      (kill-buffer ,temp-buffer))))
                       ,@forms))
                 (and (buffer-name ,temp-buffer)
                      (kill-buffer ,temp-buffer))))
@@ -224,18 +230,32 @@ See also `with-temp-file' and `with-output-to-string'."
 
 (defun mm-find-charset-region (b e)
   "Return a list of charsets in the region."
 
 (defun mm-find-charset-region (b e)
   "Return a list of charsets in the region."
-  (if enable-multibyte-characters
-      (find-charset-region b e)
+  (cond
+   ((and (boundp 'enable-multibyte-characters)
+        enable-multibyte-characters)
+    (find-charset-region b e))
+   ((not (boundp 'current-language-environment))
+    (save-excursion
+      (save-restriction
+       (narrow-to-region b e)
+       (goto-char (point-min))
+       (skip-chars-forward "\0-\177")
+       (if (eobp)
+           '(ascii)
+         ;;;!!!bogus
+         (list 'ascii 'latin-iso8859-1)))))
+   (t
     ;; We are in a unibyte buffer, so we futz around a bit.
     (save-excursion
       (save-restriction
        (narrow-to-region b e)
        (goto-char (point-min))
     ;; We are in a unibyte buffer, so we futz around a bit.
     (save-excursion
       (save-restriction
        (narrow-to-region b e)
        (goto-char (point-min))
-       (let ((entry (assoc current-language-environment language-info-alist)))
+       (let ((entry (assoc (capitalize current-language-environment)
+                           language-info-alist)))
          (skip-chars-forward "\0-\177")
          (if (eobp)
              '(ascii)
          (skip-chars-forward "\0-\177")
          (if (eobp)
              '(ascii)
-           (list 'ascii (car (last (assq 'charset entry))))))))))
+           (list 'ascii (car (last (assq 'charset entry)))))))))))
 
 (provide 'mm-util)
 
 
 (provide 'mm-util)