Update Geary.Imap.ClientSession namespace handling

Add namespace accessors, handle updating namespaces when processing
the received data, not when executing the command so that unsolicited
namespaces are still recognised. Clear namespaces when new data is
receieved and when not in selected and auth states. Add unit tests.
This commit is contained in:
Michael Gratton 2019-12-30 09:31:31 +10:30 committed by Michael James Gratton
parent b46838f100
commit 7ac72379bb
3 changed files with 175 additions and 33 deletions

View file

@ -25,6 +25,7 @@ class Geary.Imap.ClientSessionTest : TestCase {
add_test("login_logout", login_logout);
add_test("initiate_request_capabilities", initiate_request_capabilities);
add_test("initiate_implicit_capabilities", initiate_implicit_capabilities);
add_test("initiate_namespace", initiate_namespace);
}
protected override void set_up() throws GLib.Error {
@ -330,6 +331,77 @@ class Geary.Imap.ClientSessionTest : TestCase {
);
}
public void initiate_namespace() throws GLib.Error {
this.server.add_script_line(
SEND_LINE,
"* OK [CAPABILITY IMAP4rev1 LOGIN] localhost test server ready"
);
this.server.add_script_line(
RECEIVE_LINE, "a001 login test password"
);
this.server.add_script_line(
SEND_LINE, "a001 OK [CAPABILITY IMAP4rev1 NAMESPACE] ohhai"
);
this.server.add_script_line(
RECEIVE_LINE, "a002 LIST \"\" INBOX"
);
this.server.add_script_line(
SEND_LINE, "* LIST (\\HasChildren) \".\" Inbox"
);
this.server.add_script_line(
SEND_LINE, "a002 OK there"
);
this.server.add_script_line(
RECEIVE_LINE, "a003 NAMESPACE"
);
this.server.add_script_line(
SEND_LINE,
"""* NAMESPACE (("INBOX." ".")) (("user." ".")) (("shared." "."))"""
);
this.server.add_script_line(SEND_LINE, "a003 OK there");
this.server.add_script_line(WAIT_FOR_DISCONNECT, "");
var test_article = new ClientSession(new_endpoint());
assert_true(test_article.get_protocol_state(null) == NOT_CONNECTED);
test_article.connect_async.begin(
CONNECT_TIMEOUT, null, this.async_complete_full
);
test_article.connect_async.end(async_result());
assert_true(test_article.get_protocol_state(null) == UNAUTHORIZED);
test_article.initiate_session_async.begin(
new Credentials(PASSWORD, "test", "password"),
null,
this.async_complete_full
);
test_article.initiate_session_async.end(async_result());
assert_int(1, test_article.get_personal_namespaces().size);
assert_string(
"INBOX.", test_article.get_personal_namespaces()[0].prefix
);
assert_int(1, test_article.get_shared_namespaces().size);
assert_string(
"shared.", test_article.get_shared_namespaces()[0].prefix
);
assert_int(1, test_article.get_other_users_namespaces().size);
assert_string(
"user.", test_article.get_other_users_namespaces()[0].prefix
);
test_article.disconnect_async.begin(null, this.async_complete_full);
test_article.disconnect_async.end(async_result());
TestServer.Result result = this.server.wait_for_script(this.main_loop);
assert_true(
result.succeeded,
result.error != null ? result.error.message : "Server result failed"
);
}
protected Endpoint new_endpoint() {
return new Endpoint(this.server.get_client_address(), NONE, 10);
}