Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Parsing email

by jeteve (Pilgrim)
on Jan 24, 2008 at 17:32 UTC ( [id://664093]=perlquestion: print w/replies, xml ) Need Help??

jeteve has asked for the wisdom of the Perl Monks concerning the following question:

Hi Fellow monks,

I'm wondering what's the best way or what's the best module to parse an email and get the decoded data in pure perl strings.

For instance, I'd love to parse something like that:

+ + + Received: by 10.115.106.19 with HTTP; Thu, 24 Jan 2008 09:10:50 -0800 +(PST) Message-ID: <f516fcd80801240910j797b0e09h26cbafede672403f@mail.gmail.c +om> Date: Thu, 24 Jan 2008 17:10:50 +0000 From: "=?UTF-8?Q?J=C3=A9r=C3=B4me_Et=C3=A9v=C3=A9?=" <jerome@eteve.net +> Sender: jerome.eteve@gmail.com To: "Jerome Eteve" <jerome@careerjet.com> Subject: =?UTF-8?B?2LbYsdix2Ykg2LfZiNmC2YjZhtmF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: base64 Content-Disposition: inline Delivered-To: jerome.eteve@gmail.com X-Google-Sender-Auth: b14660e8948ad477 2LbYsdix2Ykg2LfZiNmC2YjZhtmFamlkamkgagoKZGppd29qZCB3b3dvd29vd293CgotLS +AKSmVy b21lIEV0ZXZlLgoKU3BlYWsgdG8gbWUgbGl2ZSBhdCBodHRwOi8vd3d3LmV0ZXZlLm5ldA +oKamVy b21lQGV0ZXZlLm5ldAo=

And then be able to do:

my $mail = MagicMailModule->parse($data) ; my $to = $mail->To() ; my $from = $mail->From() ; my $body = $mail->Body() ;

Do you have an idea of what I could use ?

Thanks for any help !!

-- Nice photos of naked perl sources here !

Replies are listed 'Best First'.
Re: Parsing email
by jettero (Monsignor) on Jan 24, 2008 at 17:41 UTC

    The very best way is: Mail::Message->new( $your_message_from_664_093 );   (update: not even close)

    It does everything you want and much more.

    my $body = $msg->body; my @encoded = $msg->body->lines; my @to = $msg->to; my @from = $msg->from;

    -Paul

      This does not appear to work and I see no way it ever could have.
        You're right. I don't know what I was thinking... it was quite a while ago, but it's clear I didn't try it. In fact, I just spent like 10 minutes trying to figure out how to fix it and I gave up (apathy mostly). What surprises me most about this, cuz I do all sorts of dumb things to be honest, is how many people clicked ++ on it thinking I was right.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://664093]
Approved by kyle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-18 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found