- (mm-encode-coding-region start (point) mime-charset)
- (setq start nil)))
- mime-charset))))))
-
-(defun mm-body-encoding ()
- "Return the encoding of the current buffer."
- (if (and
- (null (delq 'ascii (find-charset-region (point-min) (point-max))))
- ;;;!!!The following is necessary because the function
- ;;;!!!above seems to return the wrong result under Emacs 20.3.
- ;;;!!!Sometimes.
- (save-excursion
- (goto-char (point-min))
- (skip-chars-forward "\0-\177")
- (eobp)))
- '7bit
- '8bit))
+ (mm-encode-coding-region start (point)
+ (mm-charset-to-coding-system charset))
+ (setq start nil))
+ charset)))))))
+
+(defun mm-long-lines-p (length)
+ "Say whether any of the lines in the buffer is longer than LINES."
+ (save-excursion
+ (goto-char (point-min))
+ (end-of-line)
+ (while (and (not (eobp))
+ (not (> (current-column) length)))
+ (forward-line 1)
+ (end-of-line))
+ (and (> (current-column) length)
+ (current-column))))
+
+(defvar message-posting-charset)
+
+(defun mm-body-encoding (charset &optional encoding)
+ "Do Content-Transfer-Encoding and return the encoding of the current buffer."
+ (let ((bits (mm-body-7-or-8))
+ (longp (mm-long-lines-p 1000)))
+ (require 'message)
+ (cond
+ ((and (not mm-use-ultra-safe-encoding)
+ (not longp)
+ (eq bits '7bit))
+ bits)
+ ((and (not mm-use-ultra-safe-encoding)
+ (not longp)
+ (or (eq t (cdr message-posting-charset))
+ (memq charset (cdr message-posting-charset))
+ (eq charset mail-parse-charset)))
+ bits)
+ (t
+ (let ((encoding (or encoding
+ (cdr (assq charset mm-body-charset-encoding-alist))
+ (mm-qp-or-base64))))
+ (when mm-use-ultra-safe-encoding
+ (setq encoding (mm-safer-encoding encoding)))
+ (mm-encode-content-transfer-encoding encoding "text/plain")
+ encoding)))))
+
+(defun mm-body-7-or-8 ()
+ "Say whether the body is 7bit or 8bit."
+ (cond
+ ((not (featurep 'mule))
+ (if (save-excursion
+ (goto-char (point-min))
+ (skip-chars-forward mm-7bit-chars)
+ (eobp))
+ '7bit
+ '8bit))
+ (t
+ ;; Mule version
+ (if (and (null (delq 'ascii
+ (mm-find-charset-region (point-min) (point-max))))
+ ;;!!!The following is necessary because the function
+ ;;!!!above seems to return the wrong result under
+ ;;!!!Emacs 20.3. Sometimes.
+ (save-excursion
+ (goto-char (point-min))
+ (skip-chars-forward mm-7bit-chars)
+ (eobp)))
+ '7bit
+ '8bit))))