hecroce has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks:
I'm trying to do some parsing of bounced email messages.
I'm using qmail as MTA (although I think this should not be relevant).
My approach is to traverse the directories with File::Find
and the callback function would take care of the rest.
After a few attempts to use my own regexps, etc I found that this module Mail::DeliveryStatus::BounceParser; could save me some work, and if fact, everything goes ok until i try to do anything (see commented lines in the callback function) with the file handle before passing it to the constructor of Mail::DeliveryStatus::BounceParser. Any help will be highly appreciatedmy $directory = '/home/vpopmail/domains/somedomain.net'; opendir DH, $directory or die $!; my @users = grep {!/^\.+/ && !/\.bak$/ && !/postmaster/} readdir DH; closedir DH; $_ = "$directory/$_" for @users; find (\&process_file, @users); sub process_file { return if -d; my $full_name="$File::Find::dir/$_"; my $cmd_res=`file $full_name`; return unless $cmd_res =~ /smtp mail text$/; open K, "<$full_name" or die $!; #my @safe_file_copy=<K>; #my $file_content=join("\n",<K>); #@safe_file_copy); #print $file_content; # ............ #my $bounce = eval { Mail::DeliveryStatus::BounceParser->new($file +_content); }; my $bounce = eval { Mail::DeliveryStatus::BounceParser->new(\*K); +}; if ($bounce->is_bounce) { for my $report ( $bounce->reports() ) { print "email: ".$report->get('email')."\n"; print "reason: ".$report->get('std_reason')."\n"; } } else { print "Does not look like a bounced msg!\n"; } close K; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parsing email
by olus (Curate) on Apr 09, 2008 at 09:29 UTC | |
by hecroce (Friar) on Apr 10, 2008 at 04:41 UTC | |
Re: Parsing email
by CountZero (Bishop) on Apr 09, 2008 at 09:36 UTC | |
Re: Parsing email
by samtregar (Abbot) on Apr 09, 2008 at 18:36 UTC | |
by hecroce (Friar) on Apr 10, 2008 at 04:46 UTC |
Back to
Seekers of Perl Wisdom