Mercurial > emacs
comparison lisp/mail/rmail.el @ 73681:e1c32a83bd29
(rmail-redecode-body): New optional argument RAW.
Don't encode body if RAW is non-nil, or if the old encoding is identical to the
new encoding, or if the body contains only eight-bit-* characters.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 04 Nov 2006 15:38:39 +0000 |
parents | f3db6404bec1 |
children | e3694f1cb928 02cf29720f31 |
comparison
equal
deleted
inserted
replaced
73680:a171b46b168c | 73681:e1c32a83bd29 |
---|---|
2826 (with-current-buffer rmail-buffer | 2826 (with-current-buffer rmail-buffer |
2827 (rmail-auto-file)) | 2827 (rmail-auto-file)) |
2828 (if blurb | 2828 (if blurb |
2829 (message blurb)))))) | 2829 (message blurb)))))) |
2830 | 2830 |
2831 (defun rmail-redecode-body (coding) | 2831 (defun rmail-redecode-body (coding &optional raw) |
2832 "Decode the body of the current message using coding system CODING. | 2832 "Decode the body of the current message using coding system CODING. |
2833 This is useful with mail messages that have malformed or missing | 2833 This is useful with mail messages that have malformed or missing |
2834 charset= headers. | 2834 charset= headers. |
2835 | 2835 |
2836 This function assumes that the current message is already decoded | 2836 This function assumes that the current message is already decoded |
2837 and displayed in the RMAIL buffer, but the coding system used to | 2837 and displayed in the RMAIL buffer, but the coding system used to |
2838 decode it was incorrect. It then encodes the message back to its | 2838 decode it was incorrect. It then encodes the message back to its |
2839 original form, and decodes it again, using the coding system CODING. | 2839 original form, and decodes it again, using the coding system CODING. |
2840 | |
2841 Optional argument RAW, if non-nil, means don't encode the message | |
2842 before decoding it with the new CODING. This is useful if the current | |
2843 message text was produced by some function which invokes `insert', | |
2844 since `insert' leaves unibyte character codes 128 through 255 unconverted | |
2845 to multibyte. One example of such a situation is when the text was | |
2846 produced by `base64-decode-region'. | |
2847 | |
2848 Interactively, invoke the function with a prefix argument to set RAW | |
2849 non-nil. | |
2840 | 2850 |
2841 Note that if Emacs erroneously auto-detected one of the iso-2022 | 2851 Note that if Emacs erroneously auto-detected one of the iso-2022 |
2842 encodings in the message, this function might fail because the escape | 2852 encodings in the message, this function might fail because the escape |
2843 sequences that switch between character sets and also single-shift and | 2853 sequences that switch between character sets and also single-shift and |
2844 locking-shift codes are impossible to recover. This function is meant | 2854 locking-shift codes are impossible to recover. This function is meant |
2847 (interactive "zCoding system for re-decoding this message: ") | 2857 (interactive "zCoding system for re-decoding this message: ") |
2848 (when (not rmail-enable-mime) | 2858 (when (not rmail-enable-mime) |
2849 (or (eq major-mode 'rmail-mode) | 2859 (or (eq major-mode 'rmail-mode) |
2850 (switch-to-buffer rmail-buffer)) | 2860 (switch-to-buffer rmail-buffer)) |
2851 (save-excursion | 2861 (save-excursion |
2852 (let ((pruned (rmail-msg-is-pruned))) | 2862 (let ((pruned (rmail-msg-is-pruned)) |
2863 (raw (or raw current-prefix-arg))) | |
2853 (unwind-protect | 2864 (unwind-protect |
2854 (let ((msgbeg (rmail-msgbeg rmail-current-message)) | 2865 (let ((msgbeg (rmail-msgbeg rmail-current-message)) |
2855 (msgend (rmail-msgend rmail-current-message)) | 2866 (msgend (rmail-msgend rmail-current-message)) |
2856 x-coding-header) | 2867 x-coding-header) |
2857 ;; We need the message headers pruned (we later restore | 2868 ;; We need the message headers pruned (we later restore |
2881 (if (memq (coding-system-base old-coding) '(nil undecided)) | 2892 (if (memq (coding-system-base old-coding) '(nil undecided)) |
2882 (setq old-coding | 2893 (setq old-coding |
2883 (car (find-coding-systems-region msgbeg msgend)))) | 2894 (car (find-coding-systems-region msgbeg msgend)))) |
2884 (setq x-coding-header (point-marker)) | 2895 (setq x-coding-header (point-marker)) |
2885 (narrow-to-region msgbeg msgend) | 2896 (narrow-to-region msgbeg msgend) |
2886 (encode-coding-region (point) msgend old-coding) | 2897 (and (null raw) |
2898 ;; If old and new encoding are the same, it | |
2899 ;; clearly doesn't make sense to encode. | |
2900 (not (coding-system-equal | |
2901 (coding-system-base old-coding) | |
2902 (coding-system-base coding))) | |
2903 ;; If the body includes only eight-bit-* | |
2904 ;; characters, encoding might fail, e.g. with | |
2905 ;; UTF-8, and isn't needed anyway. | |
2906 (> (length (delq 'ascii | |
2907 (delq 'eight-bit-graphic | |
2908 (delq 'eight-bit-control | |
2909 (find-charset-region | |
2910 msgbeg msgend))))) | |
2911 0) | |
2912 (encode-coding-region (point) msgend old-coding)) | |
2887 (decode-coding-region (point) msgend coding) | 2913 (decode-coding-region (point) msgend coding) |
2888 (setq last-coding-system-used coding) | 2914 (setq last-coding-system-used coding) |
2889 ;; Rewrite the coding-system header according | 2915 ;; Rewrite the coding-system header according |
2890 ;; to what we did. | 2916 ;; to what we did. |
2891 (goto-char x-coding-header) | 2917 (goto-char x-coding-header) |