I mentioned ages ago about a little extension I wrote for my phone that lets me dump the contents of an email that I receive into any other bit of Pocket Outlook – turning an email about an event into a Calendar item, or an email asking me to do something into a Task item – with a single click.
I recently noticed a problem with it, and finally got around to looking into it tonight. The problem was that sometimes the body of the email wouldn’t make it to the new Calendar or Task item. Everything else, like the subject and the sender’s name would be fine, but the body of the new item would be blank.
To start with a little background, on Windows Mobile 5 Pocket Outlook’s Email lets you have multiple accounts. One of these is “Outlook E-mail” which is synced with your desktop Outlook Inbox. The others are POP3 or IMAP accounts for sending and receiving emails on the move. I mainly use the “Outlook E-mail” account so that I can process my email when I get a spare few minutes away from my desk.
(As an aside, this is part of my GTD implementation, and something which I would strongly recommend – see 43 folders for a wealth of information on the approach. But basically, the idea is to process (without necessarily “doing”) your emails, rather than leaving them sitting in your Inbox.)
The clue to my problem (and why it has taken me so long to spot it) was that it was happening only with emails in the POP3 accounts. Emails from the Outlook and Text Message accounts are copied fine – body text and all. But POP3 emails have every field copied across into the new item with no problems – except for the body.
After a bit of digging, it turns out that the answer is in how the emails make their way to the PDA. Getting the body text of a message downloaded from my PC via ActiveSync is different than gettting the body text using POP3 (or IMAP, presumably). And as a result, it is stored differently. The property I use to programmatically get the body text out of the email is PR_BODY…
hr = pMsg->OpenProperty(PR_BODY, NULL, 0, GENERIC_READ, (LPUNKNOWN*)&pStmBody);
This property is filled in by ActiveSync when it copies across the email body to the PDA. But when messages are downloaded by POP3 or IMAP the contents are put somewhere else – into PR_CE_MIME_TEXT.
Annoyingly, the fix isn’t going to be as simple as just accessing that property though. PR_CE_MIME_TEXT contains the email, downloaded in MIME format. As far as I can tell, it is up to the application to decode the MIME data into something more friendly, and get the Body out. Even though Outlook must have that functionality to be able to show emails itself, they don’t seem to have exposed that in the API.
Apologies for the unashamedly geeky post, but it’s nearly midnight and after fighting with this for ages I felt the need to moan about it to someone! Will have to have another fight with this later – there’s gotta be an easier way! 🙂
Update: Even more confusing… in Windows Mobile 6, you don’t even use PR_BODY – the move to HTML emails seems to mean that you need to use PR_BODY_HTML_A
Fun(!)