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

i'm getting really sick of having to babysit the company's mailserver every time some client sends out a bulk mail ... because all of the bounces toss the load average on the box up to something hideous, like 40 ... eventually i'll need to tackle that job, but in the meantime i've been thinking of creating a new alias to handle the bounces ...

a lot of the nodes i've seen deal with parsing mboxes, not with taking the mail off of STDIN. i know i'll hit a bottleneck ... so maybe there's a better way to architect it.

in the meantime, with of the some 10,000 odd Mail::* modules are recommended for:

1. lopping off the attachment ( the orig. message is attached )
2. parsing the message for the bad email address in the To: field.

i was originally looking at Mail::Header ... then I realized the messages have the original mail *attached*.

Mail::Message::Attachment::Stripper looks OK, but i'm wondering (out loud, i guess) if i can just pass the attachment to Mail::Header to yank out the orig. To: field

  • Comment on [Module recommendation ] parsing incoming email (piped to a script)

Replies are listed 'Best First'.
Re: [Module recommendation ] parsing incoming email (piped to a script)
by neilwatson (Priest) on Mar 29, 2004 at 21:16 UTC
    Are the clients allowed to SP, er I mean bulk mail? Handling the bounces can be done in many ways:
    • Use procmail. A useful recipie involves delivering only the first 50 lines.
    • The MIME tools module can be used for this. Keep in mind that certain email clients (Outlook) create strange entities that are very had to parse.
    • Merlyn had a script he uses for mailing lists to remove Outlook's extra attachments. You may want to search for that.

    Update: These bounces are being returned to whomever sends the bulk mail I hope. Also, I hope the bounces are being removed from the bulk list. Otherwise this is indeed SPAM.

    Neil Watson
    watson-wilson.ca

Re: [Module recommendation ] parsing incoming email (piped to a script)
by mpeppler (Vicar) on Mar 29, 2004 at 21:20 UTC
    Personally I use MIME::Parse for this sort of thing.

    Michael

Re: [Module recommendation ] parsing incoming email (piped to a script)
by xdg (Monsignor) on Mar 29, 2004 at 22:07 UTC

    I can't comment on the efficiency of it in a high-volume environment, but I've been using Mail::Box, and its handy Mail::Message class to parse out a messages coming from a procmail script. It's very versatile in dealing with encodings, attachments, etc. and that versatility has been worth the inefficiency of such a heavy object for my purposes. Here's a snippet from my script:

    #!/usr/bin/perl -w use strict; use Mail::Message; <>; # toss the mbox format From line my $msg = Mail::Message->read(\*STDIN); # (process the message) # write it back to STDOUT print $msg->head->createFromLine; $msg->print; exit;

    -xdg

    Code posted by xdg on PerlMonks is public domain. It has no warranties, express or implied. Posted code may not have been tested. Use at your own risk.