I used Email::MIME, which no one has yet mentioned, to take emails I send from my mobile phone and turn them into Web posts, with plain text and/or JPEG photo. Here is a modified untested version of that code which may suit you purposes:
my $parsed = Email::MIME->new($message) or die "Could not parse email +message: $!"; #$message is full text of entire email m\ essage foreach my $part ($parsed->parts) { if ($part->content_type =~ /text\/plain/i) { #You have a plain text part #Do stuff here with $part->body } elsif ($part->content_type =~ /image\/jpeg/i) { #You have a JPEG part #in $part->body } elsif ($part->content_type =~ /text\/html/i) { #You have an HTML part #in part body my $html = $part->body; my $plain_text; my $parsed_text = HTML::TokeParser->new(\$html) or die "Cannot rea +d message text for parsing and cleaning: $!"; while (my $token = $parsed_text->get_token) { if ($token->[0] eq 'T') { # text $plain_text .= $token->[1]; } } #Do stuff with $plain_text extracted from HTML here } }
Notice the HTML::TokeParser part inside the HTML section. You'll only want to use that if the plain text part is unavailable to you. HTH.
In reply to Re: Extracting TEXT from email
by Anonymous Monk
in thread Extracting TEXT from email
by ady
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |