Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
XP is just a number
 
PerlMonks  

Mail Processing

by virtualweb (Sexton)
on May 29, 2011 at 14:06 UTC ( #907208=perlquestion: print w/ replies, xml ) Need Help??
virtualweb has asked for the wisdom of the Perl Monks concerning the following question:

Hello:

I have asked my server to redirect all email which come to a particular email box to a little perl script so I can automate sending an auto-reply according to keywords in the Subject or Body.

Now I need to write the script but I have no knowledge of how to parse the email To: From: Subject: and Body:

I looked in CPAN.org for clues and found two results:

1) a Module called Mail::Message
http://search.cpan.org/~markov/Mail-Box-2.098/lib/Mail/Message.pod

2) a directory of mail related modules
http://search.cpan.org/~markov/Mail-Box

If anyone has already parsed email messages I would appreciate directions, perhaps your've already used the above mentioned Modules or you may have a better a quicker solution.

Much appreciated

Comment on Mail Processing
Re: Mail Processing
by SimonClinch (Chaplain) on May 29, 2011 at 15:53 UTC
    Owing to the variations that can still exist in the format, please provide some example mails to parse. Be aware that you might also get multiple formats, attachments etc.

    One world, one people

Re: Mail Processing
by ig (Vicar) on May 29, 2011 at 19:28 UTC

    I have used MIME::Parser and would use it again. Many messages are multi-part MIME and the MIME::Tools set of modules makes it easy to compose them and extract their parts. The documentation might seem a bit overwhelming in the beginning, but what you need for basic parsing is usually quite simple.

Re: Mail Processing
by gnosti (Friar) on May 29, 2011 at 21:34 UTC
    Modules in the Mail::* hierarchy are known for being featureful and heavyweight. Email::Filter is part of the Email::* family of lighter, simpler modules launched by Simon Cozens and others. I use it for filtering mail I download with Net::IMAP::Client
Re: Mail Processing
by bliffle (Initiate) on May 30, 2011 at 18:44 UTC
    I would suggest using procmail instead of attempting to re-invent that wheel: http://partmaps.org/era/procmail/mini-faq.html
      FWIW, Mail::Audit, and its successor Email::Filter, were actually developed in reaction to procmail's unusual syntax. Being able to put perl code in my filtering rules is a winner for me.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://907208]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2014-04-23 18:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (551 votes), past polls