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

I'm looking for some help in parsing the mail files, ala /var/spool/mail/root for bounced e-mail addresses to build a list from to help in cleaning out dead e-mails from our notification lists. I figured someone had done this before and went seaking the net via google for ages to find nothing, anyone here have anything of this type or any modules for parsing the entire thing? Thanks. Bob
  • Comment on Email Parsing of mail files for e-mail errors

Replies are listed 'Best First'.
Re: Email Parsing of mail files for e-mail errors
by atcroft (Abbot) on Dec 03, 2002 at 14:23 UTC

    Your post interested me. A few thoughts, if i may, that I hope will repay the interest by at least giving you a place to bounce from.

    First of all, if you have to code this yourself, take a look at the Mail::* modules, which should help somewhat in reducing the amount of custom code you have to write.

    Next, if you are not already doing so, I would, if possible, create a user that the mailing list was sent as, or if possible, set a custom header in the message (several mailing lists I am on set a Return-Path header, or something similar, with a value related to my subscription to the list). Using this, you could use one of the filtering/sorting mechanisms available as part of several of the Mail::* modules (mentioned above) to act based on seeing that header in a message to either the user the mailing list sent as (root or another).

    Hope that helps, and hope others will also contribute useful ideas to you as well.

      FYI, "Reply-To" Munging Considered Harmful. I don't administer a mail server, and I haven't read widely on this, but this article makes sense to me.

      . . .

      Maybe I should have started this node like Rod Serling, 'Submitted for your consideration, a mail list adminstrator who munges his headers. But this is no ordinary tale, these headers are being sent from ... The Twilight Zone.' Nah, guess not.

        I read it as you suggested and we don't really want to start munging, I'd like a more universal solution if possible to catch all system errors.
      The problem is, we want to do a more global system, as we have tons of utilities sending out mail and all the bounced mail is landing in root, they have tons of old mail backed up. I'd like to build both a retroactive and a proactive solution but having problems doing so as nobodys mail server seems to be returning consistently formatted errors. I'm looking into the idea of seeing if sendmail can remote connect and validate but not having much luck. Someone suggested:
      /usr/lib/sendmail -oeq -bv the@email.com; echo $status
      but not returning much of anything useful :(
Re: Email Parsing of mail files for e-mail errors
by iburrell (Chaplain) on Dec 03, 2002 at 17:52 UTC
    If you want to process mail error messages, the problem isn't parsing the mail files. The Mail::* modules handle that fine. The problem is processing the bounce messages to figure out the reason for the bounce and the address sent to. I couldn't find any modules in CPAN that do this.

    You might want to look at some of the mailing list software written in the Perl. They have to handle processing bounces to remove bad addresses.

      my guess is they embed hidden code into their e-mails, I wanna do a global system admin kind of utility.
Re: Email Parsing of mail files for e-mail errors
by cmapuk (Novice) on Dec 03, 2002 at 18:19 UTC
    Email::Find
    http://search.cpan.org/author/MIYAGAWA/Email-Find-0.09/lib/Email/Find.pm


    Save me, St.Perldoc!
      With find what would be the code sample to have it consistently pull the correct errors as theres a thousand and one ways these errors come back?? Thanks to everyone so far for the great replies I appreciate it.