aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2006-11-04 15:39:33 +0000
committerEli Zaretskii2006-11-04 15:39:33 +0000
commitd3e1986ff9d5bfa4f92c4cd16352c54fdef8dcc0 (patch)
tree84d50102b99c1bde8e88ddf3ca8147b7fa1e94b3
parent519c48d434b00413471e7d68099a7ad56ca957b1 (diff)
downloademacs-d3e1986ff9d5bfa4f92c4cd16352c54fdef8dcc0.tar.gz
emacs-d3e1986ff9d5bfa4f92c4cd16352c54fdef8dcc0.zip
(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.
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/mail/rmail.el32
2 files changed, 36 insertions, 3 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index b7f2a1a843c..41141bd7a8c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
12006-11-04 Eli Zaretskii <eliz@gnu.org>
2
3 * mail/rmail.el (rmail-redecode-body): New optional argument RAW.
4 Don't encode body if RAW is non-nil, or if the old encoding is
5 identical to the new encoding, or if the body contains only
6 eight-bit-* characters.
7
12006-11-04 Yoni Rabkin Katzenell <yoni-r@actcom.com> (tiny change) 82006-11-04 Yoni Rabkin Katzenell <yoni-r@actcom.com> (tiny change)
2 9
3 * faces.el (faces-sample-overlay, describe-face): Revert last 10 * faces.el (faces-sample-overlay, describe-face): Revert last
diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el
index 68dfd9f7ca4..148f3913c3e 100644
--- a/lisp/mail/rmail.el
+++ b/lisp/mail/rmail.el
@@ -2828,7 +2828,7 @@ If summary buffer is currently displayed, update current message there also."
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.
2833This is useful with mail messages that have malformed or missing 2833This is useful with mail messages that have malformed or missing
2834charset= headers. 2834charset= headers.
@@ -2838,6 +2838,16 @@ and displayed in the RMAIL buffer, but the coding system used to
2838decode it was incorrect. It then encodes the message back to its 2838decode it was incorrect. It then encodes the message back to its
2839original form, and decodes it again, using the coding system CODING. 2839original form, and decodes it again, using the coding system CODING.
2840 2840
2841Optional argument RAW, if non-nil, means don't encode the message
2842before decoding it with the new CODING. This is useful if the current
2843message text was produced by some function which invokes `insert',
2844since `insert' leaves unibyte character codes 128 through 255 unconverted
2845to multibyte. One example of such a situation is when the text was
2846produced by `base64-decode-region'.
2847
2848Interactively, invoke the function with a prefix argument to set RAW
2849non-nil.
2850
2841Note that if Emacs erroneously auto-detected one of the iso-2022 2851Note that if Emacs erroneously auto-detected one of the iso-2022
2842encodings in the message, this function might fail because the escape 2852encodings in the message, this function might fail because the escape
2843sequences that switch between character sets and also single-shift and 2853sequences that switch between character sets and also single-shift and
@@ -2849,7 +2859,8 @@ iso-8859, koi8-r, etc."
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))
@@ -2883,7 +2894,22 @@ iso-8859, koi8-r, etc."
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