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

LibIMAP: Support for CAPABILITY command & response

This involves parsing messages with untagged responses
This commit is contained in:
x-yl 2021-06-01 17:42:12 +04:00 committed by Ali Mohammad Pur
parent ac712b07f9
commit 0f42ea6770
4 changed files with 55 additions and 0 deletions

View file

@ -27,6 +27,10 @@ ParseStatus Parser::parse(ByteBuffer&& buffer, bool expecting_tag)
return { true, { ContinueRequest { data } } };
}
while (try_consume("*")) {
parse_untagged();
}
if (expecting_tag) {
if (at_end()) {
m_incomplete = true;
@ -117,6 +121,30 @@ unsigned Parser::parse_number()
return number.value();
}
void Parser::parse_untagged()
{
consume(" ");
if (try_consume("CAPABILITY")) {
parse_capability_response();
} else {
auto x = parse_while([](u8 x) { return x != '\r'; });
consume("\r\n");
dbgln("ignored {}", x);
}
}
void Parser::parse_capability_response()
{
auto capability = AK::Vector<String>();
while (!try_consume("\r\n")) {
consume(" ");
auto x = String(parse_atom());
capability.append(x);
}
m_response.data().add_capabilities(move(capability));
}
StringView Parser::parse_atom()
{
auto is_non_atom_char = [](u8 x) {