sparkie_77
asked on
Parse postfix mail logs for addresses then compare them to a addresses :qdatabase
Hi Guys,
I am trying to parse a postfix log file for from addresses then compare them to a database.
SO I need to extract the email from: postfix/qmgr[24973]: 199D81C28579: from=<blah@blah.com>, size=6928, nrcpt=1 (queue active) then run a query to find it in a database. Need this quick!
Tried using Email::Find and it wouldn't work.
#!/usr/bin/perl -w
use strict;
use Email::Find;
open (SRC, "/var/log/maillog") || die "can't open source file $!";
open (DEST, ">desination.txt") || die "can't open destination file $!";
my $finder = Email::Find->new(sub { my($email, $orig_email) = @_;
print DEST $email->format,$/;
return $orig_email;
});
while(my $text = <SRC>) { $finder->find(\$text); }
close SRC;
close DEST;
I am trying to parse a postfix log file for from addresses then compare them to a database.
SO I need to extract the email from: postfix/qmgr[24973]: 199D81C28579: from=<blah@blah.com>, size=6928, nrcpt=1 (queue active) then run a query to find it in a database. Need this quick!
Tried using Email::Find and it wouldn't work.
#!/usr/bin/perl -w
use strict;
use Email::Find;
open (SRC, "/var/log/maillog") || die "can't open source file $!";
open (DEST, ">desination.txt") || die "can't open destination file $!";
my $finder = Email::Find->new(sub { my($email, $orig_email) = @_;
print DEST $email->format,$/;
return $orig_email;
});
while(my $text = <SRC>) { $finder->find(\$text); }
close SRC;
close DEST;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
/from\s*=\s*<([^>]+)>/i and print DEST "$1$/"