;;; Code:
+(eval-and-compile
+ (if (not (fboundp 'base64-encode-string))
+ (require 'base64)))
(require 'mm-util)
+(require 'rfc2047)
+(require 'qp)
(defun mm-encode-body ()
"Encode a body.
charsets)
;; We encode.
(t
- (let ((mime-charset (mm-mule-charset-to-mime-charset (car charsets)))
+ (let ((mime-charset
+ (mm-mime-charset (car charsets) (point-min) (point-max)))
start)
- (when (not (mm-coding-system-equal
- mime-charset buffer-file-coding-system))
+ (when (or t
+ ;; We always decode.
+ (not (mm-coding-system-equal
+ mime-charset buffer-file-coding-system)))
(while (not (eobp))
(if (eq (char-charset (following-char)) 'ascii)
(when start
(defun mm-body-encoding ()
"Return the encoding of the current buffer."
- (if (null (delq 'ascii (find-charset-region (point-min) (point-max))))
+ (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))
;;; Functions for decoding
;;;
+(defun mm-decode-content-transfer-encoding (encoding)
+ (cond
+ ((eq encoding 'quoted-printable)
+ (quoted-printable-decode-region (point-min) (point-max)))
+ ((eq encoding 'base64)
+ (condition-case ()
+ (base64-decode-region (point-min) (point-max))
+ (error nil)))
+ ((memq encoding '(7bit 8bit binary))
+ )
+ ((null encoding)
+ )
+ (t
+ (error "Can't decode encoding %s" encoding))))
+
(defun mm-decode-body (charset encoding)
"Decode the current article that has been encoded with ENCODING.
The characters in CHARSET should then be decoded."
+ (setq charset (or charset rfc2047-default-charset))
(save-excursion
(when encoding
- (cond
- ((eq encoding 'quoted-printable)
- (quoted-printable-decode-region (point-min) (point-max)))
- ((eq encoding 'base64)
- (base64-decode-region (point-min) (point-max)))
- ((memq encoding '(7bit 8bit binary))
- )
- (t
- (error "Can't decode encoding %s" encoding))))
+ (mm-decode-content-transfer-encoding encoding))
(when (featurep 'mule)
(let (mule-charset)
(when (and charset
(setq mule-charset (mm-charset-to-coding-system charset))
- (not (mm-coding-system-equal
- buffer-file-coding-system mule-charset)))
+ buffer-file-coding-system
+ ;;(not (mm-coding-system-equal
+ ;; buffer-file-coding-system mule-charset))
+ )
(mm-decode-coding-region (point-min) (point-max) mule-charset))))))
(provide 'mm-bodies)