#!/usr/bin/perl -w use strict; use Mail::MboxParser; my $mbox = '/var/spool/mail/www37'; my $mb = Mail::MboxParser->new($mbox, decode => 'ALL'); print "Total messages: ", $mb->nmsgs, "\n"; # iterating through the mailbox while (my $msg = $mb->next_message) { my $body = $msg->body($msg->find_body); foreach my $line (split /\n/, $body) { my (undef, undef, $a) = split / /, $line if $line =~ /Host unknown/i && $line=~/^550/; if ( defined $a ) { $a =~ s/^<(.+)>\.\.\.$/$1/; print "Host unknown: ", $a, "\n"; # ... } my $b = $line if $line =~ /User unknown/i && $line =~/^550/; if ( defined $b ) { $b =~ s/550 5.1.1 (.+) \(.+/$1/; $b =~ s/550 5.1.1 <(.+)>.+/$1/; $b =~ s/550 <(.+)>.+/$1/; print "User unknown 550: ", $b, "\n"; # ... } my $c = $line if $line =~ /^<<< 554/; if (defined $c) { $c =~ s/.+to (.+) cannot.+/$1/; $c =~ s/.+account \((.+)\) .+/$1/; print "User unknown 554: ", $c, "\n"; #.. } } } #### <<< 554 delivery error: dd Sorry your message to foo@yahoo.com cannot be delivered. This account has been disabled or discontinued [#102]. - mta210.mail.scd.yahoo.com