- (cond
- ((eq encoding 'quoted-printable)
- (quoted-printable-decode-region (point-min) (point-max)))
- ((eq encoding 'base64)
- (prog1
- (condition-case ()
- (base64-decode-region (point-min) (point-max))
- (error nil))
- (when (equal type "text/plain")
- (goto-char (point-min))
- (while (search-forward "\r\n" nil t)
- (replace-match "\n" t t)))))
- ((memq encoding '(7bit 8bit binary))
- )
- ((null encoding)
- )
- ((eq encoding 'x-uuencode)
- (condition-case ()
- (uudecode-decode-region (point-min) (point-max))
- (error nil)))
- ((eq encoding 'x-binhex)
- (condition-case ()
- (binhex-decode-region (point-min) (point-max))
- (error nil)))
- ((functionp encoding)
- (condition-case ()
- (funcall encoding (point-min) (point-max))
- (error nil)))
- (t
- (message "Unknown encoding %s; defaulting to 8bit" encoding))))
+ (prog1
+ (condition-case error
+ (cond
+ ((eq encoding 'quoted-printable)
+ (quoted-printable-decode-region (point-min) (point-max)))
+ ((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))
+ (if (re-search-forward "^[\t ]*$" nil t)
+ (delete-region (point) (point-max))
+ (goto-char (point-max)))
+ (skip-chars-backward "\n\t ")
+ (delete-region (point) (point-max))
+ (point))))
+ ((memq encoding '(7bit 8bit binary))
+ ;; Do nothing.
+ )
+ ((null encoding)
+ ;; Do nothing.
+ )
+ ((memq encoding '(x-uuencode x-uue))
+ (funcall mm-uu-decode-function (point-min) (point-max)))
+ ((eq encoding 'x-binhex)
+ (funcall mm-uu-binhex-decode-function (point-min) (point-max)))
+ ((functionp encoding)
+ (funcall encoding (point-min) (point-max)))
+ (t
+ (message "Unknown encoding %s; defaulting to 8bit" encoding)))
+ (error
+ (message "Error while decoding: %s" error)
+ nil))
+ (when (and
+ (memq encoding '(base64 x-uuencode x-uue x-binhex))
+ (equal type "text/plain"))
+ (goto-char (point-min))
+ (while (search-forward "\r\n" nil t)
+ (replace-match "\n" t t)))))