may contain any ASCII characters, including whitespace
and newlines that result from joining. For most headers, however,
those characters must obey the following rules for grouping:
In the header
, space characters separate
one item from another. Each space-delimited item is further subdivided
by specials (see below), into atoms.
atom special atom
An atom is the smallest unit in a header and may not contain
any control characters. When the
is an address, an atom
is the same thing as a token (see
The special characters are those used to separate one component
of an address from another. They are internally defined as:
( ) < > @ , ; : \ " . [ ]
A special character can be made nonspecial by preceding it with
a backslash character, for example,
atom special atom
The space and tab characters are also used to separate atoms and
can be thought of as specials.
Quotation marks can be used to force multiple items to be
treated as a single atom. For example,
a single atom
Quoted text may contain any characters except the quotation mark
) and the backslash character (
Some headers, such as
Section 35.10.31, Subject:
), impose no rules on
the text in the header
. For such headers, atoms,
specials, and quotes have no significance, and the entire field
is taken as arbitrary text.
The detailed requirements of each header name are covered at the
end of this chapter.
Macros may appear in any position in the
of a header
Such macros are not expanded (their values tested or used)
until mail is queued or delivered. For the meaning of each macro name and a description of when each is given a value, see
Only two macro prefixes may be used in the
to replace the macro's
name with its value at that place in the
to perform conditional
replacement of a macro's value.
For example, the following header definition
prefix to insert the
value of the macro
into the header field:
Section 31.10.42, $x
contains as its value the full name of the sender.
When the possibility exists that a macro will not have a value at the
time the header line is processed, the
Section 31.6, "Macro Conditionals: $?, $|, and $."
) may be used:
HReceived: $?sfrom $s $.by $j ($v/$V)
operator cause the text
to be inserted into the header field
if the macro
has a value.
may contain as its value the
name of the sending site.
Recall that the backslash escape
) is used to deprive the special
characters of their special meaning.
of header definitions the escape character
may be used only inside quoted strings (see next item), in domain
literals (addresses enclosed in square bracket pairs), or in comments
Specifically, this means that the escape character may
be used within atoms. Therefore the following is not legal:
Instead, the atom to the left of the
must be isolated
with quotation marks:
Recall that quotation marks (
) force arbitrary
text to be viewed as a single atom. Arbitrary text is everything
(including joined lines) that begins with the first quotation mark and
ends with the final quotation mark. The following
example illustrates two quoted strings:
"One long string carried over
two lines by indenting the second"
The quotation mark character may appear inside a quoted
string only if it is escaped by using a backslash.
"George Herman \"Babe\" Ruth"
does not check for balanced quotation marks.
If it finds the first but not the second, it takes everything up to
the end of the line as the quoted string.
When quotation marks are used in an
they must be balanced. Although
unbalanced quotation marks can cause serious problems when they
are propagated to other programs.
Comments consist of text inside a header
that is intended to give humans
Comments are saved internally by
when processing headers,
then are restored, but otherwise are not used.
Beginning with V8.7
Section 30.8.14, F=c
) can be used to prevent restoration
of the saved comments.
A comment begins with a left parenthesis and ends with a right parenthesis.
Comments may nest. The following lines illustrate a non-nested comment
and a comment nested inside another:
(this is a comment)
(text(this is a comment nested inside another)text)
Comments may be split over multiple lines by indenting:
(this is a comment
split into two lines)
A comment (even if nested) separates one atom from another
just like a space or a tab does.
Therefore the following produces two atoms rather than one:
However, comments inside quoted strings are not special, so the
following produces a single atom:
Parentheses may exist inside of comments only if they are escaped
with a backslash:
<email@example.com> (The happy administrator ;-\))
Many of the special characters that are used in the header
in addresses need to appear in balanced pairs.
shows these characters and the characters needed to balance them.
Failure to maintain balance can lead to failed mail.
Note that only parentheses may be nested. None of the other balanced pairs
You have already seen the quoted string and comments. The angle brackets
) are used to specify a machine-readable
address, such as
. The square brackets (
) are used to specify a direct Internet address (one that
bypasses normal DNS name lookups) such as
program gives warnings about unbalanced characters
only when it is attempting to extract an address from a header definition,
from the header line of a mail message, or
from the envelope.
Beginning with V8.6, when
finds an unbalanced condition,
it tries to balance the offending characters as rationally as possible.
Whether or not it can balance them, it prints
one of the following warning messages:
If it did not succeed in balancing them, the mail will probably bounce.