From 8c40edc34e405b333f9ee2f6a118c2003995eb29 Mon Sep 17 00:00:00 2001 From: yamaoka Date: Sat, 15 Mar 2003 00:27:45 +0000 Subject: [PATCH] Synch to Oort Gnus 200303142234. --- 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 a1c51ed..6f6a52f 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 e672e33..ec33d6d 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 8fd737f..9bb8c0f 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) -- 1.7.10.4