- (when (featurep 'mule)
- (save-excursion
- (goto-char (point-min))
- (let ((alist rfc2047-header-encoding-alist)
- elem method)
- (while (not (eobp))
- (save-restriction
- (rfc2047-narrow-to-field)
- (when (rfc2047-encodable-p)
- ;; We found something that may perhaps be encoded.
- (while (setq elem (pop alist))
- (when (or (and (stringp (car elem))
- (looking-at (car elem)))
- (eq (car elem) t))
- (setq alist nil
- method (cdr elem))))
- (when method
- (cond
- ((eq method 'mime)
- (rfc2047-encode-region (point-min) (point-max)))
- ;; Hm.
- (t))))
- (goto-char (point-max)))))
- (when rfc2047-default-charset
- (encode-coding-region (point-min) (point-max)
- rfc2047-default-charset)))))
-
-(defun rfc2047-encodable-p ()
- "Say whether the current (narrowed) buffer contains characters that need encoding."
- (let ((charsets (mapcar
- 'mm-mule-charset-to-mime-charset
- (find-charset-region (point-min) (point-max))))
- (cs (list 'us-ascii rfc2047-default-charset))
+ (save-excursion
+ (goto-char (point-min))
+ (let ((alist rfc2047-header-encoding-alist)
+ elem method)
+ (while (not (eobp))
+ (save-restriction
+ (rfc2047-narrow-to-field)
+ (if (not (rfc2047-encodable-p))
+ (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.
+ ;; Is message-posting-charset a coding system?
+ (mm-encode-coding-region
+ (point-min) (point-max)
+ (car message-posting-charset)))
+ ;; We found something that may perhaps be encoded.
+ (while (setq elem (pop alist))
+ (when (or (and (stringp (car elem))
+ (looking-at (car elem)))
+ (eq (car elem) t))
+ (setq alist nil
+ method (cdr elem))))
+ (cond
+ ((eq method 'mime)
+ (rfc2047-encode-region (point-min) (point-max))
+ (rfc2047-fold-region (point-min) (point-max)))
+ ;; Hm.
+ (t)))
+ (goto-char (point-max)))))))
+
+(defun rfc2047-encodable-p (&optional header)
+ "Say whether the current (narrowed) buffer contains characters that need encoding in headers."
+ (let ((charsets
+ (mapcar
+ 'mm-mime-charset
+ (mm-find-charset-region (point-min) (point-max))))
+ (cs (list 'us-ascii (car message-posting-charset)))