29.14. Rmail and Coding Systems

Rmail automatically decodes messages which contain non-ascii characters, just as it does with files you visit and with and subprocess output. Rmail uses the standard charset=charset header in the message to determine how the was message encoded by the sender. It maps charset into the corresponding Emacs coding system (Section 20.6), and uses that coding system to decode message text. If the message header doesn't have the charset specification, or if the charset it specifies is not recognized, Rmail chooses the coding system with the usual Emacs heuristics and defaults (Section 20.7).

Occasionally, a message is decoded incorrectly, either because Emacs guessed the wrong coding system in the absence of the charset specification, or because the specification was inaccurate. For example, a misconfigured mailer could send a message with a charset=iso-8859-1 header when the message is actually encoded in koi8-r. When you see the message text garbled, or some of its characters displayed as empty boxes, this may have happened.

You can correct the problem by decoding the message again using the right coding system, if you can figure out or guess which one is right. To do this, invoke the M-x rmail-redecode-body command. It reads the name of a coding system, encodes the message body using whichever coding system was used to decode it before, then redecodes it using the coding system you specified. If you specified the right coding system, the result should be readable.

Decoding and encoding using the wrong coding system is lossless for most encodings, in particular with 8-bit encodings such as iso-8859 or koi8. So, if the initial attempt to redecode the message didn't result in a legible text, you can try other coding systems until you succeed.

With some coding systems, notably those from the iso-2022 family, information can be lost in decoding, so that encoding the message again won't bring back the original incoming text. In such a case, rmail-redecode-body cannot work. However, the problems that call for use of rmail-redecode-body rarely occur with those coding systems. So in practice the command works when you need it.