Yes, I just tried that. I was successful. This seems like a hack to me but it works. Here is the completed script:

#!/usr/bin/perl -w use strict; use warnings; use MIME::Parser; use MIME::Entity; use MIME::Body; my (@body, $i, $subentity); my $parser = new MIME::Parser; my $to; #contains the message to header my $from; #contains the message from header my $subject; #contains the message subject heaer my $body; #contains the message body $parser->ignore_errors(1); $parser->output_to_core(1); my $entity = $parser->parse(\*STDIN); my $error = ($@ || $parser->last_error); #get email headers my $header = $entity->head; $subject = $header->get('Subject'); $to = $header->get('To'); $from = $header->get('From'); chomp($subject); chomp($to); chomp($from); #get email body if ($entity->parts > 0){ for ($i=0; $i<$entity->parts; $i++){ $subentity = $entity->parts($i); if (($subentity->mime_type =~ m/text\/html/i) || ($subentity-> +mime_type =~ m/text\/plain/i)){ $body = join "", @{$subentity->body}; } #this elsif is needed for Outlook's #nasty multipart/alternative messages elsif ($subentity->mime_type =~ m/multipart\/alternative/i){ $body = join "", @{$subentity->body}; #split html and text parts @body = split /------=_NextPart_\S*\n/, $body; #assign the first part of the message, #hopefully the text part, as the body $body = $body[1]; #remove leading headers from body $body =~ s/^Content-Type.*Content-Transfer-Encoding.*?\n+/ +/is } } } else { $body = join "", @{$entity->body}; } #body may contain html tags. they will be stripped here $body =~ s/(<br>)|(<p>)/\n/gi; #create new lines $body =~ s/<.+\n*.*?>//g; #remove all <> html tages $body =~ s/(\n|\r|(\n\r)|(\r\n)){3,}//g; #remove any extra new lines $body =~ s/\&nbsp;//g; #remove html &nbsp characters #remove trailing whitespace from body $body =~ s/\s*\n+$//s; open MAIL, ("|/usr/sbin/sendmail -t") || die "Unable to send mail: $!" +; print MAIL "To: $from\n"; print MAIL "From: root\n"; print MAIL "Subject: mime parser test\n\n"; print MAIL "Messege was contructed as follows: \$from: $from \$to: $to \$subject: $subject \$body: $body"; close(MAIL);

Neil Watson
watson-wilson.ca


In reply to Re: Re: MIME::Parser and mail from MS Outlook by neilwatson
in thread MIME::Parser and mail from MS Outlook by neilwatson

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.