Subject: bug#4623: 23.1.50; rmail changes encoding of characters on save

From: Stefan Monnier <[email-masked]>
Date: Fri, 04 Dec 2009 13:42:31 -0500

> The cure for this bug, viz.
>   *** rmail.el   6 Oct 2009 06:40:40 -0000  1.554
>   --- rmail.el   13 Oct 2009 01:17:20 -0000
>   ***************
>   *** 4176,4181 ****
>   --- 4176,4182 ----
>     (defun rmail-write-region-annotate (start end)
>       (when (and (null start) (rmail-buffers-swapped-p))
>         (set-buffer rmail-view-buffer)
>   +     (set (make-local-variable 'coding-system-for-write) 'no-conversion)
>         (widen)
>         nil))

> is IMO not much better than the disease: now C-x C-s _always_ leaves
> the RMAIL buffer in no-conversion state, until you display a message,
> e.g., with "M-n".

> I think this happens because the above sets the encoding of
> rmail-view-buffer, where we display the messages, to no-conversion.

In the above code, rmail-view-buffer is (confusingly enough) the
raw-data buffer (which is why we switch to it to save the raw data), so
setting coding-system-for-write in that buffer is right.

The problem is that this setting is then somehow propagated to the other
buffer (the one we show to the user).

> Perhaps we should special-case RMAIL in save-buffer, or maybe do
> something in buffer-swap-text.

Most likely we need to do something in the rmail code that calls
buffer-swap-text.  Some debugging `message's in there showing the
coding-systems in use in each buffer before and after the swap should
make things more clear.

        Stefan