Protocols
MIME — everything that is not text
Email originally knew 128 characters and no attachments. No accents, no images, no formatting. Everything that goes without saying in a message today has been folded into that corset — without altering it.
The constraint
The original message format provided for lines of ASCII characters: 128 characters, 7 bits, the Latin alphabet without accents, digits, punctuation. There was no more than that, and no more was needed as long as text flowed between English-speaking researchers.
Two wishes burst that open: people wanted to write in their own language, and they wanted to send files along. Both are binary data, and binary data does not survive a transfer that passes on only 7 bits.
The way out: make everything text again
The solution from 1996 does not change the message format. Instead it packs arbitrary data so that what comes out the other end is innocuous ASCII lines again, and puts extra lines in front saying what is inside.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=_boundary_1"
--=_boundary_1
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hi Bert, the notes from the caf=C3=A9 are attached. Cheers, Anna
--=_boundary_1
Content-Type: application/pdf; name="notes.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="notes.pdf"
JVBERi0xLjQKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVy
… another 40,000 characters …
--=_boundary_1--
A message with an attachment, from the inside. Every part of it is pure ASCII text — the PDF included.
The four components
- Boundaries. A string that does not occur in the content separates the parts. The same principle as with the @ in an address: a separator is only any good if it cannot appear in what is being separated.
-
Content type.
text/plain,application/pdf,image/png. Only this tells the mail program whether to display something or offer it for saving. -
Encoding.
quoted-printablefor text that is mostly readable and contains only a few special characters —=C3=A9is an "é".base64for anything that is binary anyway. -
Character set.
charset=UTF-8says how the bytes become letters. If the declaration is missing or wrong, you get the familiar garbled characters.
Why attachments get bigger
Base64 represents three bytes as four characters. An attachment therefore grows by about a third, plus line breaks. A 10 MB file thus takes a good 13.5 MB inside the message — and that is what size limits which look generous at first glance actually founder on.
This is not a flaw in the encoding but the price of pushing binary data through a channel that knows only text. It is still paid on every single message today, even though practically every server involved could long since transfer 8 bits.
Accents in the subject line
The header section is a special case: even today it may contain only ASCII. A subject with accented characters is therefore packed up once more, differently:
Subject: =?UTF-8?Q?Notes_from_the_Caf=C3=A9_Th=C3=A9r=C3=A8se?=
Between =? and ?= stand the character set, the encoding and
the content. Mail programs undo this for display — which is why you almost never see
it.
And HTML mail
Formatted messages are not a format of their own but one more content type. The usual
arrangement is multipart/alternative: the same message twice, once as text
and once as HTML. The mail program takes whichever it can handle.
With that came the loading of images from the network into email — and with it the read receipt nobody asked for: an image with a unique address reveals, when fetched, when and where a message was opened. That mail programs block external content by default today is the answer to it.
What is remarkable about it
MIME got a format that can only do text to carry anything at all — without changing a single line of the protocol underneath. Old systems that knew nothing of MIME went on displaying readable text, just with odd-looking lines around it.
That is the same shape of construction as everything added later: take nothing away, break nothing, put it all alongside. It has kept email alive for four decades. It is also the reason a simple message with an attachment consists today of five layers nested inside each other, every one of them from a different era.