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

I have done some searching on CPAN but I am not finding a good module for parsing incoming mail into its parts. I thought Email::Simple with Email::MIME would do the trick but the body of a mail message sent from Outlook gets parsed as "This is a multi-part message in MIME format" (and the documentation states the "body" method will most likely return that, amazingly).

Any recommendations?
Thanks!
Rod

Replies are listed 'Best First'.
Re: Parsing Incoming Mail
by Corion (Patriarch) on Dec 30, 2008 at 17:15 UTC

    Have you looked at MIME::Parser? It's quite heavyweight, but it will parse a MIME message into its parts, which seems to be what your message is.

      Looking at it now. I also saw this thread about Mail::Message. This is not the first time I have been here, but I am a little surprised how difficult mail handling still is. Many of the modules available on CPAN don't seem to be in a fully developed state (at least the ones I have looked at). It seems the Internet has been around long enought that we would have this part down by now ;) Looking at the reviews on CPAN for Mail::Message and MIME::Parser many are complaining about the overhead of these modules and more than once I have seen people saying they have just resorted to writing their own parser.

        That's probably a case of the common case vs. technically correct. ~95% of the time, a fairly simple parser will get you all of the parts of an email message. The rest of the time consists of obscure edge-cases, weird nesting rules, and never-seen formats. Much of the time in particular contexts you can get away with ignoring all of that detail and just handling the 'standard' cases.

Re: Parsing Incoming Mail
by sflitman (Hermit) on Dec 31, 2008 at 06:53 UTC
    MIME::Tools has saved me on many occasions. It isn't hard to use, and the overhead is worth it for handling the vagaries of MIME-formatted emails, especially ones with nested attachments. I process SpamAssassin-filtered mail which can have attached RFC-822 messages which themselves contain attachments. Don't write your own parser, the whole point of CPAN is leverage what the community provides you.

    HTH, SSF

      Just to wrap up this thread, I did end up using MIME::Tools and everything is working nicely. It wasn't bad at all once I got into it. I've tested with a few user agents and so for so good. It is a heavyweight but what can I say, email is heavyweight. And yes, I agree with you sflitman, CPAN is a friend which I wholly embrace.