diff --git a/lib/Qpsmtpd/Address.pm b/lib/Qpsmtpd/Address.pm index 469a23e..ad5159e 100644 --- a/lib/Qpsmtpd/Address.pm +++ b/lib/Qpsmtpd/Address.pm @@ -190,7 +190,9 @@ sub canonify { my ($dummy, $path) = @_; # strip delimiters - return if $path !~ /^<(.*)>$/; + if ($path !~ /^<(.*)>$/) { + return undef, undef, 'missing delimiters'; ## no critic (undef) + }; $path = $1; my $domain = $domain_expr || "$subdomain_expr(?:\.$subdomain_expr)*"; @@ -204,18 +206,22 @@ sub canonify { $path =~ s/^\@$domain(?:,\@$domain)*://; # empty path is ok - return '' if $path eq ''; + if ($path eq '') { + return '', undef, 'empty path'; + }; # bare postmaster is permissible, perl RFC-2821 (4.5.1) if ( $path =~ m/^postmaster$/i ) { - return 'postmaster'; + return 'postmaster', undef, 'bare postmaster'; } my ($localpart, $domainpart) = ($path =~ /^(.*)\@($domain)$/); - return if !defined $localpart; + if (!defined $localpart) { + return; + }; if ($localpart =~ /^$atom_expr(\.$atom_expr)*/) { - return $localpart, $domainpart; # simple case, we are done + return $localpart, $domainpart, 'local matches atom'; # simple case, we are done } if ($localpart =~ /^"(($qtext_expr|\\$text_expr)*)"$/) { @@ -223,7 +229,7 @@ sub canonify { $localpart =~ s/\\($text_expr)/$1/g; return $localpart, $domainpart; } - return; + return undef, undef, 'fall through'; ## no critic (undef) } sub parse { diff --git a/t/qpsmtpd-address.t b/t/qpsmtpd-address.t index c9123b8..2fc7dec 100644 --- a/t/qpsmtpd-address.t +++ b/t/qpsmtpd-address.t @@ -17,6 +17,7 @@ BEGIN { __new(); __config(); __parse(); +__canonify(); done_testing(); @@ -186,3 +187,26 @@ sub __config { is($sender->config($_->{pref}), $_->{expected}, $_->{descr}); } } + +sub __canonify { + + my $as = 'foo@x.example.com'; + my $ao = Qpsmtpd::Address->new($as); + ok( ! defined $Qpsmtpd::Address::domain_expr, "domain_expr is undef"); + ok( $Qpsmtpd::Address::subdomain_expr, "subdomain_expr is defined, $Qpsmtpd::Address::subdomain_expr"); + + my @r = Qpsmtpd::Address->canonify('sample@path'); + is_deeply(\@r, [ undef, undef, "missing delimiters" ], 'canonify, missing delimiters'); + + @r = Qpsmtpd::Address->canonify(''); + is_deeply(\@r, [ undef, undef, "missing delimiters" ], 'canonify, empty path'); + + @r = Qpsmtpd::Address->canonify(''); + is_deeply(\@r, [ 'postmaster', undef, "bare postmaster" ], 'canonify, bare postmaster'); + + @r = Qpsmtpd::Address->canonify(''); + is_deeply(\@r, [ 'postmaster', 'test', 'local matches atom' ], 'canonify, postmaster@test'); + + @r = Qpsmtpd::Address->canonify(''); + is_deeply(\@r, [ 'postmáster', 'test', 'local matches atom' ], 'canonify, postmáster@test, local matches atom'); +}