LibIMAP+Mail: Propagate errors from LibIMAP and MailWidget

This lets us bubble up errors from `LibIMAP::Client::send_command()`,
which can happen if the connection hangs or is taking a long time, and
the user closes Mail.
This commit is contained in:
Valtteri Koskivuori 2023-07-26 22:40:05 +03:00 committed by Andrew Kaster
parent fc54bd03f9
commit 6128e859ac
Notes: sideshowbarker 2024-07-17 08:36:27 +09:00
6 changed files with 90 additions and 89 deletions

View File

@ -96,7 +96,7 @@ MailWidget::MailWidget()
};
}
bool MailWidget::connect_and_login()
ErrorOr<bool> MailWidget::connect_and_login()
{
auto server = Config::read_string("Mail"sv, "Connection"sv, "Server"sv, {});
@ -117,6 +117,7 @@ bool MailWidget::connect_and_login()
return false;
}
// FIXME: Plaintext password storage, yikes!
auto password = Config::read_string("Mail"sv, "User"sv, "Password"sv, {});
while (password.is_empty()) {
if (GUI::PasswordInputDialog::show(window(), password, "Login"sv, server, username) != GUI::Dialog::ExecResult::OK)
@ -131,13 +132,12 @@ bool MailWidget::connect_and_login()
}
m_imap_client = maybe_imap_client.release_value();
auto connection_promise = m_imap_client->connection_promise();
VERIFY(!connection_promise.is_null());
MUST(connection_promise->await());
TRY(m_imap_client->connection_promise()->await());
auto response = MUST(m_imap_client->login(username, password)->await()).release_value();
m_statusbar->set_text(String::formatted("Connected. Logging in as {}...", username).release_value_but_fixme_should_propagate_errors());
auto response = TRY(TRY(m_imap_client->login(username, password))->await()).release_value();
if (response.status() != IMAP::ResponseStatus::OK) {
dbgln("Failed to login. The server says: '{}'", response.response_text());
GUI::MessageBox::show_error(window(), DeprecatedString::formatted("Failed to login. The server says: '{}'", response.response_text()));
@ -146,7 +146,7 @@ bool MailWidget::connect_and_login()
}
m_statusbar->set_text("Logged in. Loading mailboxes..."_string);
response = MUST(m_imap_client->list(""sv, "*"sv)->await()).release_value();
response = TRY(TRY(m_imap_client->list(""sv, "*"sv))->await()).release_value();
if (response.status() != IMAP::ResponseStatus::OK) {
dbgln("Failed to retrieve mailboxes. The server says: '{}'", response.response_text());
@ -173,7 +173,7 @@ void MailWidget::on_window_close()
// User closed main window before a connection was established
return;
}
auto response = move(MUST(m_imap_client->send_simple_command(IMAP::CommandType::Logout)->await()).release_value().get<IMAP::SolidResponse>());
auto response = move(MUST(MUST(m_imap_client->send_simple_command(IMAP::CommandType::Logout))->await()).release_value().get<IMAP::SolidResponse>());
VERIFY(response.status() == IMAP::ResponseStatus::OK);
m_imap_client->close();
@ -263,7 +263,7 @@ void MailWidget::selected_mailbox()
if (mailbox.flags & (unsigned)IMAP::MailboxFlag::NoSelect)
return;
auto response = MUST(m_imap_client->select(mailbox.name)->await()).release_value();
auto response = MUST(MUST(m_imap_client->select(mailbox.name))->await()).release_value();
if (response.status() != IMAP::ResponseStatus::OK) {
dbgln("Failed to select mailbox. The server says: '{}'", response.response_text());
@ -292,7 +292,7 @@ void MailWidget::selected_mailbox()
},
};
auto fetch_response = MUST(m_imap_client->fetch(fetch_command, false)->await()).release_value();
auto fetch_response = MUST(MUST(m_imap_client->fetch(fetch_command, false))->await()).release_value();
if (response.status() != IMAP::ResponseStatus::OK) {
dbgln("Failed to retrieve subject/from for e-mails. The server says: '{}'", response.response_text());
@ -441,7 +441,7 @@ void MailWidget::selected_email_to_load()
},
};
auto fetch_response = MUST(m_imap_client->fetch(fetch_command, false)->await()).release_value();
auto fetch_response = MUST(MUST(m_imap_client->fetch(fetch_command, false))->await()).release_value();
if (fetch_response.status() != IMAP::ResponseStatus::OK) {
dbgln("Failed to retrieve the body structure of the selected e-mail. The server says: '{}'", fetch_response.response_text());
@ -502,7 +502,7 @@ void MailWidget::selected_email_to_load()
},
};
fetch_response = MUST(m_imap_client->fetch(fetch_command, false)->await()).release_value();
fetch_response = MUST(MUST(m_imap_client->fetch(fetch_command, false))->await()).release_value();
if (fetch_response.status() != IMAP::ResponseStatus::OK) {
dbgln("Failed to retrieve the body of the selected e-mail. The server says: '{}'", fetch_response.response_text());

View File

@ -19,7 +19,7 @@ class MailWidget final : public GUI::Widget {
public:
virtual ~MailWidget() override = default;
bool connect_and_login();
ErrorOr<bool> connect_and_login();
void on_window_close();

View File

@ -63,9 +63,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->show();
bool should_continue = mail_widget->connect_and_login();
if (!should_continue)
bool should_continue = TRY(mail_widget->connect_and_login());
if (!should_continue) {
return 1;
}
return app->exec();
}

View File

@ -151,7 +151,7 @@ ErrorOr<void> Client::send_raw(StringView data)
return {};
}
RefPtr<Promise<Optional<Response>>> Client::send_command(Command&& command)
ErrorOr<RefPtr<Promise<Optional<Response>>>> Client::send_command(Command&& command)
{
m_command_queue.append(move(command));
m_current_command++;
@ -160,7 +160,7 @@ RefPtr<Promise<Optional<Response>>> Client::send_command(Command&& command)
m_pending_promises.append(promise);
if (m_pending_promises.size() == 1)
MUST(send_next_command());
TRY(send_next_command());
return promise;
}
@ -175,44 +175,44 @@ RefPtr<Promise<Optional<T>>> cast_promise(RefPtr<Promise<Optional<Response>>> pr
return new_promise;
}
RefPtr<Promise<Optional<SolidResponse>>> Client::login(StringView username, StringView password)
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::login(StringView username, StringView password)
{
auto command = Command { CommandType::Login, m_current_command, { serialize_astring(username), serialize_astring(password) } };
return cast_promise<SolidResponse>(send_command(move(command)));
return cast_promise<SolidResponse>(TRY(send_command(move(command))));
}
RefPtr<Promise<Optional<SolidResponse>>> Client::list(StringView reference_name, StringView mailbox)
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::list(StringView reference_name, StringView mailbox)
{
auto command = Command { CommandType::List, m_current_command,
{ DeprecatedString::formatted("\"{}\"", reference_name),
DeprecatedString::formatted("\"{}\"", mailbox) } };
return cast_promise<SolidResponse>(send_command(move(command)));
return cast_promise<SolidResponse>(TRY(send_command(move(command))));
}
RefPtr<Promise<Optional<SolidResponse>>> Client::lsub(StringView reference_name, StringView mailbox)
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::lsub(StringView reference_name, StringView mailbox)
{
auto command = Command { CommandType::ListSub, m_current_command,
{ DeprecatedString::formatted("\"{}\"", reference_name),
DeprecatedString::formatted("\"{}\"", mailbox) } };
return cast_promise<SolidResponse>(send_command(move(command)));
return cast_promise<SolidResponse>(TRY(send_command(move(command))));
}
RefPtr<Promise<Optional<SolidResponse>>> Client::fetch(FetchCommand request, bool uid)
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::fetch(FetchCommand request, bool uid)
{
auto command = Command { uid ? CommandType::UIDFetch : CommandType::Fetch, m_current_command, { request.serialize() } };
return cast_promise<SolidResponse>(send_command(move(command)));
return cast_promise<SolidResponse>(TRY(send_command(move(command))));
}
RefPtr<Promise<Optional<Response>>> Client::send_simple_command(CommandType type)
ErrorOr<RefPtr<Promise<Optional<Response>>>> Client::send_simple_command(CommandType type)
{
auto command = Command { type, m_current_command, {} };
return send_command(move(command));
return TRY(send_command(move(command)));
}
RefPtr<Promise<Optional<SolidResponse>>> Client::select(StringView string)
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::select(StringView string)
{
auto command = Command { CommandType::Select, m_current_command, { serialize_astring(string) } };
return cast_promise<SolidResponse>(send_command(move(command)));
return cast_promise<SolidResponse>(TRY(send_command(move(command))));
}
ErrorOr<void> Client::handle_parsed_response(ParseStatus&& parse_status)
@ -264,25 +264,25 @@ ErrorOr<void> Client::send_next_command()
return {};
}
RefPtr<Promise<Optional<SolidResponse>>> Client::examine(StringView string)
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::examine(StringView string)
{
auto command = Command { CommandType::Examine, m_current_command, { serialize_astring(string) } };
return cast_promise<SolidResponse>(send_command(move(command)));
return cast_promise<SolidResponse>(TRY(send_command(move(command))));
}
RefPtr<Promise<Optional<SolidResponse>>> Client::create_mailbox(StringView name)
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::create_mailbox(StringView name)
{
auto command = Command { CommandType::Create, m_current_command, { serialize_astring(name) } };
return cast_promise<SolidResponse>(send_command(move(command)));
return cast_promise<SolidResponse>(TRY(send_command(move(command))));
}
RefPtr<Promise<Optional<SolidResponse>>> Client::delete_mailbox(StringView name)
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::delete_mailbox(StringView name)
{
auto command = Command { CommandType::Delete, m_current_command, { serialize_astring(name) } };
return cast_promise<SolidResponse>(send_command(move(command)));
return cast_promise<SolidResponse>(TRY(send_command(move(command))));
}
RefPtr<Promise<Optional<SolidResponse>>> Client::store(StoreMethod method, Sequence sequence_set, bool silent, Vector<DeprecatedString> const& flags, bool uid)
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::store(StoreMethod method, Sequence sequence_set, bool silent, Vector<DeprecatedString> const& flags, bool uid)
{
StringBuilder data_item_name;
switch (method) {
@ -306,9 +306,9 @@ RefPtr<Promise<Optional<SolidResponse>>> Client::store(StoreMethod method, Seque
flags_builder.append(')');
auto command = Command { uid ? CommandType::UIDStore : CommandType::Store, m_current_command, { sequence_set.serialize(), data_item_name.to_deprecated_string(), flags_builder.to_deprecated_string() } };
return cast_promise<SolidResponse>(send_command(move(command)));
return cast_promise<SolidResponse>(TRY(send_command(move(command))));
}
RefPtr<Promise<Optional<SolidResponse>>> Client::search(Optional<DeprecatedString> charset, Vector<SearchKey>&& keys, bool uid)
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::search(Optional<DeprecatedString> charset, Vector<SearchKey>&& keys, bool uid)
{
Vector<DeprecatedString> args;
if (charset.has_value()) {
@ -319,15 +319,15 @@ RefPtr<Promise<Optional<SolidResponse>>> Client::search(Optional<DeprecatedStrin
args.append(item.serialize());
}
auto command = Command { uid ? CommandType::UIDSearch : CommandType::Search, m_current_command, args };
return cast_promise<SolidResponse>(send_command(move(command)));
return cast_promise<SolidResponse>(TRY(send_command(move(command))));
}
RefPtr<Promise<Optional<ContinueRequest>>> Client::idle()
ErrorOr<RefPtr<Promise<Optional<ContinueRequest>>>> Client::idle()
{
auto promise = send_simple_command(CommandType::Idle);
auto promise = TRY(send_simple_command(CommandType::Idle));
return cast_promise<ContinueRequest>(promise);
}
RefPtr<Promise<Optional<SolidResponse>>> Client::finish_idle()
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::finish_idle()
{
auto promise = Promise<Optional<Response>>::construct();
m_pending_promises.append(promise);
@ -336,7 +336,7 @@ RefPtr<Promise<Optional<SolidResponse>>> Client::finish_idle()
return cast_promise<SolidResponse>(promise);
}
RefPtr<Promise<Optional<SolidResponse>>> Client::status(StringView mailbox, Vector<StatusItemType> const& types)
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::status(StringView mailbox, Vector<StatusItemType> const& types)
{
Vector<DeprecatedString> args;
for (auto type : types) {
@ -363,10 +363,10 @@ RefPtr<Promise<Optional<SolidResponse>>> Client::status(StringView mailbox, Vect
types_list.join(' ', args);
types_list.append(')');
auto command = Command { CommandType::Status, m_current_command, { mailbox, types_list.to_deprecated_string() } };
return cast_promise<SolidResponse>(send_command(move(command)));
return cast_promise<SolidResponse>(TRY(send_command(move(command))));
}
RefPtr<Promise<Optional<SolidResponse>>> Client::append(StringView mailbox, Message&& message, Optional<Vector<DeprecatedString>> flags, Optional<Core::DateTime> date_time)
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::append(StringView mailbox, Message&& message, Optional<Vector<DeprecatedString>> flags, Optional<Core::DateTime> date_time)
{
Vector<DeprecatedString> args = { mailbox };
if (flags.has_value()) {
@ -381,7 +381,7 @@ RefPtr<Promise<Optional<SolidResponse>>> Client::append(StringView mailbox, Mess
args.append(DeprecatedString::formatted("{{{}}}", message.data.length()));
auto continue_req = send_command(Command { CommandType::Append, m_current_command, args });
auto continue_req = TRY(send_command(Command { CommandType::Append, m_current_command, args }));
auto response_promise = Promise<Optional<Response>>::construct();
m_pending_promises.append(response_promise);
@ -398,33 +398,33 @@ RefPtr<Promise<Optional<SolidResponse>>> Client::append(StringView mailbox, Mess
return cast_promise<SolidResponse>(response_promise);
}
RefPtr<Promise<Optional<SolidResponse>>> Client::subscribe(StringView mailbox)
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::subscribe(StringView mailbox)
{
auto command = Command { CommandType::Subscribe, m_current_command, { serialize_astring(mailbox) } };
return cast_promise<SolidResponse>(send_command(move(command)));
return cast_promise<SolidResponse>(TRY(send_command(move(command))));
}
RefPtr<Promise<Optional<SolidResponse>>> Client::unsubscribe(StringView mailbox)
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::unsubscribe(StringView mailbox)
{
auto command = Command { CommandType::Unsubscribe, m_current_command, { serialize_astring(mailbox) } };
return cast_promise<SolidResponse>(send_command(move(command)));
return cast_promise<SolidResponse>(TRY(send_command(move(command))));
}
RefPtr<Promise<Optional<Response>>> Client::authenticate(StringView method)
ErrorOr<RefPtr<Promise<Optional<Response>>>> Client::authenticate(StringView method)
{
auto command = Command { CommandType::Authenticate, m_current_command, { method } };
return send_command(move(command));
return TRY(send_command(move(command)));
}
RefPtr<Promise<Optional<SolidResponse>>> Client::rename(StringView from, StringView to)
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::rename(StringView from, StringView to)
{
auto command = Command { CommandType::Rename, m_current_command, { serialize_astring(from), serialize_astring(to) } };
return cast_promise<SolidResponse>(send_command(move(command)));
return cast_promise<SolidResponse>(TRY(send_command(move(command))));
}
RefPtr<Promise<Optional<SolidResponse>>> Client::copy(Sequence sequence_set, StringView name, bool uid)
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> Client::copy(Sequence sequence_set, StringView name, bool uid)
{
auto command = Command {
uid ? CommandType::UIDCopy : CommandType::Copy, m_current_command, { sequence_set.serialize(), serialize_astring(name) }
};
return cast_promise<SolidResponse>(send_command(move(command)));
return cast_promise<SolidResponse>(TRY(send_command(move(command))));
}
void Client::close()

View File

@ -30,28 +30,28 @@ public:
return m_connect_pending;
}
RefPtr<Promise<Optional<Response>>> send_command(Command&&);
RefPtr<Promise<Optional<Response>>> send_simple_command(CommandType);
ErrorOr<RefPtr<Promise<Optional<Response>>>> send_command(Command&&);
ErrorOr<RefPtr<Promise<Optional<Response>>>> send_simple_command(CommandType);
ErrorOr<void> send_raw(StringView data);
RefPtr<Promise<Optional<SolidResponse>>> login(StringView username, StringView password);
RefPtr<Promise<Optional<SolidResponse>>> list(StringView reference_name, StringView mailbox_name);
RefPtr<Promise<Optional<SolidResponse>>> lsub(StringView reference_name, StringView mailbox_name);
RefPtr<Promise<Optional<SolidResponse>>> select(StringView string);
RefPtr<Promise<Optional<SolidResponse>>> examine(StringView string);
RefPtr<Promise<Optional<SolidResponse>>> search(Optional<DeprecatedString> charset, Vector<SearchKey>&& search_keys, bool uid);
RefPtr<Promise<Optional<SolidResponse>>> fetch(FetchCommand request, bool uid);
RefPtr<Promise<Optional<SolidResponse>>> store(StoreMethod, Sequence, bool silent, Vector<DeprecatedString> const& flags, bool uid);
RefPtr<Promise<Optional<SolidResponse>>> copy(Sequence sequence_set, StringView name, bool uid);
RefPtr<Promise<Optional<SolidResponse>>> create_mailbox(StringView name);
RefPtr<Promise<Optional<SolidResponse>>> delete_mailbox(StringView name);
RefPtr<Promise<Optional<SolidResponse>>> subscribe(StringView mailbox);
RefPtr<Promise<Optional<SolidResponse>>> unsubscribe(StringView mailbox);
RefPtr<Promise<Optional<SolidResponse>>> rename(StringView from, StringView to);
RefPtr<Promise<Optional<Response>>> authenticate(StringView method);
RefPtr<Promise<Optional<ContinueRequest>>> idle();
RefPtr<Promise<Optional<SolidResponse>>> finish_idle();
RefPtr<Promise<Optional<SolidResponse>>> status(StringView mailbox, Vector<StatusItemType> const& types);
RefPtr<Promise<Optional<SolidResponse>>> append(StringView mailbox, Message&& message, Optional<Vector<DeprecatedString>> flags = {}, Optional<Core::DateTime> date_time = {});
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> login(StringView username, StringView password);
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> list(StringView reference_name, StringView mailbox_name);
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> lsub(StringView reference_name, StringView mailbox_name);
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> select(StringView string);
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> examine(StringView string);
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> search(Optional<DeprecatedString> charset, Vector<SearchKey>&& search_keys, bool uid);
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> fetch(FetchCommand request, bool uid);
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> store(StoreMethod, Sequence, bool silent, Vector<DeprecatedString> const& flags, bool uid);
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> copy(Sequence sequence_set, StringView name, bool uid);
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> create_mailbox(StringView name);
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> delete_mailbox(StringView name);
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> subscribe(StringView mailbox);
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> unsubscribe(StringView mailbox);
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> rename(StringView from, StringView to);
ErrorOr<RefPtr<Promise<Optional<Response>>>> authenticate(StringView method);
ErrorOr<RefPtr<Promise<Optional<ContinueRequest>>>> idle();
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> finish_idle();
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> status(StringView mailbox, Vector<StatusItemType> const& types);
ErrorOr<RefPtr<Promise<Optional<SolidResponse>>>> append(StringView mailbox, Message&& message, Optional<Vector<DeprecatedString>> flags = {}, Optional<Core::DateTime> date_time = {});
bool is_open();
void close();

View File

@ -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(TRY(client->login(username, password.view()))->await()).release_value();
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(TRY(client->send_simple_command(IMAP::CommandType::Capability))->await()).value().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(TRY(client->list(""sv, "*"sv))->await()).release_value();
outln("[LIST] First mailbox: {}", response.data().list_items().first().name);
auto mailbox = "Inbox"sv;
response = TRY(client->select(mailbox)->await()).release_value();
response = TRY(TRY(client->select(mailbox))->await()).release_value();
outln("[SELECT] Select response: {}", response.response_text());
auto message = Message {
@ -70,7 +70,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
"This is a message just to say hello.\r\n"
"So, \"Hello\"."
};
auto promise = client->append("INBOX"sv, move(message));
auto promise = TRY(client->append("INBOX"sv, move(message)));
response = TRY(promise->await()).release_value();
outln("[APPEND] Response: {}", response.response_text());
@ -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(TRY(client->search({}, move(keys), false))->await()).release_value();
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(TRY(client->status("INBOX"sv, { IMAP::StatusItemType::Recent, IMAP::StatusItemType::Messages }))->await()).release_value();
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(TRY(client->fetch(fetch_command, false))->await()).release_value();
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(TRY(client->store(IMAP::StoreMethod::Add, { static_cast<int>(added_message), static_cast<int>(added_message) }, false, { "\\Deleted" }, false))->await()).release_value();
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(TRY(client->send_simple_command(IMAP::CommandType::Expunge))->await()).release_value().get<IMAP::SolidResponse>());
outln("[EXPUNGE] Number of expunged entries: {}", response.data().expunged().size());
if (idle_supported) {
VERIFY(TRY(client->idle()->await()).has_value());
VERIFY(TRY(TRY(client->idle())->await()).has_value());
sleep(3);
response = TRY(client->finish_idle()->await()).release_value();
response = TRY(TRY(client->finish_idle())->await()).release_value();
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(TRY(client->send_simple_command(IMAP::CommandType::Logout))->await()).release_value().get<IMAP::SolidResponse>());
outln("[LOGOUT] Bye: {}", response.data().bye_message().value());
client->close();