Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Reading Mail::Message objects using Mail::POP3Client

by TheHobbit (Pilgrim)
on Oct 13, 2002 at 17:26 UTC ( [id://204920]=perlquestion: print w/replies, xml ) Need Help??

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

wise Monks,
After some month away from the monastery, I'm back with a maybe interesting question.

I'm developping a little application, one component of wich needs to download some mail messages from a POP3 account and do something with them according to data such as the From: address, the Subject header and (obviously) the contents.

I got this idea to use Mail::POP3Client for doing the download, and it works fine. But now I do not want to reinvent the wheel just another time, so I though to use the Mail::Message class to do the parsing for me.

Well, I'm unable to find a clean way to transform the string obtained by the HeadAndbody method of the Mail::POP3Client into a Mail::Message object (actually a subclass of it I defined).

So here comes the question. Am I too a blockhead to find how to do that, or realy this operation is so difficult?

Subsidiary question is: is there another way to parse a string conatining a mail message into some kind of structure allowing easy access to the different parts of the message?

Thank you and may your regex only match when they have to.


Leo TheHobbit

Replies are listed 'Best First'.
Re: Reading Mail::Message objects using Mail::POP3Client
by dws (Chancellor) on Oct 13, 2002 at 17:34 UTC
    I got this idea to use Mail::POP3Client for doing the download, and it works fine. But now I do not want to reinvent the wheel just another time, so I though to use the Mail::Message class to do the parsing for me.

    If (or when) you start dealing with attachements, you might find that Mail::Message isn't sufficient. I recommend getting a copy of Lincon Stein's Network Programming with Perl. Chapter 8 gives a working example of dealing with MIME-encoded messages (of which non-encoded messages are a trivial subset) using MIME::Parser.

Re: Reading Mail::Message objects using Mail::POP3Client
by jlongino (Parson) on Oct 13, 2002 at 18:59 UTC
    As dws says for attachment processing mime::parser is ideal. Here is an example of Mail::POP3Client access and MIME::Parser for parsing.

    As for determining the pure text portion of the message, I've found that Mail::MboxParser is usually the easiest way to obtain it. Here is an example how to obtain the "text message" portion, if the E-mail contains one.

    --Jim

Re: Reading Mail::Message objects using Mail::POP3Client
by true (Pilgrim) on Oct 14, 2002 at 01:59 UTC
    I did it the hard way and wrote my own parser. It's really fat (not phat in a good way) and still has some problems. Namely, really large attachments can bog it down. I had to add a kill statement incase a user wasn't patient. Plus i needed a subroutine for every attachment type too. Still not done, always adding file types i never heard of. If you brave the rapids, it was a good exercise for me avec decoding/encoding/parsing.

    Source code found at: http://perl.to/lib/webmailcgi.txt

    For runnning on a webserver, put it in a folder on your website with suexec enabled. The webmail.cgi program builds the folder structure needed to run.

    Edit by dws to fix formatting

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-23 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found