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 File::Basename;
|
||||
use Getopt::Std;
|
||||
use Mail::Address;
|
||||
use Net::DNS;
|
||||
use Net::SMTP;
|
||||
|
||||
|
@ -85,7 +86,7 @@ if ($options{'f'}) {
|
|||
my (%targets,$curstat,$status,$log,$message);
|
||||
foreach (@addresses) {
|
||||
my $address = $_;
|
||||
(undef,my $domain) = splitaddress($address);
|
||||
my $domain = Mail::Address->new('',$address)->host;
|
||||
printf(" * Testing %s ...\n",$address) if !($options{'q'});
|
||||
$log .= "\n===== BEGIN $address =====\n";
|
||||
# get list of target hosts or take host forced via -m
|
||||
|
@ -205,8 +206,7 @@ sub checksmtp {
|
|||
} elsif ($success) {
|
||||
# -r: try random address (which should be guaranteed to be invalid)
|
||||
if ($options{'r'}) {
|
||||
(undef,my $domain) = splitaddress($address);
|
||||
my ($success,$code,@message) = try_rcpt_to(\$smtp,create_rand_addr($domain),$logr);
|
||||
my ($success,$code,@message) = try_rcpt_to(\$smtp,create_rand_addr(Mail::Address->new('',$address)->host),$logr);
|
||||
# connection failure?
|
||||
if ($success < 0) {
|
||||
$status = connection_failed(@message);
|
||||
|
@ -239,18 +239,6 @@ sub checksmtp {
|
|||
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 a random mail address
|
||||
# IN : $domain: the domain part
|
||||
|
@ -401,6 +389,10 @@ Getopt::Std
|
|||
|
||||
=item -
|
||||
|
||||
Mail::Address I<(CPAN)>
|
||||
|
||||
=item -
|
||||
|
||||
Net::DNS I<(CPAN)>
|
||||
|
||||
=item -
|
||||
|
|
Loading…
Reference in a new issue