;;; Code:
(eval-and-compile
- (if (not (fboundp 'base64-encode-string))
- (require 'base64)))
+ (or (fboundp 'base64-decode-region)
+ (autoload 'base64-decode-region "base64" nil t)))
(require 'mm-util)
+(require 'rfc2047)
(require 'qp)
(defun mm-encode-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 (or t
;; We always decode.
(while (not (eobp))
(if (eq (char-charset (following-char)) 'ascii)
(when start
- (mm-encode-coding-region start (point) mime-charset)
+ (save-restriction
+ (narrow-to-region start (point))
+ (mm-encode-coding-region start (point) mime-charset)
+ (goto-char (point-max)))
(setq start nil))
(unless start
(setq start (point))))
;;; 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)
- (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))))
+ (mm-decode-content-transfer-encoding encoding))
(when (featurep 'mule)
(let (mule-charset)
(when (and charset
(setq mule-charset (mm-charset-to-coding-system charset))
buffer-file-coding-system
- ;;(not (mm-coding-system-equal
- ;; buffer-file-coding-system mule-charset))
- )
+ (or (not (eq mule-charset 'ascii))
+ (setq mule-charset rfc2047-default-charset)))
(mm-decode-coding-region (point-min) (point-max) mule-charset))))))
(provide 'mm-bodies)