parsing postfix bounce back emails from log

Discussion in 'Perl Misc' started by gooogoo, Oct 10, 2005.

  1. gooogoo

    gooogoo Guest

    I have a little script going to tell me why a email bounced.

    i feel like Im taking the long road.

    Heres what I do.

    First I open the file and then do.


    while (<FILE>){

    if($_ =~ m/From\sMAILER\-DAEMON/){
    $error1 = 'unknown';

    }elsif($_ =~ m/said\:\s(.*?)\s/){
    $status_code = $1;

    }elsif($_ =~ m/Invalid\srecipient/){
    $error1 = 'Invalid Receipient';

    }elsif($_ =~ m/Mailbox\sunavailable/i){
    $error1 = 'Mailbox Unavailable';

    and so on and sooooo on. Ending up with a huge list of defined errors.


    I first match MAILER DAEMON coz every bounce back starts with that, so its a
    border to work with.

    I guess to cut down on the elsif statements I would whack the regex searches
    into an array.

    Any helpful tips.
    gooogoo, Oct 10, 2005
    #1
    1. Advertising

  2. gooogoo

    Guest

    gooogoo wrote:
    > and so on and sooooo on. Ending up with a huge list of defined errors.
    >
    > Any helpful tips.


    You could use a "case" command. Oh, wait - Perl doesn't have a "case"
    (Larry says it's redundant - but it could be handy sometimes, and this
    is one of those times).

    But CPAN has a case module:
    http://search.cpan.org/~rjohnson/Case-0.0.2/Case.pm
    , Oct 10, 2005
    #2
    1. Advertising

  3. gooogoo

    gooogoo Guest

    Yup thats what the VB ppl @ work said use Case. But then i said huh? perl
    dont have case. didn't think about case modules thou.

    Thanxs, I'll give it a go.

    <> wrote in message
    news:...
    >
    > gooogoo wrote:
    > > and so on and sooooo on. Ending up with a huge list of defined

    errors.
    > >
    > > Any helpful tips.

    >
    > You could use a "case" command. Oh, wait - Perl doesn't have a "case"
    > (Larry says it's redundant - but it could be handy sometimes, and this
    > is one of those times).
    >
    > But CPAN has a case module:
    > http://search.cpan.org/~rjohnson/Case-0.0.2/Case.pm
    >
    gooogoo, Oct 10, 2005
    #3
  4. gooogoo

    Anno Siegel Guest

    gooogoo <> wrote in comp.lang.perl.misc:
    > I have a little script going to tell me why a email bounced.
    >
    > i feel like Im taking the long road.
    >
    > Heres what I do.
    >
    > First I open the file and then do.
    >
    >
    > while (<FILE>){
    >
    > if($_ =~ m/From\sMAILER\-DAEMON/){
    > $error1 = 'unknown';


    This looks like a logical error. You'll check all other conditions only
    if the line *doesn't* match /From\sMAILER\-DAEMON/.

    > }elsif($_ =~ m/said\:\s(.*?)\s/){
    > $status_code = $1;
    >
    > }elsif($_ =~ m/Invalid\srecipient/){
    > $error1 = 'Invalid Receipient';
    >
    > }elsif($_ =~ m/Mailbox\sunavailable/i){
    > $error1 = 'Mailbox Unavailable';
    >
    > and so on and sooooo on. Ending up with a huge list of defined errors.


    Your indentation is wrong. All "elsif"s are on the same level and should
    be indented equally.

    Anno
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
    Anno Siegel, Oct 10, 2005
    #4
  5. gooogoo

    Ian Wilson Guest

    gooogoo wrote:
    > I have a little script going to tell me why a email bounced.
    >
    > i feel like Im taking the long road.
    >
    > Heres what I do.
    >
    > First I open the file and then do.
    >
    >
    > while (<FILE>){
    >
    > if($_ =~ m/From\sMAILER\-DAEMON/){
    > $error1 = 'unknown';
    >
    > }elsif($_ =~ m/said\:\s(.*?)\s/){
    > $status_code = $1;
    >
    > }elsif($_ =~ m/Invalid\srecipient/){
    > $error1 = 'Invalid Receipient';
    >
    > }elsif($_ =~ m/Mailbox\sunavailable/i){
    > $error1 = 'Mailbox Unavailable';
    >
    > and so on and sooooo on. Ending up with a huge list of defined errors.
    >
    >
    > I first match MAILER DAEMON coz every bounce back starts with that, so its a
    > border to work with.
    >
    > I guess to cut down on the elsif statements I would whack the regex searches
    > into an array.
    >
    > Any helpful tips.
    >
    >


    perldoc -q "case statement"
    Ian Wilson, Oct 10, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nils M. Lunde

    Bounce Email

    Nils M. Lunde, Jul 12, 2004, in forum: Perl
    Replies:
    1
    Views:
    610
    Nils M. Lunde
    Jul 12, 2004
  2. Darren Clark

    Parsing Email bounce back tex

    Darren Clark, Feb 23, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,248
    MasterGaurav
    Feb 24, 2005
  3. Xah Lee

    4 balls: lone-ball side-bounce

    Xah Lee, Mar 4, 2006, in forum: Java
    Replies:
    6
    Views:
    525
    Jay Linn
    Mar 6, 2006
  4. Bob Wheeler
    Replies:
    0
    Views:
    371
    Bob Wheeler
    Jun 30, 2003
  5. Priyank Shah

    How to Fetch list of Bounce emails??

    Priyank Shah, Jun 30, 2008, in forum: Ruby
    Replies:
    0
    Views:
    100
    Priyank Shah
    Jun 30, 2008
Loading...

Share This Page