1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
#!perl
use strict;
use Test::More tests => 34;
BEGIN {
use_ok('Email::Valid');
}
my $v = Email::Valid->new;
for my $sub (
sub { $_[0] },
sub { Mail::Address->new(undef, $_[0]) },
) {
ok(
! $v->address( $sub->('Alfred Neuman <Neuman@BBN-TENEXA>') ),
'Alfred Neuman <Neuman@BBN-TENEXA>',
);
ok(
$v->address( $sub->('123@example.com') ),
'123@example.com',
);
}
ok(
$v->address( -address => 'Alfred Neuman <Neuman@BBN-TENEXA>', -fqdn => 0),
'Alfred Neuman <Neuman@BBN-TENEXA> { -fqdn => 0 }',
);
is(
$v->address( -address => 'first last@aol.com', -fudge => 1),
'firstlast@aol.com',
"spaces fudged out of an address local-part",
);
ok(
! $v->address( -address => 'first last@aol.com', -fudge => 0),
"spaces in localpart is not valid when not fudging",
);
is($v->details, 'rfc822', "details are rfc822");
is(
$v->address('foo @ foo.com'),
'foo@foo.com',
"spaced out address is squished"
);
is(
$v->address(q{fred&barney@stonehenge(yup, the rock place).(that's dot)com}),
'fred&barney@stonehenge.com',
"comments nicely dropped from an address",
);
is ($v->address(-address => 'user@example.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),
undef,
"address with > 254 chars fails",
);
is($v->details, 'address_too_long', "details say address is too long");
is(
$v->address(-address => 'somebody@example.com', -localpart => 1),
'somebody@example.com',
"localpart with 64 chars or less is valid",
);
is(
$v->address(-address => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa@example.com', -localpart => 1),
undef,
"localpart with 64 chars or more fails",
);
is($v->details, 'localpart', "details are localpart");
ok(
$v->address('somebody@ example.com'),
"space between @ and domain is valid",
);
is(
$v->address(-address => '1@example.com', -localpart => 1),
'1@example.com',
"localpart in true context succeeds",
);
is(
$v->address(-address => '0@example.com', -localpart => 1),
'0@example.com',
"localpart in false context is defined (bug 75736)",
);
ok(
$v->address('-dashy@example.net'),
'an email can start with a dash',
);
ok(
$v->address(-address => '-dashy@example.net'),
'an email can start with a dash (alternate calling method)',
);
ok(
! $v->address(-address => 'dashy@-example.net', -fqdn => 1),
'but a domain cannot',
);
ok(
! $v->address(-address => 'dashy@example.net-', -fqdn => 1),
'a domain cannot end with a dash either',
);
ok(
$v->address(-address => 'dashy@a--o.example.net', -fqdn => 1),
'but a domain may contain two dashes in a row in the middle',
);
ok(
$v->address(-address => 'dashy@ao.example.net', -fqdn => 1),
'and of course two-character labels are valid!',
);
ok(
$v->address(-address => 'dashy@a.a.example.net', -fqdn => 1),
'onesies, too',
);
SKIP: {
skip "Net::DNS not available or network down", 2
unless eval { require Net::DNS; 1; } && Net::DNS::mx('debian.org');
# skip "your dns appears missing or failing to resolve", 2
# unless eval { $v->address(-address=> 'devnull@pobox.com', -mxcheck => 1) };
if (
$v->address(-address => 'blort@will-never-exist.pobox.com', -mxcheck => 1)
) {
skip "your dns is lying to you; you must not use mxcheck", 2;
}
ok(
$v->address(-address => 'blort@aol.com', -mxcheck => 1),
'blort@aol.com, with mxcheck, is ok',
);
ok(
!$v->address(-address => 'blort@will-never-exist.pobox.com', -mxcheck => 1),
'blort@will-never-exist.pobox.com, with mxcheck, is invalid',
) or diag "was using $Email::Valid::DNS_Method for dns resolution";
}
ok(
$v->address(-address => 'rjbs@[127.0.0.1]'),
'a domain literal address is okay',
);
ok(
! $v->address(-address => 'rjbs@[127.0.0.1]', -allow_ip => 0),
'a domain literal address is not okay if we say -allow_ip=>0',
);
SKIP: {
skip "tests require Net::Domain::TLD 1.65", 4
unless (eval {require Net::Domain::TLD;Net::Domain::TLD->VERSION(1.65);1});
{
my $v = Email::Valid->new;
ok(
$v->address(
-address => 'blort@notarealdomainfoo.com',
-mxcheck => 0,
-tldcheck => 1,
),
'blort@notarealdomainfoo.com is ok with tldcheck',
);
ok(
! $v->address(
-address => 'blort@notarealdomainfoo.bla',
-mxcheck => 0,
-tldcheck => 1,
),
'blort@notarealdomainfoo.bla is not ok with tldcheck',
);
is($v->details, 'tldcheck', "it was the tldcheck that broke this email");
}
ok(
Email::Valid->address(
-tldcheck => 1,
-allow_ip => 1,
-address => q!foo@[1.2.3.4]!,
),
"allow_ip + domain literal = no tldcheck",
);
}
|