views:

12

answers:

1

See RFC 2822, section 2.1.1 and 2.2.3 to start

Does System.Net.Mail.MailMessage auto fold its header fields if their content exceeds the maximum length restrictions? RFC2822 states that a header field must not exceed 998 characters per line. To get around that, CRLF may be inserted to have a header field take up more than one line.

Thoughts?

+2  A: 

The MailMessage class does not do any automatic folding at least until it's sent using an SmtpClient. It's only when the message is sent that .NET performs automatic folding of the header fields in order to construct the MIME message. You can check this by accessing MailMessage.Headers after the message is sent.

The folding may occur at several places depending if the header field needs to be previously encoded. For example if the subject contains non US-ASCII characters it must be encoded in Base64 or Q encoding. In this case the classes responsible for the encoding also do the folding.

If you use Reflector you can take a look for example at the MailWriter class which is one of the classes that performs folding and that, at least in .NET 2.0, uses the recommended default line limit of 78 characters per line as specified in RFC2822.

Each line of characters MUST be no more than 998 characters, and SHOULD be no more than 78 characters, excluding the CRLF.

João Angelo