Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mail Body Issues.

Status
Not open for further replies.

tar565

Programmer
Jan 24, 2005
39
0
0
IE
Hi, I am trying to parse a mail to get the body of a mail in the simplist way possible. I have tried Email::Simple but a hmtl tags are returned when I parse the mail which is no good.

I have managed to get the body with no tags using MIME::parser BUT I am having a few issues with it:

(Note : $local_FileString contains the contents read from a .msg file.)

When a parse the filestring a number of files are returned, usually a .txt and .html version of the body. How can I control the output better with the module. I dont understand how 2 files are created in parsing.

Can anyone suggest a better way of getting the body of a mail without the html tags.

Here is the parsing code :

my $mail = Email::Simple->new($local_FileString);
my $parser = new MIME::parser;
my $entity = $parser->parse_data(\$local_FileString) or die "Parse failed\n";





 
I usually process emails like this
Code:
my $parser = new MIME::Parser
    or die "$0: Cannot create parser object: $!";
$parser->output_under( '/var/spool/$0' );
my $entity = $parser->parse( \*STDIN ) or die "parse failed";

# get the name of the directory that holds the parts of this message
my $dir = $parser->output_dir();

# loop through the mime parts (attachments).
if ($entity->is_multipart()) {
    foreach my $part ( $entity->parts() ) {
        my $path = $part->bodyhandle->path();
        last if process( $path );
    }
} else { # $entity is not multi-part
        die "expected an attachment in $dir";
}

"As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs."
--Maurice Wilkes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top