2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
7 require_mods 'URI::Split';
8 use_ok 'PublicInbox::URIimap';
10 is(PublicInbox::URIimap->new('https://example.com/'), undef,
11 'invalid scheme ignored');
13 my $uri = PublicInbox::URIimap->new('imaps://EXAMPLE.com/');
14 is($uri->host, 'EXAMPLE.com', 'host ok');
15 is($uri->canonical->host, 'example.com', 'host canonicalized');
16 is($uri->canonical->as_string, 'imaps://example.com/', 'URI canonicalized');
17 is($uri->port, 993, 'imaps port');
18 is($uri->auth, undef);
19 is($uri->user, undef);
21 $uri = PublicInbox::URIimap->new('imaps://foo@0/');
22 is($uri->host, '0', 'numeric host');
23 is($uri->user, 'foo', 'user extracted');
25 $uri = PublicInbox::URIimap->new('imap://0/INBOX.sub#frag')->canonical;
26 is($uri->as_string, 'imap://0/INBOX.sub', 'no fragment');
27 is($uri->scheme, 'imap');
29 $uri = PublicInbox::URIimap->new('imaps://;AUTH=ANONYMOUS@0/');
30 is($uri->auth, 'ANONYMOUS', 'AUTH=ANONYMOUS accepted');
32 $uri = PublicInbox::URIimap->new('imaps://bar%40example.com;AUTH=99%25@0/');
33 is($uri->auth, '99%', 'decoded AUTH');
34 is($uri->user, 'bar@example.com', 'decoded user');
35 is($uri->mailbox, undef, 'mailbox is undef');
37 $uri = PublicInbox::URIimap->new('imaps://ipv6@[::1]');
38 is($uri->host, '::1', 'IPv6 host');
39 is($uri->mailbox, undef, 'mailbox is undef');
41 $uri = PublicInbox::URIimap->new('imaps://0:666/INBOX');
42 is($uri->port, 666, 'port read');
43 is($uri->mailbox, 'INBOX');
44 $uri = PublicInbox::URIimap->new('imaps://0/INBOX.sub');
45 is($uri->mailbox, 'INBOX.sub');
46 is($uri->scheme, 'imaps');
48 is(PublicInbox::URIimap->new('imap://0:143/')->canonical->as_string,
50 is(PublicInbox::URIimap->new('imaps://0:993/')->canonical->as_string,
53 $uri = PublicInbox::URIimap->new('imap://NSA:Hunter2@0/INBOX');
54 is($uri->user, 'NSA');
55 is($uri->password, 'Hunter2');
57 $uri = PublicInbox::URIimap->new('imap://0/%');
58 is($uri->mailbox, '%', "RFC 2192 '%' supported");
59 $uri = PublicInbox::URIimap->new('imap://0/%25');
60 $uri = PublicInbox::URIimap->new('imap://0/*');
61 is($uri->mailbox, '*', "RFC 2192 '*' supported");
63 # TODO: support UIDVALIDITY and other params