Stripping out MIME headers

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 let you create a new To Do item in Outlook Tasks, or a new diary entry in Outlook Calendar.

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.

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.


It worked okay, but there was one problem.

The API for getting the body out of the email gives you a stream to read from.

And what you (can) read from the stream is the MIME text of the email.

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’t really want.

A lot of it.

I’ve just been ignoring it. But it is annoying to have to scroll so far down to get to the actual email body – particularly on phones with smaller screens.

Tonight I decided to have a go at fixing this.

I’ve written what is possibly the world’s dumbest MIME-parser 🙂

It basically scans through the stream, assuming that if it sees a ‘:‘ character before any whitespace or newline, then the current line is a MIME-header.

And assumes that the first line where this is not true is the start of the email body.

The slightly fiddly bit was handling where some MIME header values are continued on to the following line.

A quick test on the emails in my inbox seems to suggest that it basically works.

Doesn’t this look much more useful?

However, it’s a fairly quick hack, so I’m guessing that it’ll probably falls over if it encounters some sequence of MIME header lines that I’ve not considered.


If you’d like to give it a try, the updated version is here.

Update (19-Aug-2009): I updated the code the following evening to:

  • Fix a bug which caused some Access Violation exceptions
  • Optimised the build to make the DLL a lot smaller
  • Add the extension as a menu item on opened emails as requested in the Comments

Update (20-Aug-2009): Another update – I added a first attempt at stripping out HTML tags. It basically removes anything from the body that is either <in-angle-brackets> or &between-and-ampersand-and-a-;

Update (21-Aug-2009): 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’s very small, so hopefully this wont pose a problem for anyone.

Tags: , , , ,

28 Responses to “Stripping out MIME headers”

  1. Saijo George says:

    Very handy app, thanks for it .

  2. Ben says:

    Hi Dale,

    Did you ever get chance to look at the issue of HTML emails and the request around using the context menu within and open email message as opposed to just the email list?

    Thanks

  3. dale says:

    @Ben – Thanks for your comment

    Did you ever get chance to look at the issue of HTML emails

    Not sure what you mean… do you mean have I done something similar to this to strip out HTML tags? If so, no… and it is a bit of an issue. Another reason why I curse people who send me HTML emails 😉

    …request around using the context menu within and open email message as opposed to just the email list?

    Nope, sorry. Did think about that last night, but by the time I’d finished mucking about with this MIME header stuff, it was pretty late. I might come back to it another evening, though.

    Kind regards,
    D

  4. dave says:

    great little app, agree with ben re html, also, option exists for sms but does not work, this would be a great enhancement

  5. dale says:

    @Ben – I’ve added the menu item to individual emails now. Whew, that was more complicated then I thought it’d be! 🙂

  6. dale says:

    @dave – I guess I could try and strip out everything in < angle brackets > …. I’ll give it a try sometime

  7. Kai Wang says:

    Check out the brief review on CareAce.net: http://bit.ly/21oyBi

  8. […] that said, let me introduce you to EmailTriage, from Dale Lane, a plugin for your Outlook that, according to Dale helps “triage the emails. The […]

  9. […] that said, let me introduce you to EmailTriage, from Dale Lane, a plugin for your Outlook that, according to Dale helps “triage the emails. The […]

  10. drjim says:

    Check out my review of your app here:

    http://tinyurl.com/mj57bj

  11. dale says:

    @Ben, @dave

    I’ve had a go at adding support for removing HTML tags.

    The parser now removes anything in angle brackets – such as or anything that looks like a special character code – such as &this;

  12. dale says:

    @Ben, @dave

    I’ve had a go at adding support for removing HTML tags.

    The parser now removes anything in angle brackets – such as <this>
    or anything that looks like a special character code – such as &this;

  13. Jiri says:

    Hi Dale.
    I installed your program, but i have one problem. When I will choose for example “Move to Tasks”, only subject of e-mail was copied (without text of e-mail). 🙁
    For example see picture on this website: http://www.palmserver.cz/modules.php?name=News&file=article&sid=4147
    What can happened?
    Thanks for reply, Jiri.

  14. dale says:

    @Jiri – Try the version at
    http://dalelane.co.uk/files/EmailTriageCab_WM6_debug.CAB

    It is much less efficient but it will create a file emailtriage.trace in the root directory of your phone. This file will contain diagnostics information that may help me identify what is going wrong.

    If you could email it to me at dale.lane[at]gmail.com I will take a look.

  15. Josh says:

    Doesn’t strip out enough MIME for me.

  16. dale says:

    @Josh – Sorry to hear you’ve had problems with it. As I said in my post, it was an evening’s work producing

    possibly the world’s dumbest MIME-parser

    🙂

    If you would like to let me know what it missed, I might be able to refine the parser to handle it.

    Kind regards

    Dale

  17. Lincolnmon says:

    Hi Dale,

    Just like to know in spite of all the flaws of the “ugly looking notes” for the task, it works exactly as it advertises.

    Thanks a lot for this great program that fills in a much needed niche in Windows Outlook Mobile.

  18. CHrisV says:

    OMG! I’ve been looking for exactly this plugin since I got my 1st WM phone – 3 phones ago. Why MS didn’t include this simple idea is completely beyond me… THANK YOU! (Thanks fuzemobility for pointing me here!)

  19. José Pires says:

    Excellent application! Thanks.

    But I wonder if it’ll be possible that, instead of opening “edit outlook tasks and calendar” will be opened other PIM (e.g., Pocket Informant).
    It’s easy and factible?

    Thanks.

    José

  20. dale says:

    @Jose – Many thanks for the kind comment. With regard to interacting with other PIMs, I don’t know. I’d need to know more about them and how they work. It’s not high on my list to look into, though.

  21. Darryl says:

    Dale,
    just wanted to say thanks for the pluggin. i have been looking for something exactly like this for years!

  22. Andy Davidson says:

    Hi Dale,

    Many thanks for this app – very useful.

    However, recently it has stopped working on my TyTn II for moving SMS’s to either Tasks or Calendar.

    It worked perfectly for a couple of weeks or so, but now, although it works fine for email, nothing happens when using it on SMS’s. The option is there but simply nothing happens when selecting it.

    Tried numerous uninstalls, soft resets and re-installs but to no avail. This all applies to the recent version that strips out the HTML coding etc.

    Nothing else has changed on my device in this time, no other software installs etc.

    Currently back on the original version, which is working on SMS’s, but all the HTML Tags show when using on email etc.

    Only thing I have not tried is a hard reset, but I would rather avoid that!

    Any other ideas how I could get the most recent version to work again?

    Thanks again,

    Andy.

  23. dale says:

    Andy – Sorry to hear you’re having trouble with it – certainly sounds like a very strange bug. If you would like to try http://dalelane.co.uk/files/EmailTriageCab_WM6_debug.CAB this should create an “emailtriage” log file in your root folder that might suggest the source of the problem?

  24. Andy Davidson says:

    Hi Dale, many thanks for the info on the debug version. I’ve tried it and compared the trace when using it on email (which works) and SMS (doesn’t work anymore!).

    Seems it doesn’t think that the SMS has a body. Tries to force a body but fails:

    DEBUG: email doesnt have a MIME body
    DEBUG: email doesnt have a body
    DEBUG: email doesnt have an HTML body
    DEBUG: forcing code into bHasBody
    DEBUG: trying to open PR_BODY
    DEBUG: trying to open PR_BODY_W
    DEBUG: trying to open PR_BODY_A
    DEBUG: trying to open PR_BODY_HTML_A
    DEBUG: trying to open PR_BODY_HTML_W
    DEBUG: trying to open PR_BODY_HTML
    DEBUG: trying to open PR_CE_MIME_TEXT
    DEBUG: failed all BODY property types
    DEBUG: failed to get body text
    DEBUG: building new Outlook item
    DEBUG: calculated l1
    20
    DEBUG: calculated l2
    2
    DEBUG: calculated l3
    20

    Trace file ends at this point.

    The older version’s working fine on SMS’S and I’ve got used to the in emails – using that version fine. Any ideas are most welcome – it’s very much appreciated.

    Many thanks,

    Andy.

  25. Eric says:

    I’m really disapointed cos’ your great plugin seems no more working under 6.5

    The install is ok, but nothing appear in the context menu.

    Any solution ?

  26. dale says:

    Eric – Do you mean it was working on WinMob 6.5 but isn’t any more? Or that it’s not working since you upgraded to Win Mob 6.5?

  27. Eric says:

    Hi Dale,

    It doesn’t work since I upgraded to WinMob 6.5