1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:58:12 +00:00

LibIMAP: Support for the LIST and SELECT commands

This commit is contained in:
x-yl 2021-06-01 18:39:50 +04:00 committed by Ali Mohammad Pur
parent 0f42ea6770
commit 2f04d24b66
5 changed files with 343 additions and 1 deletions

View file

@ -114,6 +114,10 @@ static ReadonlyBytes command_byte_buffer(CommandType command)
return "NOOP"sv.bytes();
case CommandType::Capability:
return "CAPABILITY"sv.bytes();
case CommandType::List:
return "LIST"sv.bytes();
case CommandType::Select:
return "SELECT"sv.bytes();
}
VERIFY_NOT_REACHED();
}
@ -143,12 +147,36 @@ RefPtr<Promise<Optional<Response>>> Client::send_command(Command&& command)
return promise;
}
template<typename T>
RefPtr<Promise<Optional<T>>> cast_promise(RefPtr<Promise<Optional<Response>>> promise_variant)
{
auto new_promise = promise_variant->map<Optional<T>>(
[](Optional<Response>& variant) {
return variant.has_value() ? move(variant->get<T>()) : Optional<T>();
});
return new_promise;
}
RefPtr<Promise<Optional<SolidResponse>>> Client::list(StringView reference_name, StringView mailbox)
{
auto command = Command { CommandType::List, m_current_command,
{ String::formatted("\"{}\"", reference_name),
String::formatted("\"{}\"", mailbox) } };
return cast_promise<SolidResponse>(send_command(move(command)));
}
RefPtr<Promise<Optional<Response>>> Client::send_simple_command(CommandType type)
{
auto command = Command { type, m_current_command, {} };
return send_command(move(command));
}
RefPtr<Promise<Optional<SolidResponse>>> Client::select(StringView string)
{
auto command = Command { CommandType::Select, m_current_command, { string } };
return cast_promise<SolidResponse>(send_command(move(command)));
}
void Client::handle_parsed_response(ParseStatus&& parse_status)
{
if (!m_expecting_response) {