From 5326bd1777979c3e80999d6e02360f05b4b099c1 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sun, 14 Jul 2024 11:41:30 +0300 Subject: [PATCH] Minor improvement in 'rmail-redecode-body' * lisp/mail/rmail.el (rmail-redecode-body): Signal user-error if 'rmail-enable-mime' is non-nil; doc fix. (cherry picked from commit 159f3f59b1d6ca57cff6f0628458908b62639e30) --- lisp/mail/rmail.el | 93 ++++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el index 5e3633d221c..e38ab12fae6 100644 --- a/lisp/mail/rmail.el +++ b/lisp/mail/rmail.el @@ -2955,51 +2955,56 @@ charset= headers. This function assumes that the current message is already decoded and displayed in the RMAIL buffer, but the coding system used to decode it was incorrect. It then decodes the message again, -using the coding system CODING." +using the coding system CODING. + +This function does nothing (except reporting a user-error) +if `rmail-enable-mime' is non-nil." (interactive "zCoding system for re-decoding this message: ") - (when (not rmail-enable-mime) - (with-current-buffer rmail-buffer - (rmail-swap-buffers-maybe) - (save-restriction - (widen) - (let ((msgbeg (rmail-msgbeg rmail-current-message)) - (msgend (rmail-msgend rmail-current-message)) - (buffer-read-only nil) - body-start x-coding-header old-coding) - (narrow-to-region msgbeg msgend) - (goto-char (point-min)) - (unless (setq body-start (search-forward "\n\n" (point-max) 1)) - (error "No message body")) - - (save-restriction - ;; Narrow to headers - (narrow-to-region (point-min) body-start) - (setq x-coding-header (goto-char (point-min))) - (if (not (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t)) - (setq old-coding (rmail-get-coding-system)) - (setq old-coding (intern (match-string 1))) - (setq x-coding-header (point))) - (check-coding-system old-coding) - ;; Make sure the new coding system uses the same EOL - ;; conversion, to prevent ^M characters from popping up - ;; all over the place. - (let ((eol-type (coding-system-eol-type old-coding))) - (if (numberp eol-type) - (setq coding - (coding-system-change-eol-conversion coding eol-type)))) - (when (not (coding-system-equal - (coding-system-base old-coding) - (coding-system-base coding))) - ;; Rewrite the coding-system header. - (goto-char x-coding-header) - (if (> (point) (point-min)) - (delete-region (line-beginning-position) (point)) - (forward-line) - (insert "\n") - (forward-line -1)) - (insert "X-Coding-System: " - (symbol-name coding)))) - (rmail-show-message)))))) + (if (not rmail-enable-mime) + (with-current-buffer rmail-buffer + (rmail-swap-buffers-maybe) + (save-restriction + (widen) + (let ((msgbeg (rmail-msgbeg rmail-current-message)) + (msgend (rmail-msgend rmail-current-message)) + (buffer-read-only nil) + body-start x-coding-header old-coding) + (narrow-to-region msgbeg msgend) + (goto-char (point-min)) + (unless (setq body-start (search-forward "\n\n" (point-max) 1)) + (error "No message body")) + + (save-restriction + ;; Narrow to headers + (narrow-to-region (point-min) body-start) + (setq x-coding-header (goto-char (point-min))) + (if (not (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t)) + (setq old-coding (rmail-get-coding-system)) + (setq old-coding (intern (match-string 1))) + (setq x-coding-header (point))) + (check-coding-system old-coding) + ;; Make sure the new coding system uses the same EOL + ;; conversion, to prevent ^M characters from popping up + ;; all over the place. + (let ((eol-type (coding-system-eol-type old-coding))) + (if (numberp eol-type) + (setq coding + (coding-system-change-eol-conversion coding eol-type)))) + (when (not (coding-system-equal + (coding-system-base old-coding) + (coding-system-base coding))) + ;; Rewrite the coding-system header. + (goto-char x-coding-header) + (if (> (point) (point-min)) + (delete-region (line-beginning-position) (point)) + (forward-line) + (insert "\n") + (forward-line -1)) + (insert "X-Coding-System: " + (symbol-name coding)))) + (rmail-show-message)))) + (user-error + (substitute-quotes "`rmail-enable-mime' is non-nil; disable it first")))) (defun rmail-highlight-headers () "Highlight the headers specified by `rmail-highlighted-headers'. -- 2.39.5