user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
b9e4583d40a888246d53d719f5b3b6993c67df34 blob 5573 bytes (raw)

  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
 
#!perl -w
# Copyright (C) 2020-2021 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
use v5.10.1;
use PublicInbox::TestCommon;
require_mods 'URI::Split';
use_ok 'PublicInbox::URIimap';

is(PublicInbox::URIimap->new('https://example.com/'), undef,
	'invalid scheme ignored');

my $uri = PublicInbox::URIimap->new('imaps://EXAMPLE.com/');
is($uri->host, 'EXAMPLE.com', 'host ok');
is($uri->canonical->host, 'example.com', 'host canonicalized');
is($uri->canonical->as_string, 'imaps://example.com/', 'URI canonicalized');
is($uri->port, 993, 'imaps port');
is($uri->auth, undef);
is($uri->user, undef);

$uri = PublicInbox::URIimap->new('imaps://foo@0/');
is("$uri", $uri->as_string, '"" overload works');
is($uri->host, '0', 'numeric host');
is($uri->user, 'foo', 'user extracted');

$uri = PublicInbox::URIimap->new('imap://0/INBOX.sub#frag')->canonical;
is($uri->as_string, 'imap://0/INBOX.sub', 'no fragment');
is($uri->scheme, 'imap');

$uri = PublicInbox::URIimap->new('imaps://;AUTH=ANONYMOUS@0/');
is($uri->auth, 'ANONYMOUS', 'AUTH=ANONYMOUS accepted');

$uri = PublicInbox::URIimap->new('imaps://bar%40example.com;AUTH=99%25@0/');
is($uri->auth, '99%', 'decoded AUTH');
is($uri->user, 'bar@example.com', 'decoded user');
is($uri->mailbox, undef, 'mailbox is undef');

$uri = PublicInbox::URIimap->new('imaps://ipv6@[::1]');
is($uri->host, '::1', 'IPv6 host');
is($uri->mailbox, undef, 'mailbox is undef');

$uri = PublicInbox::URIimap->new('imaps://0:666/INBOX');
is($uri->port, 666, 'port read');
is($uri->mailbox, 'INBOX');
$uri = PublicInbox::URIimap->new('imaps://0/INBOX.sub');
is($uri->mailbox, 'INBOX.sub');
is($uri->scheme, 'imaps');

is(PublicInbox::URIimap->new('imap://0:143/')->canonical->as_string,
	'imap://0/');
is(PublicInbox::URIimap->new('imaps://0:993/')->canonical->as_string,
	'imaps://0/');

$uri = PublicInbox::URIimap->new('imap://NSA:Hunter2@0/INBOX');
is($uri->user, 'NSA');
is($uri->password, 'Hunter2');
is($uri->uidvalidity, undef, 'no UIDVALIDITY');

$uri = PublicInbox::URIimap->new('imap://0/%');
is($uri->mailbox, '%', "RFC 2192 '%' supported");
$uri = PublicInbox::URIimap->new('imap://0/%25');
$uri = PublicInbox::URIimap->new('imap://0/*');
is($uri->mailbox, '*', "RFC 2192 '*' supported");

$uri = PublicInbox::URIimap->new('imap://0/mmm;UIDVALIDITY=1');
is($uri->mailbox, 'mmm', 'mailbox works with UIDVALIDITY');
is($uri->uidvalidity, 1, 'single-digit UIDVALIDITY');
$uri = PublicInbox::URIimap->new('imap://0/mmm;UIDVALIDITY=21');
is($uri->uidvalidity, 21, 'multi-digit UIDVALIDITY');
$uri = PublicInbox::URIimap->new('imap://0/mmm;UIDVALIDITY=bogus');
is($uri->uidvalidity, undef, 'bogus UIDVALIDITY');
is($uri->uidvalidity(2), 2, 'uid set');
is($$uri, 'imap://0/mmm;UIDVALIDITY=2', 'bogus uidvalidity replaced');
is($uri->uidvalidity(13), 13, 'uid set');
is($$uri, 'imap://0/mmm;UIDVALIDITY=13', 'valid uidvalidity replaced');

