Skip to main content

II.B. Syntax

This syntax is given in four parts. The first part describes a base-level lexical analyzer which feeds the higher-level parser described in the succeeding sections. The second part gives a general syntax for messages and standard header fields. The third part specifies the syntax of addresses. A final section specifies some general syntax which supports the other sections.

1. Lexical Analysis of Messages​

a. General Description​

A message consists of headers and, optionally, a body (i.e. the <message-text>). The <message-text> part is just a sequence of ASCII characters; it is separated from the headers by a null line (i.e., a line with nothing preceding the <crlf>).

1) Folding and unfolding of headers​

Each header item can be viewed as a single, logical, long line of ASCII characters. For convenience, this conceptual entity can be split into a multiple-line representation (i.e., "folded"). The general rule is that wherever there can be <linear-white-space> characters, you can instead insert a <crlf> immediately followed by AT LEAST one <linear-white-space> character. Thus, the single line

To:  "Joe Dokes & J. Harvey" <ddd at Host>, JJV at BBN

can be represented as

To:  "Joe Dokes & J. Harvey" <ddd at Host>,
JJV at BBN

and

To:  "Joe Dokes & J. Harvey"
<ddd at Host>,
JJV at BBN

and

To:  "Joe Dokes
& J. Harvey" <ddd at Host>, JJV at BBN

The process of moving from this folded multiple-line representation of a header field to its single line representation will be called "unfolding". Unfolding is accomplished by regarding <crlf> immediately followed by a <linear-white-space-char> as equivalent to the <linear-white-space-char>.

2) Structure of header fields​

Once header fields have been unfolded, they may be viewed as being composed of a <field-name> followed by a ":" (colon), followed by a <field-body>. The <field-name> must be composed of printable ASCII characters (i.e., characters which have decimal values between 33 and 126) and <linear-white-space> characters. The <field-body> may composed of any ASCII characters (other than <cr> and <lf>, which have been removed by unfolding).

Certain header fields may be interpreted according to an internal syntax which some systems may wish to parse. These fields will be referred to as structured fields. Examples include fields containing dates and addresses. Other fields, such as the subject field, are regarded simply as a single line of text.

3) Field names​

To aid in the creation and reading of <field-name>s, the free insertion of <linear-white-space> characters is allowed in reasonable places. Rather than obscuring the syntax specification for <field-name> with the explicit syntax for these <linear-white-space> characters, the existence of a simple "lexical" analyzer is assumed. The analyzer reinterprets the unfolded text which comprises the <field-name> as a sequence of <atoms> separated by <linear-white-space> characters. The field name may be conveniently represented by the sequence of these atoms, separated by a single ASCII space character.

4) Field bodies​

To aid in the creation and reading of structured fields, the free insertion of <linear-white-space> characters is allowed in reasonable places. Rather than obscuring the syntax specifications for these structured fields with explicit syntax for these <linear-white-space> characters, the existence of another simple "lexical" analyzer is assumed. It provides an interpretation of the unfolded text comprising the body of the field as a sequence of lexical symbols. These include

  • individual special characters
  • quoted strings
  • comments
  • atoms

The first three symbols are self-delimiting. Atoms are not; they therefore are delimited by the self-delimiting symbols and by <linear-white-space>.

So, for example, the folded body of an address field

":sysmail"@ Some-Host,
Muhammed(I am the greatest)Ali at WBA

is analyzed into the following lexical symbols and types:

":sysmail"              quoted string
@ special
Some-Host atom
, special
Muhammed atom
(I am the greatest) comment
Ali atom
at atom
WBA atom

b. Formal Definition​

<field>           ::=   <field-name> ":" <field-body>
<field-name>      ::=   <atom>
                      | <atom> <field-name>

<field-body>      ::=   <field-body-contents>
                      | <field-body-contents> <crlf>
                           <linear-white-space-char>
                           <field-body>

<field-body-contents> ::= <the TELNET ASCII characters making
                           up the <field-body>, as defined in
                           the following sections, and
                           consisting of combinations of
                           <atom>, <quoted-string>, <text-line>,
                           and <specials> tokens>

<atom>            ::=   <a sequence of one or more TELNET
                           ASCII alpha-numeric or graphics
                           characters, excluding all control
                           characters (those characters with
                           a decimal value less than 33 or
                           equal to 127) and <delimeters> >

<quoted-string>   ::=   <double quote mark ("), decimal 34>
                           <a sequence of one or more TELNET
                           ASCII characters, where two
                           adjacent quotes are treated as a
                           single quote and part of the
                           string> <">

<text-line>        ::=   <a sequence of one or more TELNET
                           ASCII characters excluding <cr>
                           and <lf> >

<message-text>     ::=   <a sequence of zero of more TELNET
                           ASCII characters>

<delimeters>      ::=   <specials> | <comment>
                      | <linear-white-space> | <crlf>

<specials>        ::=   "(" | ")" | "<" | ">"
                      | "@" | "," | ";" | ":" | <">

<comment>         ::=   "(" <TELNET ASCII characters, except
                           <crlf> > ")"

<linear-white-space>::= <linear-white-space-char>
                      | <linear-white-space-char>
                           <linear-white-space>
<linear-white-space-char>::=  <space> | <horizontal-tab>

<space>           ::=   <TELNET ASCII space (decimal 32)>
<tab>             ::=   <TELNET ASCII tab   (decimal  9)>
<cr>              ::=   <TELNET ASCII carriage return
                           (decimal 13)>
<lf>              ::=   <TELNET ASCII line feed (decimal 10)>
<crlf>            ::=   <TELNET ASCII carriage return/line
                         feed (decimal 13, followed by
                         decimal 10)>

c. Clarifications​

1) Comments​

Comments may appear only within <field-body>s of structured fields. A comment is any set of TELNET ASCII characters, which is not within a quoted string, and which is enclosed in matching parentheses; parentheses nest, so that if a left paren occurs in a comment string, there must also be a matching right paren.

Comments are NOT passed to the FTP server, as part of a MAIL or MLFL command, since comments are not part of the "formal" address.

2) "White space"​

Remember that in structured fields, MULTIPLE LINEAR WHITE SPACE TELNET ASCII CHARACTERS (namely <tab>s and <space>s) ARE TREATED AS SINGLE SPACES AND MAY FREELY SURROUND ANY SYMBOL. In all header fields, at least one <space> is REQUIRED only at the beginning of folded lines.

Writers of mail-sending (i.e. header generating) programs should realize that there is no Network-wide definition of the effect of <tab> TELNET ASCII characters on the appearance of text at another Network host; therefore, the use of <tab>s in message headers, though permitted, is discouraged.

Note that the contents of messages are required to conform with TELNET NVT conventions (e.g. <cr> must be followed by either <lf>, making a <crlf>, or <null>, if the <cr> is to stand alone).

3) Quoted strings​

Where permitted (i.e., in structured fields) quoted strings are treated as a single symbol (i.e. equivalent to an <atom> syntactically). However, if quoted strings are to be "folded" onto multiple lines, then the syntax for folding must be adhered to (See items II.B.1.a.1, above, and II.B.1.c.6, below.) Note that the official semantics do not encounter <crlf>s in quoted strings, although particular parsing programs may wish to note their presence.

4) Bracketing characters​

There are two types of brackets which must be well nested:

  • Parentheses are used to indicate comments.
  • Angle brackets ("<" and ">") are used where there is a question of the presence of machine-usable code (e.g. deliminating mailboxes).

5) Case independence of certain specials <atom>s​

It should be assumed by all mail reading programs that certain <atom>s can be represented in any combination of upper and lower case. These are:

  • <field-name>s,
  • "File", in a <path>,
  • "at", in an <at-indicator>,
  • <host-name>s,
  • <day-of-week>s,
  • <string-month>s, and
  • <time-zone>s

For example, the <field-name>s "From", "FROM", "from", and even "FroM" should all be treated identically. Note that, at the level of this specification, case IS relevant to other <word>s and <text-line>s. Also see Section II.C.1.a.4, below.

6) Folding long lines​

Each header item (field of the message) may be represented on exactly one line consisting of the name of the field and its body, and this is what the parser sees. For readability, it is recommended that the <field-body> portion of long header items be "folded" onto multiple lines of the actual header.

7) Backspace characters​

Backspace TELNET ASCII characters (ASCII BS, decimal 8) may be included in <text-line> and <quoted-string> to effect overstriking; however, any use of backspaces which effects an overstrike to the left of the beginning of the <text-line> or <quoted-string> is prohibited.