mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:07:35 +00:00
LibIMAP+Mail+test-imap: Let a Promise result type be non-optional
The Empty type was used only when parsing a response failed. The failures will now go to Promise's error type.
This commit is contained in:
parent
1f605407bd
commit
90af21aef4
4 changed files with 71 additions and 72 deletions
|
@ -46,18 +46,18 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto client = TRY(tls ? IMAP::Client::connect_tls(host, port) : IMAP::Client::connect_plaintext(host, port));
|
||||
TRY(client->connection_promise()->await());
|
||||
|
||||
auto response = TRY(client->login(username, password.view())->await()).release_value();
|
||||
auto response = TRY(client->login(username, password.view())->await());
|
||||
outln("[LOGIN] Login response: {}", response.response_text());
|
||||
|
||||
response = move(TRY(client->send_simple_command(IMAP::CommandType::Capability)->await()).value().get<IMAP::SolidResponse>());
|
||||
response = move(TRY(client->send_simple_command(IMAP::CommandType::Capability)->await()).get<IMAP::SolidResponse>());
|
||||
outln("[CAPABILITY] First capability: {}", response.data().capabilities().first());
|
||||
bool idle_supported = !response.data().capabilities().find_if([](auto capability) { return capability.equals_ignoring_ascii_case("IDLE"sv); }).is_end();
|
||||
|
||||
response = TRY(client->list(""sv, "*"sv)->await()).release_value();
|
||||
response = TRY(client->list(""sv, "*"sv)->await());
|
||||
outln("[LIST] First mailbox: {}", response.data().list_items().first().name);
|
||||
|
||||
auto mailbox = "Inbox"sv;
|
||||
response = TRY(client->select(mailbox)->await()).release_value();
|
||||
response = TRY(client->select(mailbox)->await());
|
||||
outln("[SELECT] Select response: {}", response.response_text());
|
||||
|
||||
auto message = Message {
|
||||
|
@ -71,7 +71,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
"So, \"Hello\"."
|
||||
};
|
||||
auto promise = client->append("INBOX"sv, move(message));
|
||||
response = TRY(promise->await()).release_value();
|
||||
response = TRY(promise->await());
|
||||
outln("[APPEND] Response: {}", response.response_text());
|
||||
|
||||
Vector<IMAP::SearchKey> keys;
|
||||
|
@ -79,13 +79,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
IMAP::SearchKey::From { "jdoe@machine.example" } });
|
||||
keys.append(IMAP::SearchKey {
|
||||
IMAP::SearchKey::Subject { "Saying Hello" } });
|
||||
response = TRY(client->search({}, move(keys), false)->await()).release_value();
|
||||
response = TRY(client->search({}, move(keys), false)->await());
|
||||
|
||||
Vector<unsigned> search_results = move(response.data().search_results());
|
||||
auto added_message = search_results.first();
|
||||
outln("[SEARCH] Number of results: {}", search_results.size());
|
||||
|
||||
response = TRY(client->status("INBOX"sv, { IMAP::StatusItemType::Recent, IMAP::StatusItemType::Messages })->await()).release_value();
|
||||
response = TRY(client->status("INBOX"sv, { IMAP::StatusItemType::Recent, IMAP::StatusItemType::Messages })->await());
|
||||
outln("[STATUS] Recent items: {}", response.data().status_item().get(IMAP::StatusItemType::Recent));
|
||||
|
||||
for (auto item : search_results) {
|
||||
|
@ -118,7 +118,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
};
|
||||
// clang-format on
|
||||
|
||||
auto fetch_response = TRY(client->fetch(fetch_command, false)->await()).release_value();
|
||||
auto fetch_response = TRY(client->fetch(fetch_command, false)->await());
|
||||
outln("[FETCH] Subject of search result: {}",
|
||||
fetch_response.data()
|
||||
.fetch_data()
|
||||
|
@ -136,22 +136,22 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
// FIXME: There is a discrepancy between IMAP::Sequence wanting signed ints
|
||||
// and IMAP search results returning unsigned ones. Find which one is
|
||||
// more correct and fix this.
|
||||
response = TRY(client->store(IMAP::StoreMethod::Add, { static_cast<int>(added_message), static_cast<int>(added_message) }, false, { "\\Deleted" }, false)->await()).release_value();
|
||||
response = TRY(client->store(IMAP::StoreMethod::Add, { static_cast<int>(added_message), static_cast<int>(added_message) }, false, { "\\Deleted" }, false)->await());
|
||||
outln("[STORE] Store response: {}", response.response_text());
|
||||
|
||||
response = move(TRY(client->send_simple_command(IMAP::CommandType::Expunge)->await()).release_value().get<IMAP::SolidResponse>());
|
||||
response = move(TRY(client->send_simple_command(IMAP::CommandType::Expunge)->await()).get<IMAP::SolidResponse>());
|
||||
outln("[EXPUNGE] Number of expunged entries: {}", response.data().expunged().size());
|
||||
|
||||
if (idle_supported) {
|
||||
VERIFY(TRY(client->idle()->await()).has_value());
|
||||
VERIFY(!client->idle()->await().is_error());
|
||||
sleep(3);
|
||||
response = TRY(client->finish_idle()->await()).release_value();
|
||||
response = TRY(client->finish_idle()->await());
|
||||
outln("[IDLE] Idle response: {}", response.response_text());
|
||||
} else {
|
||||
outln("[IDLE] Skipped. No IDLE support.");
|
||||
}
|
||||
|
||||
response = move(TRY(client->send_simple_command(IMAP::CommandType::Logout)->await()).release_value().get<IMAP::SolidResponse>());
|
||||
response = move(TRY(client->send_simple_command(IMAP::CommandType::Logout)->await()).get<IMAP::SolidResponse>());
|
||||
outln("[LOGOUT] Bye: {}", response.data().bye_message().value());
|
||||
|
||||
client->close();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue