I try to process email in my application, and everything works fine until I get an email from a user whose mail server uses word wrap from a text message. I know the word wrap is part of the RFC specification, so I'm just looking for the best way to handle this in order to get a beautifully displayed message.
Original Email:
Here is my main problem. When I send an email, the text breaks pretty weird. It seems that the message itself is broken. I am not sure why this is so, because my original letter does not look like that.
Here's what the received email looks like (marked CRLF to show where their mail server is inserting):
Here is my main problem. When I send an email, the text breaks rather into CRLF
surprisingly. It seems that the message itself is broken. I'm not sure CRLF
why is this because my original letter is not like CRLF
what.
My processing code goes through the following and then inserts the result into the database.
$dirty_string = nl2br($dirty_string); $config = HTMLPurifier_Config::createDefault(); $config->set('AutoFormat.RemoveEmpty', 'true'); $config->set('AutoFormat.RemoveEmpty.RemoveNbsp', 'true'); $config->set('HTML.Allowed', 'a[href],br,p'); $purifier = new HTMLPurifier($config); $clean_string = $purifier->purify($dirty_string);
Below is the result that is displayed. If the div on my page is not wide enough for the line, the browser will automatically close it, but line break from nl2br () will cause the next line to be short.
Here is my main problem. When I send an email, text
rather broken
surprisingly. It seems that the message itself is
is broken. I'm not sure
why is this because my original letter looks
nothing like this
what.
I thought that maybe I could just change the double CRLF to new paragraphs and split all the single CRLFs to merge the lines into one line that will display correctly. But if someone sends the following token list to an email, this will break the list.
This is my CRLF list
- Paragraph 1 of the CRLF
- Paragraph 2 of the CRLF
etc...
Any help would be greatly appreciated.