2004-07-15 01:58:47 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use strict;
|
2004-09-14 21:34:19 +02:00
|
|
|
$^W = 1;
|
2004-07-15 01:58:47 +02:00
|
|
|
|
2004-09-14 21:34:19 +02:00
|
|
|
use Test::More tests => 24;
|
2004-07-15 01:58:47 +02:00
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
use_ok('Qpsmtpd::Address');
|
|
|
|
}
|
|
|
|
|
|
|
|
my $as;
|
|
|
|
my $ao;
|
|
|
|
|
|
|
|
$as = '<>';
|
|
|
|
$ao = Qpsmtpd::Address->parse($as);
|
|
|
|
ok ($ao, "parse $as");
|
|
|
|
is ($ao->format, $as, "format $as");
|
|
|
|
|
|
|
|
$as = '<foo@example.com>';
|
|
|
|
$ao = Qpsmtpd::Address->parse($as);
|
|
|
|
ok ($ao, "parse $as");
|
|
|
|
is ($ao->format, $as, "format $as");
|
|
|
|
|
2004-07-16 04:51:39 +02:00
|
|
|
is ($ao->user, 'foo', 'user');
|
|
|
|
is ($ao->host, 'example.com', 'host');
|
|
|
|
|
2004-07-15 01:58:47 +02:00
|
|
|
# the \ before the @ in the local part is not required, but
|
|
|
|
# allowed. For simplicity we add a backslash before all characters
|
|
|
|
# which are not allowed in a dot-string.
|
|
|
|
$as = '<"musa_ibrah@caramail.comandrea.luger"@wifo.ac.at>';
|
|
|
|
$ao = Qpsmtpd::Address->parse($as);
|
|
|
|
ok ($ao, "parse $as");
|
|
|
|
is ($ao->format, '<"musa_ibrah\@caramail.comandrea.luger"@wifo.ac.at>', "format $as");
|
|
|
|
|
|
|
|
# email addresses with spaces
|
|
|
|
$as = '<foo bar@example.com>';
|
|
|
|
$ao = Qpsmtpd::Address->parse($as);
|
|
|
|
ok ($ao, "parse $as");
|
|
|
|
is ($ao->format, '<"foo\ bar"@example.com>', "format $as");
|
|
|
|
|
|
|
|
|
2004-07-16 04:51:39 +02:00
|
|
|
$as = 'foo@example.com';
|
|
|
|
$ao = Qpsmtpd::Address->parse($as);
|
|
|
|
is ($ao, undef, "can't parse $as");
|
|
|
|
|
|
|
|
$as = '<@example.com>';
|
|
|
|
is (Qpsmtpd::Address->parse($as), undef, "can't parse $as");
|
|
|
|
|
|
|
|
$as = '<@123>';
|
|
|
|
is (Qpsmtpd::Address->parse($as), undef, "can't parse $as");
|
|
|
|
|
|
|
|
$as = '<user>';
|
|
|
|
is (Qpsmtpd::Address->parse($as), undef, "can't parse $as");
|
|
|
|
|
|
|
|
|
2004-07-16 04:22:27 +02:00
|
|
|
$as = 'foo@example.com';
|
|
|
|
$ao = Qpsmtpd::Address->new($as);
|
2004-07-16 04:51:39 +02:00
|
|
|
ok ($ao, "new $as");
|
2004-07-16 04:22:27 +02:00
|
|
|
is ($ao->address, $as, "address $as");
|
|
|
|
|
2004-07-16 04:51:39 +02:00
|
|
|
$as = '<foo@example.com>';
|
|
|
|
$ao = Qpsmtpd::Address->new($as);
|
|
|
|
ok ($ao, "new $as");
|
|
|
|
is ($ao->address, 'foo@example.com', "address $as");
|
|
|
|
|
2004-09-14 21:34:19 +02:00
|
|
|
$as = '<foo@foo.x.example.com>';
|
|
|
|
$ao = Qpsmtpd::Address->new($as);
|
|
|
|
ok ($ao, "new $as");
|
|
|
|
is ($ao->format, $as, "format $as");
|
|
|
|
|
|
|
|
$as = 'foo@foo.x.example.com';
|
|
|
|
ok ($ao = Qpsmtpd::Address->parse($as), "parse $as");
|
|
|
|
is ($ao && $ao->address, $as, "address $as");
|
|
|
|
|
2004-07-16 04:51:39 +02:00
|
|
|
# Not sure why we can change the address like this, but we can so test it ...
|
|
|
|
is ($ao->address('test@example.com'), 'test@example.com', 'address(test@example.com)');
|
|
|
|
|
2004-07-16 04:22:27 +02:00
|
|
|
|