2012-06-22 11:38:01 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
|
|
$^W = 1;
|
|
|
|
|
|
|
|
use Test::More qw/no_plan/;
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
use_ok('Qpsmtpd::Address');
|
|
|
|
}
|
|
|
|
|
|
|
|
my $as;
|
|
|
|
my $ao;
|
|
|
|
|
|
|
|
$as = '<>';
|
|
|
|
$ao = Qpsmtpd::Address->parse($as);
|
2013-04-21 06:52:07 +02:00
|
|
|
ok($ao, "parse $as");
|
|
|
|
is($ao->format, $as, "format $as");
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
$as = '<postmaster>';
|
|
|
|
$ao = Qpsmtpd::Address->parse($as);
|
2013-04-21 06:52:07 +02:00
|
|
|
ok($ao, "parse $as");
|
|
|
|
is($ao->format, $as, "format $as");
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
$as = '<foo@example.com>';
|
|
|
|
$ao = Qpsmtpd::Address->parse($as);
|
2013-04-21 06:52:07 +02:00
|
|
|
ok($ao, "parse $as");
|
|
|
|
is($ao->format, $as, "format $as");
|
2012-06-22 11:38:01 +02:00
|
|
|
|
2013-04-21 06:52:07 +02:00
|
|
|
is($ao->user, 'foo', 'user');
|
|
|
|
is($ao->host, 'example.com', 'host');
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
# the \ before the @ in the local part is not required, but
|
2013-04-21 06:52:07 +02:00
|
|
|
# allowed. For simplicity we add a backslash before all characters
|
2012-06-22 11:38:01 +02:00
|
|
|
# which are not allowed in a dot-string.
|
|
|
|
$as = '<"musa_ibrah@caramail.comandrea.luger"@wifo.ac.at>';
|
|
|
|
$ao = Qpsmtpd::Address->parse($as);
|
2013-04-21 06:52:07 +02:00
|
|
|
ok($ao, "parse $as");
|
|
|
|
is($ao->format, '<"musa_ibrah\@caramail.comandrea.luger"@wifo.ac.at>',
|
|
|
|
"format $as");
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
# email addresses with spaces
|
|
|
|
$as = '<foo bar@example.com>';
|
|
|
|
$ao = Qpsmtpd::Address->parse($as);
|
2013-04-21 06:52:07 +02:00
|
|
|
ok($ao, "parse $as");
|
|
|
|
is($ao->format, '<"foo\ bar"@example.com>', "format $as");
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
$as = 'foo@example.com';
|
|
|
|
$ao = Qpsmtpd::Address->new($as);
|
2013-04-21 06:52:07 +02:00
|
|
|
ok($ao, "new $as");
|
|
|
|
is($ao->address, $as, "address $as");
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
$as = '<foo@example.com>';
|
|
|
|
$ao = Qpsmtpd::Address->new($as);
|
2013-04-21 06:52:07 +02:00
|
|
|
ok($ao, "new $as");
|
|
|
|
is($ao->address, 'foo@example.com', "address $as");
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
$as = '<foo@foo.x.example.com>';
|
|
|
|
$ao = Qpsmtpd::Address->new($as);
|
2013-04-21 06:52:07 +02:00
|
|
|
ok($ao, "new $as");
|
|
|
|
is($ao->format, $as, "format $as");
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
$as = 'foo@foo.x.example.com';
|
2013-04-21 06:52:07 +02:00
|
|
|
ok($ao = Qpsmtpd::Address->parse('<' . $as . '>'), "parse $as");
|
|
|
|
is($ao && $ao->address, $as, "address $as");
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
# Not sure why we can change the address like this, but we can so test it ...
|
2013-04-21 06:52:07 +02:00
|
|
|
is($ao && $ao->address('test@example.com'),
|
|
|
|
'test@example.com', 'address(test@example.com)');
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
$as = '<foo@foo.x.example.com>';
|
|
|
|
$ao = Qpsmtpd::Address->new($as);
|
2013-04-21 06:52:07 +02:00
|
|
|
ok($ao, "new $as");
|
|
|
|
is($ao->format, $as, "format $as");
|
|
|
|
is("$ao", $as, "overloaded stringify $as");
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
$as = 'foo@foo.x.example.com';
|
2013-04-21 06:52:07 +02:00
|
|
|
ok($ao = Qpsmtpd::Address->parse("<$as>"), "parse <$as>");
|
|
|
|
is($ao && $ao->address, $as, "address $as");
|
|
|
|
ok($ao eq $as, "overloaded 'cmp' operator");
|
|
|
|
|
|
|
|
my @unsorted_list = map { Qpsmtpd::Address->new($_) } qw(
|
|
|
|
"musa_ibrah@caramail.comandrea.luger"@wifo.ac.at
|
|
|
|
foo@example.com
|
|
|
|
ask@perl.org
|
|
|
|
foo@foo.x.example.com
|
|
|
|
jpeacock@cpan.org
|
|
|
|
test@example.com
|
|
|
|
);
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
# NOTE that this is sorted by _host_ not by _domain_
|
2013-04-21 06:52:07 +02:00
|
|
|
my @sorted_list = map { Qpsmtpd::Address->new($_) } qw(
|
|
|
|
jpeacock@cpan.org
|
|
|
|
foo@example.com
|
|
|
|
test@example.com
|
|
|
|
foo@foo.x.example.com
|
|
|
|
ask@perl.org
|
|
|
|
"musa_ibrah@caramail.comandrea.luger"@wifo.ac.at
|
|
|
|
);
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
my @test_list = sort @unsorted_list;
|
|
|
|
|
2013-04-21 06:52:07 +02:00
|
|
|
is_deeply(\@test_list, \@sorted_list, "sort via overloaded 'cmp' operator");
|
2012-06-22 11:38:01 +02:00
|
|
|
|
|
|
|
# RT#38746 - non-RFC compliant address should return undef
|
|
|
|
|
2013-04-21 06:52:07 +02:00
|
|
|
$as = '<user@example.com#>';
|
2012-06-22 11:38:01 +02:00
|
|
|
$ao = Qpsmtpd::Address->new($as);
|
2013-04-21 06:52:07 +02:00
|
|
|
is($ao, undef, "illegal $as");
|