MIME Encoding

When a MIME-compliant MUA implementation is faced with a file to attach to a message, it must decide how to encode it. Indeed, it must decide if it needs encoding at all. This section describes the choices involved and the algorithms for performing any necessary encoding. Decoding of MIME message parts is effectively the opposite of encoding. Decoding is also addressed in this section.

When creating a mail message, one must decide how to encode each part of the message. In general, 8-bit and binary encodings will not be used for Internet email. Seven-bit text should be left as is. Quoted-printable encoding should be used for data that is nominally text and human readable but which should be protected in transit from mail gateways that might wrap the lines, change the tabs to spaces, or otherwise affect formatting that the sender would like to retain. Base64 encoding should be used to represent binary data or arbitrary octet streams that do not need to be transmitted in any human-readable form.

As a rule of thumb, send simple text as 7-bit (no encoding). Test other textual data for special characters (to be defined later), and encode with quoted-printable if needed. Encode any binary, nontextual data with base64 encoding.

When receiving MIME messages, no decoding is needed for Content-Transfer-Encoding values of 7-bit, 8-bit, or binary. Decoding of quoted-printable and base64 encodings are discussed in the sections that follow.

Get Programming Internet Email now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.