Address: renamed $domain/$domain_re (clearer)

and added a couple more tests
This commit is contained in:
Matt Simerson 2014-09-22 10:33:15 -07:00
parent 2aaedbb445
commit 7576e64f70
2 changed files with 12 additions and 5 deletions

View File

@ -195,27 +195,27 @@ sub canonify {
};
$path = $1;
my $domain = $domain_expr || "$subdomain_expr(?:\.$subdomain_expr)*";
my $domain_re = $domain_expr || "$subdomain_expr(?:\.$subdomain_expr)*";
# $address_literal_expr may be empty, if a site doesn't allow them
if (!$domain_expr && $address_literal_expr) {
$domain = "(?:$address_literal_expr|$domain)";
$domain_re = "(?:$address_literal_expr|$domain_re)";
};
# strip source route
$path =~ s/^\@$domain(?:,\@$domain)*://;
$path =~ s/^\@$domain_re(?:,\@$domain_re)*://;
# empty path is ok
if ($path eq '') {
return '', undef, 'empty path';
};
# bare postmaster is permissible, perl RFC-2821 (4.5.1)
# bare postmaster is permissible, per RFC-2821 (4.5.1)
if ( $path =~ m/^postmaster$/i ) {
return 'postmaster', undef, 'bare postmaster';
}
my ($localpart, $domainpart) = ($path =~ /^(.*)\@($domain)$/);
my ($localpart, $domainpart) = $path =~ /^(.*)\@($domain_re)$/;
if (!defined $localpart) {
return;
};

View File

@ -207,6 +207,13 @@ sub __canonify {
@r = Qpsmtpd::Address->canonify('<postmaster@test>');
is_deeply(\@r, [ 'postmaster', 'test', 'local matches atom' ], 'canonify, postmaster@test');
@r = Qpsmtpd::Address->canonify('<@a:postmaster@test>');
is_deeply(\@r, [ 'postmaster', 'test', 'local matches atom' ], 'canonify, @a:postmaster@test (source route)');
@r = Qpsmtpd::Address->canonify('<postmáster@test>');
is_deeply(\@r, [ 'postmáster', 'test', 'local matches atom' ], 'canonify, postmáster@test, local matches atom');
@r = Qpsmtpd::Address->canonify('<@192.168.1.1>');
is_deeply(\@r, [ undef, undef, 'fall through' ], 'canonify, fall through, @192.168.1.1')
or diag Data::Dumper::Dumper(@r);
}