$uri = PublicInbox::URIimap->new('imap://0/mmm');
is($uri->uidvalidity(2), 2, 'uid set');
is($$uri, 'imap://0/mmm;UIDVALIDITY=2', 'uidvalidity appended');
is($uri->uid, undef, 'no uid');

is(PublicInbox::URIimap->new('imap://0/x;uidvalidity=1')->canonical->as_string,
	'imap://0/x;UIDVALIDITY=1', 'capitalized UIDVALIDITY');

$uri = PublicInbox::URIimap->new('imap://0/mmm/;uid=8');
is($uri->canonical->as_string, 'imap://0/mmm/;UID=8', 'canonicalized UID');
is($uri->mailbox, 'mmm', 'mailbox works with uid');
is($uri->uid, 8, 'uid extracted');
is($uri->uid(9), 9, 'uid set');
is($$uri, 'imap://0/mmm/;UID=9', 'correct uid when stringified');
is($uri->uidvalidity(1), 1, 'set uidvalidity with uid');
is($$uri, 'imap://0/mmm;UIDVALIDITY=1/;UID=9',
	'uidvalidity added with uid');
is($uri->uidvalidity(4), 4, 'set uidvalidity with uid');
is($$uri, 'imap://0/mmm;UIDVALIDITY=4/;UID=9',
	'uidvalidity replaced with uid');
is($uri->uid(3), 3, 'uid set with uidvalidity');
is($$uri, 'imap://0/mmm;UIDVALIDITY=4/;UID=3', 'uid replaced properly');

my $lc = lc($$uri);
is(PublicInbox::URIimap->new($lc)->canonical->as_string, "$$uri",
	'canonical uppercased both params');

is($uri->uid(undef), undef, 'uid can be clobbered');
is($$uri, 'imap://0/mmm;UIDVALIDITY=4', 'uid dropped');

$uri->auth('ANONYMOUS');
is($$uri, 'imap://;AUTH=ANONYMOUS@0/mmm;UIDVALIDITY=4', 'AUTH= set');
is($uri->user, undef, 'user is undef w/ AUTH=');
is($uri->password, undef, 'password is undef w/ AUTH=');

$uri->user('foo');
is($$uri, 'imap://foo;AUTH=ANONYMOUS@0/mmm;UIDVALIDITY=4', 'user set w/AUTH');
is($uri->password, undef, 'password is undef w/ AUTH= & user');
$uri->auth(undef);
is($$uri, 'imap://foo@0/mmm;UIDVALIDITY=4', 'user remains set w/o auth');
is($uri->password, undef, 'password is undef w/ user only');

$uri->user('bar');
is($$uri, 'imap://bar@0/mmm;UIDVALIDITY=4', 'user set w/o AUTH');
$uri->auth('NTML');
is($$uri, 'imap://bar;AUTH=NTML@0/mmm;UIDVALIDITY=4', 'auth set w/user');
$uri->auth(undef);
$uri->user(undef);
is($$uri, 'imap://0/mmm;UIDVALIDITY=4', 'auth and user both cleared');
is($uri->user, undef, 'user is undef');
is($uri->auth, undef, 'auth is undef');
is($uri->password, undef, 'password is undef');
$uri = PublicInbox::URIimap->new('imap://[::1]:36281/');
my $cred = bless { username => $uri->user, password => $uri->password };
is($cred->{username}, undef, 'user is undef in array context');
is($cred->{password}, undef, 'password is undef in array context');
$uri = PublicInbox::URIimap->new('imap://u@example.com/slash/separator');
is($uri->mailbox, 'slash/separator', "`/' separator accepted");

done_testing;
debug log:

solving b9e4583d ...
found b9e4583d in https://80x24.org/public-inbox.git

Code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).