# HG changeset patch # User Eli Zaretskii # Date 980183627 0 # Node ID a06f22cd075b7dcfcc89e5fafe7fe22ff3b26c69 # Parent ec19fde3944ddab7d19f7f81f0ab60e1d76b5c49 (rmail-redecode-body): New function. diff -r ec19fde3944d -r a06f22cd075b lisp/mail/rmail.el --- a/lisp/mail/rmail.el Mon Jan 22 17:11:38 2001 +0000 +++ b/lisp/mail/rmail.el Mon Jan 22 17:13:47 2001 +0000 @@ -2257,6 +2257,66 @@ (if blurb (message blurb)))))) +(defun rmail-redecode-body (coding) + "Decode the body of the current message using coding system CODING. +This is useful with mail messages that have malformed or missing +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 encodes the message back to its +original form, and decodes it again, using the coding system you +supply at the prompt. + +Note that if Emacs erroneously auto-detected one of the iso-2022 +encodings in the message, this function might fail because the escape +sequences that switch between character sets and also single-shift and +locking-shift codes are impossible to recover. This function is meant +to be used to fix messages encoded with 8-bit encodings, such as +iso-8859, koi8-r, etc." + (interactive "zCoding system for re-decoding this message: ") + (when (not rmail-enable-mime) + (or (eq major-mode 'rmail-mode) + (switch-to-buffer rmail-buffer)) + (save-excursion + (unwind-protect + (let ((msgbeg (rmail-msgbeg rmail-current-message)) + (msgend (rmail-msgend rmail-current-message)) + x-coding-header) + (narrow-to-region msgbeg msgend) + (goto-char (point-min)) + (when (search-forward "\n*** EOOH ***\n" (point-max) t) + (narrow-to-region msgbeg (point))) + (goto-char (point-min)) + (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t) + (let ((old-coding (intern (match-string 1))) + (buffer-read-only nil)) + (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. + (setq coding + (coding-system-change-eol-conversion + coding + (coding-system-eol-type old-coding))) + (setq x-coding-header (point-marker)) + (narrow-to-region msgbeg msgend) + (encode-coding-region (point) msgend old-coding) + (decode-coding-region (point) msgend coding) + (setq last-coding-system-used coding) + ;; Rewrite the coding-system header according + ;; to what we did. + (goto-char x-coding-header) + (delete-region (point) + (save-excursion + (beginning-of-line) + (point))) + (insert "X-Coding-System: " + (symbol-name last-coding-system-used)) + (set-marker x-coding-header nil) + (rmail-show-message)) + (error "No X-Coding-System header found"))))))) + ;; Find all occurrences of certain fields, and highlight them. (defun rmail-highlight-headers () ;; Do this only if the system supports faces.