Thanks zwon. Here is code to get html alternative if it is available, text otherwise, in case anyone can use it.

Steve

use Mail::POP3Client; use Email::MIME; my $pop = new Mail::POP3Client( USER => 'user@mail.com, PASSWORD => 'foobar', AUTH_MODE => 'PASS', HOST => "mail.com" ); for( my $i = 1; $i <= $pop->Count(); $i++ ) { my $message = $pop->HeadAndBody($i); my $parsed = Email::MIME->new($message); my ($body,$type) = getbody($parsed); # do something with body } sub getbody { my $parsedmessage = shift; my $body; my $bodytype; my @parts = $parsedmessage->parts; if ($messagetype =~ /^multipart\/alternative/) { # it's a plain alternative so get the html body in the second +part $body = $parts[1]->body; $bodytype = 'html'; } elsif ($messagetype =~ /^multipart\/[mixed|related]/) { # it's an alternative or related so check the first part my $subtype = $parts[0]->content_type; if ($subtype =~ /^multipart\/alternative/) { # it's an alternative with attachments so get the body fro +m the # second subpart of the first part my @subparts = $parts[0]->parts; $body = $subparts[1]->body; $bodytype = 'html'; } else { # otherwise it's plain text with an attachment so get the +body # from the first part $body = $parts[0]->body; $bodytype = 'text'; } } else { # it's plain text with no attachments so get the body # from the first part $body = $parts[0]->body; $bodytype = 'text'; } return ($body,$bodytype); }

In reply to Re^2: Email::MIME Distinguishing HTML msg from HTML attachment by cormanaz
in thread Email::MIME Distinguishing HTML msg from HTML attachment by cormanaz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.