Messages and MIME

Read an Internet message

Separate the RFC 5322 header section from the body and recognize continuation lines.

8 minute lesson

~~~

The message transferred after DATA has a header section, one empty line, and a body.

Each header field has a name, a colon, and a value. A field can continue on following lines that begin with whitespace, although generating unnecessarily folded fields is discouraged in modern software.

From: Alice <alice@example.org>
To: Bob <bob@example.net>
Subject: Project update
Date: Thu, 30 Jul 2026 10:00:00 +0200
Message-ID: <1234@example.org>

The deployment is complete.

The first empty line is structural. Everything before it is fields; everything after it is body content. A line in the body that looks like Subject: hello does not become a header.

Header field names are case-insensitive, but field meaning and allowed repetition come from their definitions. Parsers should unfold continuation lines before interpreting a field value. They must also reject raw line breaks injected through untrusted form input, or an attacker can create extra fields.

Message format uses CRLF line endings on the wire. Libraries normally normalize them. When investigating a malformed message, inspect the raw source rather than the rendered mail view because the viewer may repair or hide invalid structure.

Transport fields can be prepended after message creation. That means the delivered message is not necessarily byte-for-byte identical to the submitted one, even when its body is unchanged.

Add a folded Subject field and a body line beginning with From: to the example. Mark the exact empty line where header parsing stops.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →