Messages and MIME
MIME types and transfer encodings
Describe message content with media types, character sets, and safe transfer encodings.
8 minute lesson
MIME adds fields such as MIME-Version, Content-Type, and Content-Transfer-Encoding.
Content-Type: text/plain; charset=utf-8 tells a reader how to interpret the bytes. quoted-printable keeps mostly readable text efficient; base64 safely represents arbitrary binary data using ASCII characters.
Base64 is an encoding, not encryption. Anyone who receives it can decode it. The media type describes the content; the transfer encoding describes how that content was made safe for transport.
Here is a small text part:
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
The caf=C3=A9 opens at 08:00.
The charset explains how decoded bytes become characters. The transfer encoding explains how those bytes were represented for transport. Mixing those two jobs produces mojibake or failed decoding.
Quoted-printable works well for text that is mostly ASCII. Base64 adds overhead but handles arbitrary bytes predictably. The decoder must process transfer encoding before it interprets the media type and charset.
Do not trust a declared Content-Type as proof of file safety. Senders can label executable content as an image. A receiving application should inspect content, apply size limits, and keep active data away from executable contexts.
Long lines and non-ASCII headers use their own message-format rules. Do not base64-encode an entire RFC 5322 message unless the containing protocol explicitly calls for it.
Decode caf=C3=A9 in two steps: quoted-printable to bytes, then UTF-8 to text. Explain what breaks if you assume ISO-8859-1.
Lesson completed