Replace splitaddress() by Mail::Address.
Signed-off-by: Thomas Hochstein <thh@inter.net>
This commit is contained in:
parent
9fc0e92776
commit
fd1fe450c1
22
checkmail.pl
22
checkmail.pl
|
@ -24,6 +24,7 @@ my %config=(
|
||||||
use strict;
|
use strict;
|
||||||
use File::Basename;
|
use File::Basename;
|
||||||
use Getopt::Std;
|
use Getopt::Std;
|
||||||
|
use Mail::Address;
|
||||||
use Net::DNS;
|
use Net::DNS;
|
||||||
use Net::SMTP;
|
use Net::SMTP;
|
||||||
|
|
||||||
|
@ -85,7 +86,7 @@ if ($options{'f'}) {
|
||||||
my (%targets,$curstat,$status,$log,$message);
|
my (%targets,$curstat,$status,$log,$message);
|
||||||
foreach (@addresses) {
|
foreach (@addresses) {
|
||||||
my $address = $_;
|
my $address = $_;
|
||||||
(undef,my $domain) = splitaddress($address);
|
my $domain = Mail::Address->new('',$address)->host;
|
||||||
printf(" * Testing %s ...\n",$address) if !($options{'q'});
|
printf(" * Testing %s ...\n",$address) if !($options{'q'});
|
||||||
$log .= "\n===== BEGIN $address =====\n";
|
$log .= "\n===== BEGIN $address =====\n";
|
||||||
# get list of target hosts or take host forced via -m
|
# get list of target hosts or take host forced via -m
|
||||||
|
@ -205,8 +206,7 @@ sub checksmtp {
|
||||||
} elsif ($success) {
|
} elsif ($success) {
|
||||||
# -r: try random address (which should be guaranteed to be invalid)
|
# -r: try random address (which should be guaranteed to be invalid)
|
||||||
if ($options{'r'}) {
|
if ($options{'r'}) {
|
||||||
(undef,my $domain) = splitaddress($address);
|
my ($success,$code,@message) = try_rcpt_to(\$smtp,create_rand_addr(Mail::Address->new('',$address)->host),$logr);
|
||||||
my ($success,$code,@message) = try_rcpt_to(\$smtp,create_rand_addr($domain),$logr);
|
|
||||||
# connection failure?
|
# connection failure?
|
||||||
if ($success < 0) {
|
if ($success < 0) {
|
||||||
$status = connection_failed(@message);
|
$status = connection_failed(@message);
|
||||||
|
@ -239,18 +239,6 @@ sub checksmtp {
|
||||||
return $status;
|
return $status;
|
||||||
}
|
}
|
||||||
|
|
||||||
################################# splitaddress #################################
|
|
||||||
# split mail address into local and domain part
|
|
||||||
# IN : $address: a mail address
|
|
||||||
# OUT: $local : local part
|
|
||||||
# $domain: domain part
|
|
||||||
sub splitaddress {
|
|
||||||
my($address)=@_;
|
|
||||||
(my $lp = $address) =~ s/^([^@]+)@.*/$1/;
|
|
||||||
(my $domain = $address) =~ s/[^@]+\@(\S*)$/$1/;
|
|
||||||
return ($lp,$domain);
|
|
||||||
};
|
|
||||||
|
|
||||||
############################### create_rand_addr ###############################
|
############################### create_rand_addr ###############################
|
||||||
# create a random mail address
|
# create a random mail address
|
||||||
# IN : $domain: the domain part
|
# IN : $domain: the domain part
|
||||||
|
@ -401,6 +389,10 @@ Getopt::Std
|
||||||
|
|
||||||
=item -
|
=item -
|
||||||
|
|
||||||
|
Mail::Address I<(CPAN)>
|
||||||
|
|
||||||
|
=item -
|
||||||
|
|
||||||
Net::DNS I<(CPAN)>
|
Net::DNS I<(CPAN)>
|
||||||
|
|
||||||
=item -
|
=item -
|
||||||
|
|
Loading…
Reference in a new issue