简体   繁体   中英

Convert HTML to Plain Text?

I am able to read emails in from Microsoft Exchange using an IMAP Client from Lumisoft. I have set the exchange server settings to convert any mail to plain text. However, when I read in the information it still seems to contain HTML/CSS.

What is the best way of removing HTML/CSS from the body of an email? Or is there a setting on the exchange server I seemed to have missed?

I usually take one of these approaches...

  1. Using regular expressions. It can be a bit difficult to get right if you have to come up with a solution that also works with all kinds of invalid markup, but i bet someone else has done it before you (Hint: google or search SO).

  2. Using an HTML parser library. You can find one for any popular programming language out there. I recommend using the Html Agility Pack.

I'm not sure of exactly how your setup works, if you can run scripts, etc. An HTML parser would be the best way to parse the HTML, obviously. For instance, with Hpricot (a Ruby HTML-parsing library), you could do puts doc.find_element('body').inner_text and that would print the text content of the document.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM