开发者

Preserving original formatting in plaintext emails (ie. we're parsing and would like to throw out auto-inserted line breaks)

We're receiving and parsing plaintext emails for a reply-via-email feature. Basically, we have a forum and people can reply to a forum thread by replying to the notification email.

The problem we're seeing is that email clients will generate a plaintext version of the email, but hard wrap it at 80 characters. From what I've read, this is in accordance with email specifications. The end result is that the forum reply created from the email has linebreaks at every 80 characters, making the formatting quite strange when displayed on the web.

When we parse the plaintext we would like to preserve the original formatting. Is there any way to do this reliably? For 开发者_Go百科example, are the auto-inserted terminators always a "\r\n" instead of just a "\n"? Could we strip out all "\r\n" and leave all "\n" and be safe, or will that garble messages just as bad as doing nothing?


You can't rely on all email clients to insert "\r\n" when wrapping text. The difference in line ending characters usually depends on the operating system conventions.

People usually have to press return twice to make a real paragraph break in email, so it is probably best to remove single line endings, but leave multiple line endings. I.e. "\r\n" or "\n" gets stripped, but "\r\n\r\n" and "\n\n" are left.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