From 23575e7700fff4cf444adfcf512978ae2077c5bb Mon Sep 17 00:00:00 2001 From: Jesper Harder Date: Fri, 14 Mar 2003 22:33:59 +0000 Subject: [PATCH] * mm-bodies.el (mm-decode-coding-region-safely): New function. (mm-decode-body): Use it. * rfc2047.el (rfc2047-decode-region): do. (rfc2047-decode-string): Guess coding system if the default is invalid. --- lisp/ChangeLog | 9 +++++++++ lisp/mm-bodies.el | 16 +++++++++++++++- lisp/rfc2047.el | 9 +++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a1c51eded..6f6a52fdb 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2003-03-14 Jesper Harder + + * mm-bodies.el (mm-decode-coding-region-safely): New function. + (mm-decode-body): Use it. + + * rfc2047.el (rfc2047-decode-region): do. + (rfc2047-decode-string): Guess coding system if the default is + invalid. + 2003-03-12 Paul Jarc * nnmaildir.el (nnmaildir-request-update-info): Pretend missing diff --git a/lisp/mm-bodies.el b/lisp/mm-bodies.el index e672e337a..ec33d6dcd 100644 --- a/lisp/mm-bodies.el +++ b/lisp/mm-bodies.el @@ -271,7 +271,21 @@ The characters in CHARSET should then be decoded." (or (not (eq coding-system 'ascii)) (setq coding-system mail-parse-charset)) (not (eq coding-system 'gnus-decoded))) - (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* ((decoded (mm-decode-coding-string (buffer-substring start end) + coding-system)) + (charsets (find-charset-string decoded))) + (if (or (memq 'eight-bit-control charsets) + (memq 'eight-bit-graphic charsets)) + (mm-decode-coding-region start end 'undecided) + (delete-region start end) + (insert decoded)))) (defun mm-decode-string (string charset) "Decode STRING with CHARSET." diff --git a/lisp/rfc2047.el b/lisp/rfc2047.el index fdce08db1..0b65fcb84 100644 --- a/lisp/rfc2047.el +++ b/lisp/rfc2047.el @@ -538,7 +538,7 @@ The buffer may be narrowed." mail-parse-charset (not (eq mail-parse-charset 'us-ascii)) (not (eq mail-parse-charset 'gnus-decoded))) - (mm-decode-coding-region b (point-max) mail-parse-charset)))))) + (mm-decode-coding-region-safely b (point-max) mail-parse-charset)))))) (defun rfc2047-decode-string (string) "Decode the quoted-printable-encoded STRING and return the results." @@ -555,7 +555,12 @@ The buffer may be narrowed." mail-parse-charset (not (eq mail-parse-charset 'us-ascii)) (not (eq mail-parse-charset 'gnus-decoded))) - (mm-decode-coding-string string mail-parse-charset) + (let* ((decoded (mm-decode-coding-string string mail-parse-charset)) + (charsets (find-charset-string decoded))) + (if (or (memq 'eight-bit-control charsets) + (memq 'eight-bit-graphic charsets)) + (mm-decode-coding-string string 'undecided) + decoded)) string)))) (defun rfc2047-parse-and-decode (word) -- 2.25.1