• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • Last Modified:

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;
0
sparkie_77
Asked:
sparkie_77
  • 2
2 Solutions
 
Kim RyanIT ConsultantCommented:
Should be as simple as extracting text inside the angle brackets from the current line

while(my $text = <SRC>) {
   /.*<(.*)>/ and $email = $1;
}


 
0
 
Perl_DiverCommented:
this might work OK:

#!/usr/bin/perl -w
use strict;

open (SRC, "/var/log/maillog") || die "can't open source file $!";
open (DEST, ">desination.txt") || die "can't open destination file $!";
my @emails = ();
while(<SRC>) {
    /from=<([^>]+)>/i and print DEST "$1$/"
}
close SRC;
close DEST;

although it will not do any of the validating/checking Email::Find would.
0
 
Perl_DiverCommented:
if there are spaces before or after the = sign you may have to alter the regexp above

  /from\s*=\s*<([^>]+)>/i and print DEST "$1$/"



0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now