{"id":188,"date":"2007-09-13T20:44:41","date_gmt":"2007-09-13T20:44:41","guid":{"rendered":"http:\/\/dalelane.co.uk\/blog\/?p=188"},"modified":"2007-09-28T09:44:30","modified_gmt":"2007-09-28T09:44:30","slug":"process-your-emails-an-outlook-plugin","status":"publish","type":"post","link":"https:\/\/dalelane.co.uk\/blog\/?p=188","title":{"rendered":"Process your emails &#8211; an Outlook plugin"},"content":{"rendered":"<p><img decoding=\"async\" src=\"post-images\/061112-emailtriage.gif\" align=\"left\" hspace=\"10\" vspace=\"5\" \/>I got a nice email last week from someone asking why I never made the <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=54\">&#8220;triage&#8221; Outlook plugin<\/a> I mentioned last year available as I have with other <a href=\"http:\/\/dalelane.co.uk\/software\/\">bits of code<\/a>. The short answer was obviously because I never got round to finishing it! \ud83d\ude42 <\/p>\n<p>However, the idea feels a bit more topical at the moment so I think it is worth revisiting. <\/p>\n<p>The aim was to create something that would let me process my emails in Outlook Mobile (the cut-down version of Outlook you get on Windows Mobile PDAs and smartphones). <\/p>\n<p><a href=\"http:\/\/www.43folders.com\/2006\/03\/27\/process-to-zero\/\">&#8220;Processing&#8221;<\/a>, rather than doing emails is an idea that I hear people mention more often since <a href=\"http:\/\/www.43folders.com\/2007\/07\/25\/merlins-inbox-zero-talk\/\">Merlin Mann&#8217;s brilliant Inbox Zero talk<\/a> started doing the rounds as a Google video. I&#8217;m even hearing other people <a href=\"http:\/\/twitter.com\/rooreynolds\/statuses\/265455592\">use it as a phrase<\/a> from time to time! I used to call it &#8220;triaging&#8221; my email, but I think &#8220;processing&#8221; is actually a better term. Either way, the idea is that I want to be able to go through my inbox as quickly as possible &#8211; doing something with each one so that I can finish up with an empty inbox. <\/p>\n<p><a href=\"http:\/\/www.43folders.com\/izero\/\" target=\"_blank\"><img decoding=\"async\" alt=\"Inbox Zero\" src=\"post-images\/inboxzero.jpg\" align=\"right\" hspace=\"5\" vspace=\"5\"\/><\/a>It doesn&#8217;t mean doing everything right away &#8211; just putting the information in it&#8217;s right place. If it&#8217;s an email asking me to do something, the right place for the email is in my Task List, not my Inbox. If it&#8217;s an email telling me about a meeting or appointment, then the right place for the email is in my Calendar. If it&#8217;s an email containing information that I need to keep for future reference, then the right place for it is in my <a href=\"http:\/\/dale.lane.googlepages.com\/\">wiki<\/a>. <\/p>\n<p>Mobile phones seem like an ideal tool for processing email, as it&#8217;s something that you can do when you have a few spare minutes and without having to do a lot of text entry or other input. Rather rely on manual (and slow!) copy-and-pasting, I wanted Outlook Mobile to be able to move my emails around like this for me. This was the idea of the plugin&#8230;<\/p>\n<p>If you are interested in the pain of writing MAPI plugins in C++, read on. If you are&#8230; erm&#8230; normal &#8211; then the short version is that I tidied up the code and <a href=\"http:\/\/dalelane.co.uk\/page.php?id=1043\">made it available<\/a>. <\/p>\n<p><!--more-->As I mentioned when I originally wrote the plugin, the idea was to <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=54\">use IContextMenu to add new menu items to Outlook&#8217;s context menu<\/a>. Once you&#8217;ve got that bit working, most of it is pretty straightforward. The only other tricky bit is writing the MAPI code to get the information you want out of the email. <\/p>\n<p>There is a nice intro to <a href=\"http:\/\/blogs.msdn.com\/windowsmobile\/archive\/2007\/03\/21\/getting-started-with-mapi.aspx\">Getting Started with MAPI<\/a> on the Windows Mobile Team Blog (<em>annoyingly written about five months after I spent a few nights trying to get my head around it with virtually no doc! \ud83d\ude42<\/em>), which tells you how to get simple short values out of emails using MAPI &#8211; like the date\/time an email was sent. <\/p>\n<p>Getting longer properties &#8211; like the body of the email &#8211; is more complicated, and isn&#8217;t something that was covered in the blog post. It was <a href=\"http:\/\/blogs.msdn.com\/windowsmobile\/archive\/2007\/03\/21\/getting-started-with-mapi.aspx#1961082\">asked for a few times in the comments<\/a> so I&#8217;ve copied a simplified snippet of code below in case it is helpful to people.<\/p>\n<pre style=\"overflow-x: scroll; font-size: 1.2em; background-color: #eeeeee; border: 1px solid #666666; padding: 3px;\">\/\/ starting with pMsg - an IMessage, as it's fairly straightforward \r\n\/\/   to get to that bit\r\n\r\n\/\/ need a different method to get larger properties, like the email body\r\nLPSTREAM        pStmBody    = NULL;\r\nSTATSTG         statstg     = {0};\r\nDWORD           cbRead      = 0;\r\n\r\n\/\/ open a stream that we will use to get the email body\r\npMsg-&gt;OpenProperty(PR_CE_MIME_TEXT, \r\n                   &amp;IID_IStream, \r\n                   STGM_READ, \r\n                   NULL, \r\n                   (LPUNKNOWN*)&amp;pStmBody);\r\n\r\n\/\/ we successfully opened the stream\r\n\/\/ before getting data out of it, we use stat to ask how\r\n\/\/  much space we will need\r\nmemset(&amp;statstg, 0, sizeof(statstg));\r\npStmBody-&gt;Stat(&amp;statstg, STATFLAG_NONAME);\r\n\r\nint msgsize = statstg.cbSize.LowPart + 1;\r\n\r\n\/\/ allocate space in the string's used to store the body\r\nchar* szEmailBody = (char*)malloc(sizeof(char) * msgsize);\r\n\r\n\/\/ read data from the stream into our char array\r\nhr = pStmBody-&gt;Read((void*)szEmailBody, msgsize, &amp;cbRead);\r\n\r\n\/\/ finished with the stream\r\npStmBody-&gt;Release();<\/pre>\n<p>As I&#8217;ve <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=112\">mentioned before<\/a>, when you get the <code>PR_CE_MIME_TEXT<\/code> contents of a mail from a POP3 account, you get the MIME version of the email. It&#8217;s still readable, you just get a bunch of headers at the top. It&#8217;s a pain, but not bad enough that I&#8217;ve ever been bothered to write the code to clean that bit off the top. \ud83d\ude42<\/p>\n<p>With the Outlook account, the MIME headers aren&#8217;t included when the emails are transferred from your computer by ActiveSync, so when you get the <code>PR_CE_MIME_TEXT<\/code> contents, it&#8217;s just the body. <\/p>\n<p>With the SMS Text Messages account, the whole message is in the <code>PR_SUBJECT<\/code> property, so you don&#8217;t have to bother with the whole streams bit at all!<\/p>\n<p>And there we go&#8230; few nice extra options to help get through your email a bit quicker. The code probably needs a bit more work and there might be a small memory leak or two hiding in there, but it seems to more-or-less do the trick for now. \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I got a nice email last week from someone asking why I never made the &#8220;triage&#8221; Outlook plugin I mentioned last year available as I have with other bits of code. The short answer was obviously because I never got round to finishing it! \ud83d\ude42 However, the idea feels a bit more topical at the [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-188","post","type-post","status-publish","format-standard","hentry","category-code"],"_links":{"self":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/188","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\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=188"}],"version-history":[{"count":0,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/188\/revisions"}],"wp:attachment":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}