- (or (not (eq mule-charset 'ascii))
- (setq mule-charset mail-parse-charset)))
- (mm-decode-coding-region (point-min) (point-max) mule-charset))))))
+ (or (not (eq coding-system 'ascii))
+ (setq coding-system mail-parse-charset))
+ (not (eq coding-system 'gnus-decoded)))
+ (if force
+ (mm-decode-coding-region (point-min) (point-max)
+ coding-system)
+ (mm-decode-coding-region-safely (point-min) (point-max)
+ coding-system)))))))
+
+(defun mm-decode-coding-region-safely (start end coding-system)
+ "Decode region between START and END with CODING-SYSTEM.
+If CODING-SYSTEM is not a valid coding system for the text, let Emacs
+decide which coding system to use."
+ (let* ((orig (buffer-substring start end))
+ charsets)
+ (save-restriction
+ (narrow-to-region start end)
+ (mm-decode-coding-region (point-min) (point-max) coding-system)
+ (setq charsets (find-charset-region (point-min) (point-max)))
+ (when (or (memq 'eight-bit-control charsets)
+ (memq 'eight-bit-graphic charsets))
+ (delete-region (point-min) (point-max))
+ (insert orig)
+ (mm-decode-coding-region (point-min) (point-max) 'undecided)))))