- (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 t)
- ;; 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))
- (rfc2047-fold-region (point-min) (point-max)))
- ;; Hm.
- (t))))
- (goto-char (point-max)))))
- (when mail-parse-charset
- (encode-coding-region (point-min) (point-max)
- mail-parse-charset)))))
-
-(defun rfc2047-encodable-p (&optional header)
- "Say whether the current (narrowed) buffer contains characters that need encoding.
-
-A non-nil value should be passed for the optional parameter HEADER if
-the region is part of a message header. In this case, the only
-permitted unencoded charset is us-ascii."
+ (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)))
+ ;; No encoding necessary, but folding is nice
+ (rfc2047-fold-region (save-excursion
+ (goto-char (point-min))
+ (skip-chars-forward "^:")
+ (and (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)))
+ ((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))
+
+(defun rfc2047-encodable-p ()
+ "Return non-nil if any characters in current buffer need encoding in headers.
+The buffer may be narrowed."
+ (require 'message) ; for message-posting-charset