3

I'm debugging a MIME parser that fails to parse a header from one email service. The email service includes a header that consists of a field body entirely on the next line, like so:

Message-Id:
  <12345.67890.abcdef@example.com>

Is this legal?

RFC-822 specifies the following grammar for valid headers:

3.2.  HEADER FIELD DEFINITIONS

      These rules show a field meta-syntax, without regard for the
 particular  type  or internal syntax.  Their purpose is to permit
 detection of fields; also, they present to  higher-level  parsers
 an image of each field as fitting on one line.

 field       =  field-name ":" [ field-body ] CRLF

 field-name  =  1*<any CHAR, excluding CTLs, SPACE, and ":">

 field-body  =  field-body-contents
                [CRLF LWSP-char field-body]

 field-body-contents =
               <the ASCII characters making up the field-body, as
                defined in the following sections, and consisting
                of combinations of atom, quoted-string, and
                specials tokens, or else consisting of texts>

Does the empty string satisfy field-body-contents to allow for the [CRLF LWSP field-body] portion of field-body?

Jesse Spears
  • 136
  • 9

1 Answers1

3

Yes, it is perfectly permissble to fold on whitespace. Usually, this is only done when the line is otherwise too long, but it is entirely optional anyway; there is no requirement to fold, or to avoid folding. (Of course, if a line is too long to meet the RFC5321, it has to be folded, or somehow otherwise shortened. These days, RFC2047 is somewhat more versatile and transparent than traditional whitespace folding.)

As explained in https://www.rfc-editor.org/rfc/rfc5322#section-2.2.3 a folded line is one "logical line". (Note that ye olde 822 has long been superseded by newer standards; 5322 is the current replacement.)

Community
  • 1
  • 1
tripleee
  • 175,061
  • 34
  • 275
  • 318