-(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))
+(defun mm-decode-content-transfer-encoding (encoding &optional type)
+ "Decodes buffer encoded with ENCODING, returning success status.
+If TYPE is `text/plain' CRLF->LF translation may occur."
+ (prog1
+ (condition-case error
+ (cond
+ ((eq encoding 'quoted-printable)
+ (quoted-printable-decode-region (point-min) (point-max))
+ t)
+ ((eq encoding 'base64)
+ (base64-decode-region
+ (point-min)
+ ;; Some mailers insert whitespace
+ ;; junk at the end which
+ ;; base64-decode-region dislikes.
+ ;; Also remove possible junk which could
+ ;; have been added by mailing list software.
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward "^[\t ]*\r?\n" nil t)
+ (delete-region (match-beginning 0) (match-end 0)))
+ (goto-char (point-max))
+ (when (re-search-backward "^[A-Za-z0-9+/]+=*[\t ]*$" nil t)
+ (forward-line))
+ (point))))
+ ((memq encoding '(nil 7bit 8bit binary))
+ ;; Do nothing.
+ t)
+ ((memq encoding '(x-uuencode x-uue))
+ (require 'mm-uu)
+ (funcall mm-uu-decode-function (point-min) (point-max))
+ t)
+ ((eq encoding 'x-binhex)
+ (require 'mm-uu)
+ (funcall mm-uu-binhex-decode-function (point-min) (point-max))
+ t)
+ ((eq encoding 'x-yenc)
+ (require 'mm-uu)
+ (funcall mm-uu-yenc-decode-function (point-min) (point-max))
+ )
+ ((functionp encoding)
+ (funcall encoding (point-min) (point-max))
+ t)
+ (t
+ (message "Unknown encoding %s; defaulting to 8bit" encoding)))
+ (error
+ (message "Error while decoding: %s" error)
+ nil))
+ (when (and
+ type
+ (memq encoding '(base64 x-uuencode x-uue x-binhex x-yenc))
+ (string-match "\\`text/" type))
+ (goto-char (point-min))
+ (while (search-forward "\r\n" nil t)
+ (replace-match "\n" t t)))))
+
+(defun mm-decode-body (charset &optional encoding type)
+ "Decode the current article that has been encoded with ENCODING to CHARSET.
+ENCODING is a MIME content transfer encoding.
+CHARSET is the MIME charset with which to decode the data after transfer
+decoding. If it is nil, default to `mail-parse-charset'."
+ (when (stringp charset)
+ (setq charset (intern (downcase charset))))
+ (when (or (not charset)
+ (eq 'gnus-all mail-parse-ignored-charsets)
+ (memq 'gnus-all mail-parse-ignored-charsets)
+ (memq charset mail-parse-ignored-charsets))
+ (setq charset mail-parse-charset))