For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > May 2004 > Parse a MIME E-Mail









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Parse a MIME E-Mail
Christian Gersch

2004-05-19, 11:31 pm

Hi,

I have some troubles with the MIME::Parser module. I have saved a MIME
message in a variable. Now I need to extract the plain text.

$entity = $parser->parse_data($message);

What code do I have to use to get the plain text?

Thanks a lot,
-Chris
Malcolm Dew-Jones

2004-05-20, 2:31 am

Christian Gersch (gersch.news19@iways.de) wrote:
: Hi,

: I have some troubles with the MIME::Parser module. I have saved a MIME
: message in a variable. Now I need to extract the plain text.

: $entity = $parser->parse_data($message);

: What code do I have to use to get the plain text?


perldoc MIME::Entity

further down, "Access examples"

various methods mentioned, $ent->mime_type looks useful for choosing the
right entity.





For my own mental excersize, this is how using MIME::Xparser, this
example does not decode the data, just find it.


#!/usr/bin/perl
use strict;

use MIME::Xparser;

package handler;

sub AUTOLOAD {}
sub new { bless \ my $plain , shift }

sub header
{
my $plain = shift;
my $header = shift;

if ( $header =~ m/^Content-Type:\s*text\/plain\b/is )
{ $$plain=1;
}
}

sub end_body { my $plain = shift; $$plain=0;}

sub body
{
my $plain = shift;
my $line = shift;
print $line if $$plain;
}


package main;


my $parser = new MIME::Xparser(new handler);
$parser->start_document();

while (<> )
{
$parser->line($_);

}
$parser->end_document();



--

(Paying) telecommute programming projects wanted. Simply reply to this.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com