简体   繁体   English

如何解码7bit普通/文本邮件正文(如何删除CRLF)?

[英]How to decode 7bit plain/text email body (how to remove CRLF)?

Content-Transfer-Encoding: 7bit
Content-Type: plain/text

As per rfc5322 you need to break line (add CRLF) after 78 characters. 根据rfc5322,您需要在78个字符后断行(添加CRLF)。

My question is how can I decode the text/body back(remove the CRLF)? 我的问题是如何解码文本/正文(删除CRLF)? How do I know which CRLF was added by the encoder and which was part of the original body content? 我怎么知道编码器添加了哪个CRLF,哪个是原始正文内容的一部分? I've checked few implementations but most of them don't seem to bother though on encoding the rule is enforced. 我已经检查了一些实现,但大多数实际上似乎并不打扰,但编码规则是强制执行的。

The RFC doesn't say you have to break lines after 78 characters: RFC没有说你必须在78个字符后断行:

Each line of characters MUST be no more than 998 characters, and SHOULD be no more than 78 characters, excluding the CRLF. 每行字符必须不超过998个字符,并且不应超过78个字符,不包括CRLF。

There is no way do “decode” a CRLF added by the sending system, the recipient will just leave it as it is. 没有办法“解码”发送系统添加的CRLF,收件人将保持原样。

If you don't want to modify the message, just don't add line breaks in any line with less than 998 characters. 如果您不想修改消息,请不要在任何小于998个字符的行中添加换行符。

Actually, rfc5322 states: 实际上,rfc5322声明:

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

That said, it is recommended to limit lines to 78 characters. 这就是说, 建议行限制为78个字符。

For text-based MIME parts (such as the one in your example), you have a few options to achieve this: 对于基于文本的MIME部分(例如示例中的部分),您有几个选项可以实现此目的:

  1. Use text/plain; format=flowed 使用text/plain; format=flowed text/plain; format=flowed . text/plain; format=flowed For more information about this format, check out rfc2646 . 有关此格式的更多信息,请查看rfc2646 Essentially it provides a way of wrapping long lines that is reversible by the receiving client (hey! that's exactly what you wanted!) 从本质上讲,它提供了一种包装长线的方式,接收客户端是可逆的(嘿!这正是你想要的!)
  2. Use a different Content-Transfer-Encoding , such as quoted-printable or base64 . 使用不同的Content-Transfer-Encoding ,例如quoted-printablebase64
  3. Allow lines to exceed 78 characters and hope that they aren't longer than 998 characters... but you essentially end up with the same problem if you have extremely long lines that exceed 998 characters, so your best bet really is to follow one of the other options. 允许行超过78个字符,并希望它们不超过998个字符...但如果你有超过998个字符的超长行,你基本上会遇到同样的问题,所以你最好的选择是遵循其中一个其他选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM