emailencodingcharacter-encodingasciirfc5322

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.


Solution

  • 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. 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.