mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 09:17:36 +00:00
LibIMAP: Support for LOGIN and LOGOUT
This commit is contained in:
parent
2f04d24b66
commit
f00c2c0192
4 changed files with 31 additions and 0 deletions
|
@ -114,6 +114,10 @@ static ReadonlyBytes command_byte_buffer(CommandType command)
|
||||||
return "NOOP"sv.bytes();
|
return "NOOP"sv.bytes();
|
||||||
case CommandType::Capability:
|
case CommandType::Capability:
|
||||||
return "CAPABILITY"sv.bytes();
|
return "CAPABILITY"sv.bytes();
|
||||||
|
case CommandType::Logout:
|
||||||
|
return "LOGOUT"sv.bytes();
|
||||||
|
case CommandType::Login:
|
||||||
|
return "LOGIN"sv.bytes();
|
||||||
case CommandType::List:
|
case CommandType::List:
|
||||||
return "LIST"sv.bytes();
|
return "LIST"sv.bytes();
|
||||||
case CommandType::Select:
|
case CommandType::Select:
|
||||||
|
@ -157,6 +161,12 @@ RefPtr<Promise<Optional<T>>> cast_promise(RefPtr<Promise<Optional<Response>>> pr
|
||||||
return new_promise;
|
return new_promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RefPtr<Promise<Optional<SolidResponse>>> Client::login(StringView username, StringView password)
|
||||||
|
{
|
||||||
|
auto command = Command { CommandType::Login, m_current_command, { username, password } };
|
||||||
|
return cast_promise<SolidResponse>(send_command(move(command)));
|
||||||
|
}
|
||||||
|
|
||||||
RefPtr<Promise<Optional<SolidResponse>>> Client::list(StringView reference_name, StringView mailbox)
|
RefPtr<Promise<Optional<SolidResponse>>> Client::list(StringView reference_name, StringView mailbox)
|
||||||
{
|
{
|
||||||
auto command = Command { CommandType::List, m_current_command,
|
auto command = Command { CommandType::List, m_current_command,
|
||||||
|
|
|
@ -21,6 +21,7 @@ public:
|
||||||
RefPtr<Promise<Optional<Response>>> send_command(Command&&);
|
RefPtr<Promise<Optional<Response>>> send_command(Command&&);
|
||||||
RefPtr<Promise<Optional<Response>>> send_simple_command(CommandType);
|
RefPtr<Promise<Optional<Response>>> send_simple_command(CommandType);
|
||||||
void send_raw(StringView data);
|
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>>> list(StringView reference_name, StringView mailbox_name);
|
||||||
RefPtr<Promise<Optional<SolidResponse>>> select(StringView string);
|
RefPtr<Promise<Optional<SolidResponse>>> select(StringView string);
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,8 @@ namespace IMAP {
|
||||||
enum class CommandType {
|
enum class CommandType {
|
||||||
Capability,
|
Capability,
|
||||||
List,
|
List,
|
||||||
|
Login,
|
||||||
|
Logout,
|
||||||
Noop,
|
Noop,
|
||||||
Select,
|
Select,
|
||||||
};
|
};
|
||||||
|
@ -50,6 +52,7 @@ enum class ResponseType : unsigned {
|
||||||
UIDValidity = 1u << 6,
|
UIDValidity = 1u << 6,
|
||||||
Unseen = 1u << 7,
|
Unseen = 1u << 7,
|
||||||
PermanentFlags = 1u << 8,
|
PermanentFlags = 1u << 8,
|
||||||
|
Bye = 1u << 13,
|
||||||
};
|
};
|
||||||
|
|
||||||
class Parser;
|
class Parser;
|
||||||
|
@ -208,6 +211,18 @@ public:
|
||||||
return m_permanent_flags;
|
return m_permanent_flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_bye(Optional<String> message)
|
||||||
|
{
|
||||||
|
add_response_type(ResponseType::Bye);
|
||||||
|
m_bye_message = move(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<String>& bye_message()
|
||||||
|
{
|
||||||
|
VERIFY(contains_response_type(ResponseType::Bye));
|
||||||
|
return m_bye_message;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned m_response_type;
|
unsigned m_response_type;
|
||||||
|
|
||||||
|
@ -222,6 +237,7 @@ private:
|
||||||
unsigned m_unseen {};
|
unsigned m_unseen {};
|
||||||
Vector<String> m_permanent_flags;
|
Vector<String> m_permanent_flags;
|
||||||
Vector<String> m_flags;
|
Vector<String> m_flags;
|
||||||
|
Optional<String> m_bye_message;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SolidResponse {
|
class SolidResponse {
|
||||||
|
|
|
@ -179,6 +179,10 @@ void Parser::parse_untagged()
|
||||||
parse_while([](u8 x) { return x != '\r'; });
|
parse_while([](u8 x) { return x != '\r'; });
|
||||||
consume("\r\n");
|
consume("\r\n");
|
||||||
}
|
}
|
||||||
|
} else if (try_consume("BYE")) {
|
||||||
|
auto message = parse_while([](u8 x) { return x != '\r'; });
|
||||||
|
consume("\r\n");
|
||||||
|
m_response.data().set_bye(message.is_empty() ? Optional<String>() : Optional<String>(message));
|
||||||
} else {
|
} else {
|
||||||
auto x = parse_while([](u8 x) { return x != '\r'; });
|
auto x = parse_while([](u8 x) { return x != '\r'; });
|
||||||
consume("\r\n");
|
consume("\r\n");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue