#!/usr/bin/perl use Email::MIME; $file = shift; $which = shift; ############################## # $which is: # text = plain text portion # html = html portion ############################## local( $/, *FILE ) ; open(FILE, $file); $message = ; close(FILE); my $parsed = Email::MIME->new($message); if ($parsed->content_type =~ m{^multipart/alternative}) { print get_text_parts($parsed)->body; } sub get_text_parts { my @parts = shift->parts; my %ct; $ct{$_->content_type} = $_ for @parts; return $ct{'text/plain'} if exists $ct{'text/plain'}; return $ct{'text/html'} if exists $ct{'text/html'}; return $parts[0] if $which =~ /text/; return $parts[1] if $which =~ /html/; } #### Content-Type: multipart/alternative; boundary="_000_200907060005UAA14932pisas291mscom88clm_" MIME-Version: 1.0 --_000_200907060005UAA14932pisas291mscom88clm_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable line1 line2 line3 --_000_200907060005UAA14932pisas291mscom88clm_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable

blah

blah2

--_000_200907060005UAA14932pisas291mscom88clm_-- --_004_38D25DCAD7370B4FACA079E2FAA2C690B02CB5NYWEXMB24msadmsco_-- ##
## $ ./grab.pl mime4 text line1 line2 line3 $ ./grab.pl mime4 html

blah

blah2

$