Importing Oort Gnus v0.03.
[elisp/gnus.git-] / lisp / mm-encode.el
index 7d8763b..677c2df 100644 (file)
@@ -1,5 +1,5 @@
 ;;; mm-encode.el --- Functions for encoding MIME things 
-;; Copyright (C) 1998,99 Free Software Foundation, Inc.
+;; Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
 
 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 ;;     MORIOKA Tomohiko <morioka@jaist.ac.jp>
 
 ;;; Code:
 
+(eval-when-compile (require 'cl))
 (require 'mail-parse)
 (require 'mailcap)
+(eval-and-compile
+  (autoload 'mm-body-7-or-8 "mm-bodies"))
 
 (defvar mm-content-transfer-encoding-defaults
   '(("text/x-patch" 8bit)
@@ -62,8 +65,7 @@ This variable should never be set directly, but bound before a call to
   "Insert multipart/mixed headers."
   (let ((boundary "=-=-="))
     (insert "MIME-Version: 1.0\n")
-    (insert (format "Content-Type: multipart/mixed; boundary=\"%s\"\n"
-                   boundary))
+    (insert "Content-Type: multipart/mixed; boundary=\"" boundary "\"\n")
     boundary))
 
 (defun mm-default-file-encoding (file)
@@ -83,7 +85,8 @@ This variable should never be set directly, but bound before a call to
 (defun mm-encode-content-transfer-encoding (encoding &optional type)
   (cond
    ((eq encoding 'quoted-printable)
-    (quoted-printable-encode-region (point-min) (point-max) t))
+    (mm-with-unibyte-current-buffer-mule4
+      (quoted-printable-encode-region (point-min) (point-max) t)))
    ((eq encoding 'base64)
     (when (equal type "text/plain")
       (goto-char (point-min))
@@ -142,9 +145,9 @@ The encoding used is returned."
        (when (string-match (caar rules) type)
          (throw 'found
                 (let ((encoding 
-                       (if (eq (cadar rules) 'qp-or-base64)
+                       (if (eq (cadr (car rules)) 'qp-or-base64)
                            (mm-qp-or-base64)
-                         (cadar rules))))
+                         (cadr (car rules)))))
                   (if mm-use-ultra-safe-encoding
                       (mm-safer-encoding encoding)
                     encoding))))
@@ -160,7 +163,10 @@ The encoding used is returned."
        (incf n8bit)
        (forward-char 1)
        (skip-chars-forward "\x20-\x7f\r\n\t" limit))
-      (if (< (* 6 n8bit) (- limit (point-min)))
+      (if (or (< (* 6 n8bit) (- limit (point-min)))
+             ;; Don't base64, say, a short line with a single
+             ;; non-ASCII char when splitting parts by charset.
+             (= n8bit 1))
          'quoted-printable
        'base64))))