From e59fb960ee3bacf937cab11b1b23e6c7389de3ed Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Fri, 4 May 2012 18:26:36 +0800 Subject: [PATCH] Backport fix for Bug#11282 from trunk --- lisp/ChangeLog | 6 ++++++ lisp/mail/rmailmm.el | 48 ++++++++++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index dbbb2fb4c76..ff08f0681aa 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -3,6 +3,12 @@ * select.el (xselect--encode-string): Always use utf-8 for TEXT on Nextstep. +2012-05-03 Kenichi Handa + + * mail/rmailmm.el (rmail-show-mime): Catch an error caused by text + decoding, and show a warning message without signalling an error + (Bug#11282). + 2012-04-30 Eli Zaretskii * mail/rmail.el (rmail-yank-current-message): Use the encoding of diff --git a/lisp/mail/rmailmm.el b/lisp/mail/rmailmm.el index 9adc5eb9a06..67b2e62275f 100644 --- a/lisp/mail/rmailmm.el +++ b/lisp/mail/rmailmm.el @@ -1300,26 +1300,40 @@ The arguments ARG and STATE have no effect in this case." (rmail-mime-mbox-buffer rmail-buffer) (rmail-mime-view-buffer rmail-view-buffer) (rmail-mime-coding-system nil)) + ;; If ENTITY is not a vector, it is a string describing an error. (if (vectorp entity) (with-current-buffer rmail-mime-view-buffer (erase-buffer) - (rmail-mime-insert entity) - (if (consp rmail-mime-coding-system) - ;; Decoding is done by rfc2047-decode-region only for a - ;; header. But, as the used coding system may have been - ;; overridden by mm-charset-override-alist, we can't - ;; trust (car rmail-mime-coding-system). So, here we - ;; try the decoding again with mm-charset-override-alist - ;; bound to nil. - (let ((mm-charset-override-alist nil)) - (setq rmail-mime-coding-system - (rmail-mime-find-header-encoding - (rmail-mime-entity-header entity))))) - (set-buffer-file-coding-system - (if rmail-mime-coding-system - (coding-system-base rmail-mime-coding-system) - 'undecided) - t t)) + ;; This condition-case is for catching an error in the + ;; internal MIME decoding (e.g. incorrect BASE64 form) that + ;; may be signaled by rmail-mime-insert. + ;; FIXME: The current code doesn't set a proper error symbol + ;; in ERR. We must find a way to propagate a correct error + ;; symbol that is caused in the very deep code of text + ;; decoding (e.g. an error by base64-decode-region called by + ;; post-read-conversion function of utf-7). + (condition-case err + (progn + (rmail-mime-insert entity) + (if (consp rmail-mime-coding-system) + ;; Decoding is done by rfc2047-decode-region only for a + ;; header. But, as the used coding system may have been + ;; overridden by mm-charset-override-alist, we can't + ;; trust (car rmail-mime-coding-system). So, here we + ;; try the decoding again with mm-charset-override-alist + ;; bound to nil. + (let ((mm-charset-override-alist nil)) + (setq rmail-mime-coding-system + (rmail-mime-find-header-encoding + (rmail-mime-entity-header entity))))) + (set-buffer-file-coding-system + (if rmail-mime-coding-system + (coding-system-base rmail-mime-coding-system) + 'undecided) + t t)) + (error (setq entity (format "%s" err)))))) + ;; Re-check ENTITY. It may be set to an error string. + (when (stringp entity) ;; Decoding failed. ENTITY is an error message. Insert the ;; original message body as is, and show warning. (let ((region (with-current-buffer rmail-mime-mbox-buffer -- 2.39.2