+ (save-excursion
+ (goto-char (point-min))
+ (let (alist elem method)
+ (while (not (eobp))
+ (save-restriction
+ (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.
+ ;; Is message-posting-charset a coding system?
+ (mm-encode-coding-region
+ (point-min) (point-max)
+ (car message-posting-charset))
+ nil)
+ ;; 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)))
+ ;; We found something that may perhaps be encoded.
+ (setq method nil
+ alist rfc2047-header-encoding-alist)
+ (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
+ ((stringp method)
+ (rfc2047-encode-region (point-min) (point-max) method))
+ ((eq method 'mime)
+ (rfc2047-encode-region (point-min) (point-max)))
+ ((eq method 'default)
+ (if (and (featurep 'mule)
+ (if (boundp 'default-enable-multibyte-characters)
+ default-enable-multibyte-characters)
+ mail-parse-charset)
+ (mm-encode-coding-region (point-min) (point-max)
+ mail-parse-charset)))
+ ;; We get this when CC'ing messsages to newsgroups with
+ ;; 8-bit names. The group name mail copy just get
+ ;; unconditionally encoded. Previously, it would ask
+ ;; whether to encode, which was quite confusing for the
+ ;; user. If the new behaviour is wrong, tell me. I have
+ ;; left the old code commented out below.
+ ;; -- Per Abrahamsen <abraham@dina.kvl.dk> Date: 2001-10-07.
+ ((null method)
+ (when (delq 'ascii
+ (mm-find-charset-region (point-min) (point-max)))
+ (rfc2047-encode-region (point-min) (point-max))))
+;;; ((null method)
+;;; (and (delq 'ascii
+;;; (mm-find-charset-region (point-min)
+;;; (point-max)))
+;;; (if (or (message-options-get
+;;; 'rfc2047-encode-message-header-encode-any)
+;;; (message-options-set
+;;; 'rfc2047-encode-message-header-encode-any
+;;; (y-or-n-p
+;;; "Some texts are not encoded. Encode anyway?")))
+;;; (rfc2047-encode-region (point-min) (point-max))
+;;; (error "Cannot send unencoded text"))))
+ ((mm-coding-system-p method)
+ (if (and (featurep 'mule)
+ (if (boundp 'default-enable-multibyte-characters)
+ default-enable-multibyte-characters))
+ (mm-encode-coding-region (point-min) (point-max) method)))
+ ;; Hm.
+ (t)))
+ (goto-char (point-max)))))))
+
+;; Fixme: This, and the require below may not be the Right Thing, but
+;; should be safe just before release. -- fx 2001-02-08
+(eval-when-compile (defvar message-posting-charset))