in reply to html to e-mail

It depends on the format that you encode it with. If you just print the raw data to sendmail it will be a plain text email.

However, why not take a break from the wheel rewriting and look at the nms formail? It does what you have described and I'm sure you can tweak the look of it to suit.