开发者

Does .Net MailMessage auto fold header fields longer than RFC2822 max length?

开发者 https://www.devze.com 2023-01-12 22:51 出处:网络
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 lengt开发者_StackOverflow中文版h restrictions?RFC2822

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 lengt开发者_StackOverflow中文版h 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消