{"id":878,"date":"2009-08-18T22:42:53","date_gmt":"2009-08-18T22:42:53","guid":{"rendered":"http:\/\/dalelane.co.uk\/blog\/?p=878"},"modified":"2009-08-21T16:36:01","modified_gmt":"2009-08-21T16:36:01","slug":"stripping-out-mime-headers","status":"publish","type":"post","link":"https:\/\/dalelane.co.uk\/blog\/?p=878","title":{"rendered":"Stripping out MIME headers"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/i267.photobucket.com\/albums\/ii311\/dale_lane\/090818-triage0.gif\" align=\"right\" hspace=\"10\" vspace=\"10\" style=\"border: thin black solid\"\/>A <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=188\">couple of years ago<\/a>, I wrote a small <a href=\"http:\/\/dalelane.co.uk\/page.php?id=1043\">plugin for Outlook Mobile<\/a> (the version of Outlook that you get on Windows Mobile phones) to help me triage my emails.<\/p>\n<p>The idea was to make it quicker to <a target=\"_blank\" href=\"http:\/\/www.43folders.com\/2006\/03\/27\/process-to-zero\/\">process my email<\/a> from my phone, by adding a couple of context menu items to emails that let you create a new To Do item in Outlook Tasks, or a new diary entry in Outlook Calendar. <\/p>\n<p>So if someone sends you an email asking you to do something, with one tap you can create a new To Do list item, pre-filling it with information from the email. <\/p>\n<p>And if someone sends you an email about an event or meeting you need to go to, with one tap you can create a new Calendar item, prefilling it with information from the email. <\/p>\n<p><!--more--><br clear=\"all\"\/><img decoding=\"async\" src=\"http:\/\/i267.photobucket.com\/albums\/ii311\/dale_lane\/090818-triage1.gif\" align=\"left\" hspace=\"10\" vspace=\"10\" style=\"border: thin black solid\"\/>It worked okay, but there was one problem.<\/p>\n<p>The <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=188\">API for getting the body out of the email<\/a> gives you a stream to read from. <\/p>\n<p>And what you (can) read from the stream is the <a href=\"http:\/\/en.wikipedia.org\/wiki\/MIME\" target=\"_blank\">MIME<\/a> text of the email. <\/p>\n<p>Which meant that while I did get the body of the email in my new Task or Calendar items, I also got a ton of MIME header junk that I didn&#8217;t really want. <\/p>\n<p>A lot of it.<br \/>\n<br clear=\"all\"\/><img decoding=\"async\" src=\"http:\/\/i267.photobucket.com\/albums\/ii311\/dale_lane\/090818-triage2.gif\" align=\"right\" hspace=\"10\" vspace=\"10\" style=\"border: thin black solid\"\/>I&#8217;ve just been ignoring it. But it is annoying to have to scroll so far down to get to the actual email body &#8211; particularly on phones with smaller screens. <\/p>\n<p>Tonight I decided to have a go at fixing this.<\/p>\n<p>I&#8217;ve written what is possibly the world&#8217;s dumbest MIME-parser \ud83d\ude42 <\/p>\n<p>It basically scans through the stream, assuming that if it sees a &#8216;<code>:<\/code>&#8216; character before any whitespace or newline, then the current line is a MIME-header. <\/p>\n<p>And assumes that the first line where this is not true is the start of the email body. <\/p>\n<p>The slightly fiddly bit was handling where some MIME header values are continued on to the following line.<br \/>\n<br clear=\"all\"\/><img decoding=\"async\" src=\"http:\/\/i267.photobucket.com\/albums\/ii311\/dale_lane\/090818-triage3.gif\" align=\"left\" hspace=\"10\" vspace=\"10\" style=\"border: thin black solid\"\/>A quick test on the emails in my inbox seems to suggest that it basically works. <\/p>\n<p>Doesn&#8217;t this look much more useful?<\/p>\n<p>However, it&#8217;s a fairly quick hack, so I&#8217;m guessing that it&#8217;ll probably falls over if it encounters some sequence of MIME header lines that I&#8217;ve not considered.  <\/p>\n<p><br clear=\"all\"\/>If you&#8217;d like to give it a try, the <a href=\"http:\/\/dalelane.co.uk\/files\/EmailTriageCab_WM6.CAB\">updated version is here<\/a>.<\/p>\n<p><strong>Update (19-Aug-2009):<\/strong> I updated the code the following evening to:<\/p>\n<ul>\n<li>Fix a bug which caused some Access Violation exceptions\n<\/li>\n<li>Optimised the build to make the DLL a lot smaller\n<\/li>\n<li>Add the extension as a menu item on opened emails as requested in the Comments <\/li>\n<\/ul>\n<p><strong>Update (20-Aug-2009):<\/strong> Another update &#8211; I added a first attempt at stripping out HTML tags. It basically removes anything from the body that is either &lt;in-angle-brackets&gt; or &amp;between-and-ampersand-and-a-;<\/p>\n<p><strong>Update (21-Aug-2009):<\/strong> One user reported a problem if they installed it to their Storage Card. The extension needs to be installed to main memory to work. It&#8217;s very small, so hopefully this wont pose a problem for anyone.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A couple of years ago, I wrote a small plugin for Outlook Mobile (the version of Outlook that you get on Windows Mobile phones) to help me triage my emails. The idea was to make it quicker to process my email from my phone, by adding a couple of context menu items to emails that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[408,409,411,410,19],"class_list":["post-878","post","type-post","status-publish","format-standard","hentry","category-code","tag-mapi","tag-mime","tag-poutlook","tag-pr_body","tag-windows-mobile"],"_links":{"self":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/878","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=878"}],"version-history":[{"count":0,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/878\/revisions"}],"wp:attachment":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=878"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=878"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=878"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}