I'm reading email from a pop server and logging it into a tracking system. Since the email is coming from users, it can be plain text, or HTML, or a mix. All I'd like to do is extract the plain text.
If it is a mime-encoded message, just stripping HTML means that I can wind up with two copies of the message (plain text section + filtered HTML section) plus some mime-boundary stuff, so that doesn't seem like the best way to go.
I'm guessing that I need to look at the email, decide if it's mime encoded, and then see if there is a plain text section. So there's three cases (?) of emails:
1) Not Mime, so no decoding needed, just read msg body
2) Mime-encoded with plain text section -> extract plain text section
3) Mime-encoded, no plain text section, just HTML -> decode the HTML
Seems like a fair amount of effort, so I wondered if someone else has solved this in better way. I didn't see anything in CPAN that would be a complete solution (ie, nothing entitled Mail::ReadAnythingAndExtractPlainText)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.