D. J. Bernstein
Internet mail
SMTP: Simple Mail Transfer Protocol

Encoded messages

Some messages cannot be expressed in SMTP. Messages in SMTP cannot contain partial lines. Messages cannot contain lines with the byte sequence \015\012. Clients asked to send such messages must refuse.

Here is how to encode a message. Insert a dot in front of any line that already starts with a dot. Concatenate all the lines, with \015\012 between each pair of lines; the result ends with \015\012 (unless the original message had no lines), since the final line is empty. Append a dot followed by \015\012.

This encoding is self-delimiting. An encoded message ends with the five-byte sequence "\015\012.\015\012", and does not contain the same sequence anywhere else. (Exception: the three-byte sequence ".\015\012" is an encoded message, representing a zero-line message.)

For example, the string "This is a test.\015\012.... Three dots\015\012.\015\012" is an encoded message. It represents the three-line text message

     This is a test.
     ... Three dots
which under Windows would be stored as the string "This is a test.\015\012... Three dots\015\012". Notice that the encoded message starts with four dots on the second line.

Arbitrary limits on messages

RFC 821 prohibits lines longer than 998 bytes, and requires that all servers be able to accept 998-byte lines. In practice, users sometimes send longer lines.

RFC 1123 says that ``mailer software MUST be able to send and receive messages of at least 64K bytes in length (including header), and a much larger maximum size is highly desirable.''