{"id":220,"date":"2006-03-27T08:57:38","date_gmt":"2006-03-26T21:57:38","guid":{"rendered":"http:\/\/www.somethinkodd.com\/oddthinking\/2006\/03\/27\/wordpress-versus-outlook-a-step-forward\/"},"modified":"2007-12-30T21:09:39","modified_gmt":"2007-12-30T11:09:39","slug":"wordpress-versus-outlook-a-step-forward","status":"publish","type":"post","link":"https:\/\/www.somethinkodd.com\/oddthinking\/2006\/03\/27\/wordpress-versus-outlook-a-step-forward\/","title":{"rendered":"WordPress Versus Outlook: A Step Forward"},"content":{"rendered":"<p>I am excited. I have had some Outlook\/WordPress compatibilities issues for almost a year now, but I was unable to find any sign that other people have been suffering them.<\/p>\n<p>I finally have an hypothesis to explain the problem. The hypothesis is untested and as yet unfixed, but this is already a bold step forward.<\/p>\n<h4>Symptoms<\/h4>\n<p>When read in Outlook, emails sent from WordPress are formatted poorly. All of the paragraphs are jammed together. Also, sometimes some of the email headers leak into the body &#8211; e.g. the top line of the email body will read:<\/p>\n<blockquote><p>Content-Type: text\/plain; charset=&#8221;UTF-8&#8243;<\/p><\/blockquote>\n<p>When the same email is read via a webmail client, it looks fine.<\/p>\n<p>When the same email is read via Python&#8217;s poplib, there are CR characters stuck at the end of some lines even after poplib has allegedly filtered out both CR-LF and LF-CR sequences.<\/p>\n<p>When the same email is read via Python&#8217;s poplib with debugging turned on, it seems each line in the body &#8211; and each of the troublesome lines in the header &#8211; is terminated with CR-CR-LF.<\/p>\n<h4>Hypothesis<\/h4>\n<p><a href=\"http:\/\/wordpress.org\/\">WordPress 2.0.2<\/a> uses <a href=\"http:\/\/www.php.net\">PHP<\/a>&#8216;s <a href=\"http:\/\/au2.php.net\/mail\">mail<\/a> function.<\/p>\n<p>According to <a href=\"http:\/\/php.mirrors.ilisys.com.au\/manual\/en\/ref.mail.php#59773\">Ben Cooke<\/a>, the function requires different input when it is running on different operating systems: On Windows systems, you <em>need<\/em> to use the CR-LF, as defined in the SMTP email standard. On Unix systems, you <em>need<\/em> to use the traditional Unix LF only &#8211; it will convert to use the CR-LF style that is required to send down the wire.<\/p>\n<p>Here&#8217;s the kicker. The Unix system will replace all of the LF characters into CR-LF, <em>even if there is already a CR preceding it<\/em>. That means a CR-LF sequence will be broken (Ben Cooke describes it as &#8220;hypercorrected&#8221;) into a CR-CR-LF sequence.<\/p>\n<p>Many email clients accept the CR-CR-LF sequence without blinking. I suspect all the clients that WordPress testers use fall into this category.<\/p>\n<p><code>&lt;supposition&gt;<\/code><br \/>\nOutlook uses a single CR-LF sequence to indicate an end-of-line &#8220;hint&#8221;. Outlook reformats the text to fill the whole window. so it effectively discards that hint. Outlook uses a double CR-LF sequence to indicate an end-of-paragraph.<\/p>\n<p>So when WordPress incorrectly sends an end-of-paragraph CR-CR-LF-CR-CR-LF sequence, Outlook interprets it in two phases.<\/p>\n<p>First, it searches for end-of-paragraphs (CR-LF-CR-LF) and finds none.<\/p>\n<p>Then, it strips out any remaining LF and CR characters, as they are merely end-of-line hints, and can be ignored.<br \/>\n<code>&lt;\/supposition&gt;<\/code><\/p>\n<p>My hypothesis matches the facts neatly.<\/p>\n<h4>Solution<\/h4>\n<p>The solution is three-fold.<\/p>\n<ol>\n<li>Search the WordPress bug database again, now that I have a better idea what to search for, and see if this is already known.<\/li>\n<li>If not, raise the issue in the WordPress database.<\/li>\n<li>Consider writing a simple plugin which replaces the easily-pluggable wp_mail function in WordPress, with an equivalent one that calls one of the third-party open-source replacements for PHP&#8217;s mail function. They allegedly handle all of the platform incompatibility issues more gracefully.\n<\/li>\n<\/ol>\n<div class=\"aside\">To head off snarky comments suggesting a quite different solution, I <em>have<\/em> to use Outlook at work, so I <em>prefer<\/em> to use Outlook at home.<\/div>\n","protected":false},"excerpt":{"rendered":"<p>When read in Outlook, emails sent from WordPress are formatted poorly. I finally have a hypothesis to explain this behaviour.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_s2mail":"","footnotes":""},"categories":[32,25,34],"tags":[209,210,187,85],"class_list":["post-220","post","type-post","status-publish","format-standard","hentry","category-about-oddthinking","category-insufficiently-advanced-technology","category-software-development","tag-crcrlf","tag-outlook","tag-real-world-puzzle","tag-wordpress"],"_links":{"self":[{"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/posts\/220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/comments?post=220"}],"version-history":[{"count":0,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/posts\/220\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/media?parent=220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/categories?post=220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.somethinkodd.com\/oddthinking\/wp-json\/wp\/v2\/tags?post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}