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.
my $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;
}
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 appreciated