1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:57:44 +00:00

LibIMAP+Userland: Convert LibIMAP::Client to the Serenity Stream APIs

You now cannot get an unconnected LibIMAP::Client, but you can still
close it. This makes for a nicer API where we don't have a Client object
in a limbo state between being constructed and being connected.

This code still isn't as nice as it should be, as TLS::TLSv12 is still
not a Core::Stream::Socket subclass, which would allow for consolidating
most of the TLS/non-TLS code into a single implementation.
This commit is contained in:
sin-ack 2021-12-18 12:38:44 +00:00 committed by Ali Mohammad Pur
parent 53e9d757fe
commit aedb013ee3
4 changed files with 162 additions and 94 deletions

View file

@ -126,12 +126,15 @@ bool MailWidget::connect_and_login()
return false;
}
m_imap_client = make<IMAP::Client>(server, port, tls);
auto connection_promise = m_imap_client->connect();
if (!connection_promise) {
GUI::MessageBox::show_error(window(), String::formatted("Failed to connect to '{}:{}' over {}.", server, port, tls ? "TLS" : "Plaintext"));
auto maybe_imap_client = tls ? IMAP::Client::connect_tls(server, port) : IMAP::Client::connect_plaintext(server, port);
if (maybe_imap_client.is_error()) {
GUI::MessageBox::show_error(window(), String::formatted("Failed to connect to '{}:{}' over {}: {}", server, port, tls ? "TLS" : "Plaintext", maybe_imap_client.error()));
return false;
}
m_imap_client = maybe_imap_client.release_value();
auto connection_promise = m_imap_client->connection_promise();
VERIFY(!connection_promise.is_null());
connection_promise->await();
auto response = m_imap_client->login(username, password)->await().release_value();