#!/usr/bin/perl #checks for valid email address #usage validemail <file containing email addresses> use warnings; use strict; use Email::Valid::Loose; use Net::DNS; use Parallel::ForkManager; use Fcntl qw/:flock :seek/; my $pm=new Parallel::ForkManager(20); my $resolver=Net::DNS::Resolver->new(); my $addrfile = $ARGV[0] || die "Usage validemail <file containing email addresses> Will return two files: goodmails.csv and badmails.csv. If these files exits already they will be deleted. "; my ($is_valid, $host, $x, @mx, $add, @adds); #custom words that make emails invalid to you my @custom = qw/ postmaster webmaster /; my $regex = join "|", @custom; $regex = qr/$regex/; open (EMAILS, "$addrfile"); #remove troublesome windows /r characters #and leading whitespace while (<EMAILS>){ $_ =~ s/\015//; $_ =~ s/^\s*//; chomp $_; push @adds, $_; } close (EMAILS); #warning, I will delete existing files open (BADADDR, ">badmails.csv") || die; open (GOODADDR, ">goodmails.csv") || die; #remove custom regexes $x = 0; while ($x <= $#adds){ if ($adds[$x] =~ m/$regex/){ splice @adds, $x, 1; }else{ $x++; } } foreach $add (@adds){ $pm->start and next; #if email is invalid move on if (!defined(Email::Valid::Loose->address($add))){ writeaddr(*BADADDR, $add); #address is bad $pm->finish; } #if email is valid get domain name $is_valid = Email::Valid::Loose->address($add); if ($is_valid =~ m/\@(.*)$/) { $host = $1; } $is_valid=""; # perform dsn lookup to check domain @mx=mx($resolver, $host); if (@mx) { writeaddr(*GOODADDR, $add); #address is good }else{ writeaddr(*BADADDR, $add); #address is bad } $pm->finish; } $pm->wait_all_children; close (BADADDR); close (GOODADDR); sub writeaddr{ my $FH = $_[0]; my $address = $_[1]; flock $FH, LOCK_EX or die "Flock failed: $!\n"; seek $FH, 0, 2 or die "Seek failed: $!\n"; print $FH "$address\n"; flock $FH, LOCK_UN or die "unFlock failed: $!\n"; }
The errors:
Unrecognised line: user1@foo.com at /usr/lib/perl5/site_perl/5.8.0/Ema +il/Valid.pm line 232 Unrecognised line: user2@foo.com at /usr/lib/perl5/site_perl/5.8.0/Ema +il/Valid.pm line 232 Unrecognised line: user3@foo.com at /usr/lib/perl5/site_perl/5.8.0/Ema +il/Valid.pm line 232
Anyone have any ideas as to the cause?
Neil Watson
watson-wilson.ca
update (broquaint): added <readmore> tags
In reply to Email::Valid::Loose failing on new box? by neilwatson
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |