(mm-insert-part): Switch the multibyteness of data which will be inserted
[gnus] / lisp / rfc2047.el
index 3b4cfda..081ba9b 100644 (file)
@@ -1,5 +1,7 @@
 ;;; rfc2047.el --- functions for encoding and decoding rfc2047 messages
 ;;; rfc2047.el --- functions for encoding and decoding rfc2047 messages
-;; Copyright (C) 1998, 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
+
+;; Copyright (C) 1998, 1999, 2000, 2002, 2003, 2004
+;;        Free Software Foundation, Inc.
 
 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 ;;     MORIOKA Tomohiko <morioka@jaist.ac.jp>
 
 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
 ;;     MORIOKA Tomohiko <morioka@jaist.ac.jp>
@@ -42,7 +44,7 @@
   '(("Newsgroups" . nil)
     ("Followup-To" . nil)
     ("Message-ID" . nil)
   '(("Newsgroups" . nil)
     ("Followup-To" . nil)
     ("Message-ID" . nil)
-    ("\\(Resent-\\)?\\(From\\|Cc\\|To\\|Bcc\\|Reply-To\\|Sender\
+    ("\\(Resent-\\)?\\(From\\|Cc\\|To\\|Bcc\\|\\(In-\\)?Reply-To\\|Sender\
 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\)" . address-mime)
     (t . mime))
   "*Header/encoding method alist.
 \\|Mail-Followup-To\\|Mail-Copies-To\\|Approved\\)" . address-mime)
     (t . mime))
   "*Header/encoding method alist.
@@ -87,12 +89,15 @@ The values can be:
 Valid encodings are nil, `Q' and `B'.  These indicate binary (no) encoding,
 quoted-printable and base64 respectively.")
 
 Valid encodings are nil, `Q' and `B'.  These indicate binary (no) encoding,
 quoted-printable and base64 respectively.")
 
-(defvar rfc2047-encoding-function-alist
-  '((Q . rfc2047-q-encode-region)
-    (B . rfc2047-b-encode-region)
-    (nil . ignore))
+(defvar rfc2047-encode-function-alist
+  '((Q . rfc2047-q-encode-string)
+    (B . rfc2047-b-encode-string)
+    (nil . identity))
   "Alist of RFC2047 encodings to encoding functions.")
 
   "Alist of RFC2047 encodings to encoding functions.")
 
+(defvar rfc2047-encode-encoded-words t
+  "Whether encoded words should be encoded again.")
+
 ;;;
 ;;; Functions for encoding RFC2047 messages
 ;;;
 ;;;
 ;;; Functions for encoding RFC2047 messages
 ;;;
@@ -134,7 +139,7 @@ This is either `base64' or `quoted-printable'."
     (save-restriction
       (rfc2047-narrow-to-field)
       (re-search-forward ":[ \t\n]*" nil t)
     (save-restriction
       (rfc2047-narrow-to-field)
       (re-search-forward ":[ \t\n]*" nil t)
-      (buffer-substring (point) (point-max)))))
+      (buffer-substring-no-properties (point) (point-max)))))
 
 (defvar rfc2047-encoding-type 'address-mime
   "The type of encoding done by `rfc2047-encode-region'.
 
 (defvar rfc2047-encoding-type 'address-mime
   "The type of encoding done by `rfc2047-encode-region'.
@@ -154,24 +159,25 @@ Should be called narrowed to the head of the message."
          (rfc2047-narrow-to-field)
          (if (not (rfc2047-encodable-p))
              (prog1
          (rfc2047-narrow-to-field)
          (if (not (rfc2047-encodable-p))
              (prog1
-               (if (and (eq (mm-body-7-or-8) '8bit)
-                        (mm-multibyte-p)
-                        (mm-coding-system-p
-                         (car message-posting-charset)))
-                   ;; 8 bit must be decoded.
-                   (mm-encode-coding-region
-                    (point-min) (point-max)
-                    (mm-charset-to-coding-system
-                     (car message-posting-charset))))
+                 (if (and (eq (mm-body-7-or-8) '8bit)
+                          (mm-multibyte-p)
+                          (mm-coding-system-p
+                           (car message-posting-charset)))
+                     ;; 8 bit must be decoded.
+                     (mm-encode-coding-region
+                      (point-min) (point-max)
+                      (mm-charset-to-coding-system
+                       (car message-posting-charset))))
                ;; No encoding necessary, but folding is nice
                ;; No encoding necessary, but folding is nice
-               (rfc2047-fold-region
-                (save-excursion
-                  (goto-char (point-min))
-                  (skip-chars-forward "^:")
-                  (when (looking-at ": ")
-                    (forward-char 2))
-                  (point))
-                (point-max)))
+               (when nil
+                 (rfc2047-fold-region
+                  (save-excursion
+                    (goto-char (point-min))
+                    (skip-chars-forward "^:")
+                    (when (looking-at ": ")
+                      (forward-char 2))
+                    (point))
+                  (point-max))))
            ;; We found something that may perhaps be encoded.
            (setq method nil
                  alist rfc2047-header-encoding-alist)
            ;; We found something that may perhaps be encoded.
            (setq method nil
                  alist rfc2047-header-encoding-alist)
@@ -181,7 +187,6 @@ Should be called narrowed to the head of the message."
                        (eq (car elem) t))
                (setq alist nil
                      method (cdr elem))))
                        (eq (car elem) t))
                (setq alist nil
                      method (cdr elem))))
-           (goto-char (point-min))
            (re-search-forward "^[^:]+: *" nil t)
            (cond
             ((eq method 'address-mime)