简体   繁体   中英

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.

My question is how can I decode the text/body back(remove the CRLF)? How do I know which CRLF was added by the encoder and which was part of the original body content? 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:

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

There is no way do “decode” a CRLF added by the sending system, the recipient will just leave it as it is.

If you don't want to modify the message, just don't add line breaks in any line with less than 998 characters.

Actually, rfc5322 states:

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.

For text-based MIME parts (such as the one in your example), you have a few options to achieve this:

  1. Use text/plain; format=flowed text/plain; format=flowed . For more information about this format, check out 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 .
  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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