How do webmail clients do it?
When I send myself an email with html content it does process that content first with htmlentities before displaying it (otherwise, besides showing it as html, it would also execute any javascripts etc.). But no matter when I view it as html or switch to plaintext view, the content is shown like I've sent it. E.g. when I view it as plaintext, any tags aren't converted to html entity values.