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

In reply to Parsing email by hecroce

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.