Skip to content

BUG: Not fold long (header) line at limited max length in Wrap() #378

Description

@iredmail

Hi @jhillyerd

Current Wrap() folds long line after whitespace or tab characters, but if a line doesn't contain any whitespace and tab, it doesn't respect the max length, which means it doesn't fold the long line at all.

case ' ', '\t':

And unit test TestWrapIdentityLong is wrong too, correct result should be:

// 46 `a` chars in total.
aaaaa\r\n aaaa\r\n aaaa\r\n aaaa\r\n aaaa\r\n aaaa\r\n aaaa\r\n aaaa\r\n aaaa\r\n aaaa\r\n aaaa\r\n a\r\n

According to RFC 5322, section 2.2.3, Long Header Fields:

 Note: Though structured field bodies are defined in such a way
 that folding can take place between many of the lexical tokens
 (and even within some of the lexical tokens), folding SHOULD be
 limited to placing the CRLF at higher-level syntactic breaks.  For
 instance, if a field body is defined as comma-separated values, it
 is recommended that folding occur after the comma separating the
 structured items in preference to other places where the field
 could be folded, even if it is allowed elsewhere.

Suggestions:

  • Fold after additional chars like ,, ; too.
  • Force to fold when it reaches max length.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions