parsing postfix bounce back emails from log

G

gooogoo

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.
 
G

gooogoo

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.
 
A

Anno Siegel

gooogoo said:
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
 
I

Ian Wilson

gooogoo said:
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"
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top