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

Alright; I was checking out my profile at it looks like I was working on this same problem 2 years ago. How sad is that?
Actually it has gone in and out of being simi-important to my employer which is why I have not followed through...Anyway...
I have been re-re-tasked with creating a list of bounced e-mail addresses and the reason they bounced. I only get access to the mail after it reaches the exchange server and I can see it through Outlook. That is the extent of my access to the server as well (last time it was suggested that I parse the SMTP logs. While this is a very clever idea, I do not have that much access.)
I have Outlook filtering the bounced messages into a separate folder that I have exported as a CSV. I trimmed this CSV down to a single 'body' column (just to eliminate any gotchas) and am trying to feed it to Mail::DeliveryStatus::BounceParse using DBM::CSV (since otherwise it is hard to figure out whether a new line is the end of a record or just part of a message body.)
There are about 2000 bounce backs per day so I would prefer not having to do this manually ;-)
First question: Will this Bounce Parser work based on the body only or does it need the header of the message?
Second Question: If you can keep from laughing at my code long enough, can you tell me what I have done wrong / does this have any chance of working? As you may be able to tell, it is snippets from wherever I could find them, mashed together and left to ferment.
use Mail::DeliveryStatus::BounceParser; use DBI; my $dbh = DBI->connect("DBI:CSV:") or die "Cannot connect: " . $DBI::e +rrstr; my $in_file = "testcsv"; my $out_file = "bounce_report.csv"; print "WARNING...this program will write over your ",$out_file, " file + in a few sec.\n"; sleep 3; open (REPORT, "+>$out_file") or die "Cant open report file, $!"; print REPORT "Arival_Date,Email,Final_Recipient,Action,Std_Reason,R +eason,SMTP_Code,Status,Diag_Code,Reporting_MTA,Host,Raw\n"; my($query) = "SELECT * FROM $in_file"; my($sth) = $dbh->prepare($query) or die "Cannot prepare: " . $dbh->err +str(); $sth->execute() or die "Cannot execute: " . $sth->errstr(); my($body); $sth->bind_columns(undef, \$body); my $n=0; while ($sth->fetch) { my $bounce = eval { Mail::DeliveryStatus::BounceParser->new( $body ) } +; print $report->get('email'); $n++; } $sth->finish(); $dbh->disconnect(); close REPORT; print "Processing complete. In = ", $n, " records\n";

I get "can't call method "get" on an undefined value at sqlbouncerpt.pl line 20 when I try to run it. Line 20 is
print $report->get('email');
I currently have this line just printing to STDOUT so that I can tell if it works. Once it does, I will enter the rest of the fields and point them to the output file. Any help or a better way to go about this would be very much appreciated.
James

Replies are listed 'Best First'.
Re: Mail::DeliveryStatus::BounceParse
by Juerd (Abbot) on Jan 16, 2005 at 16:30 UTC

    I get "can't call method "get" on an undefined value at sqlbouncerpt.pl line 20 when I try to run it. Line 20 is print $report->get('email');

    Eh, yea. It's the first and only time you use $report, so it is undef, which cannot be used as an object.

    use strict; use strict; use strict; use strict; use strict; use strict; use strict;
    And use warnings too!

    See also a tutorial or a book. You need one.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

      To make sure I understand, you somewhat recommend using
      use strict; ?
      In all seriousness, I appreciate the suggestions and the pointer to the tutorial. I have started going through it and, really enjoy the way it is written.
      I have no delusions about the strength of my code. While I have written many small LAMP applications (mostly but not all, using PHP), I am (obviously) not a programmer.
      In the past I have had very good luck, learning (figuring out is a more accurate term) on the fly from the books I have on my shelf, code snippets I can find on the web and, in this case, a dose of pod2html. Most of the time I can mash them all together, make any specific changes I want, and have a working program that does what I want it to. In this case however, I seem to be shut out. My lack of real programming knowledge may have caught up to me.
      I know that the problem is not with the logic of the program (even though that could no doubt be improved) but with my attempts to call the available reports. I have placed in my main loop, a print statement that prints $body and $bounce (sounds like a shampoo commercial). The $body prints just fine (telling me that the file opens, is read and is parsed correctly) and, although all I see is a hash reference, $bounce updates as the loop runs so I know the data is getting fed into the module and it is accepting it.
      I am confident that I can figure out the last part, how to define $report so that it contains the information necessary to call $report->get('XYZ');
      I am going to go through the module code and the tutorial more tonight to see what I can turn up.

      Thanks again for the pointers;
      James

        To make sure I understand, you somewhat recommend using use strict; ?

        Nahhh... Where did you get that idea? ;)

        Both strict and warnings would have told you about the mistake with $report. This is why these tools are so valuable.

        Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }