mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 11:17:34 +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();
|
||||
case CommandType::Capability:
|
||||
return "CAPABILITY"sv.bytes();
|
||||
case CommandType::Logout:
|
||||
return "LOGOUT"sv.bytes();
|
||||
case CommandType::Login:
|
||||
return "LOGIN"sv.bytes();
|
||||
case CommandType::List:
|
||||
return "LIST"sv.bytes();
|
||||
case CommandType::Select:
|
||||
|
@ -157,6 +161,12 @@ RefPtr<Promise<Optional<T>>> cast_promise(RefPtr<Promise<Optional<Response>>> pr
|
|||
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)
|
||||
{
|
||||
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_simple_command(CommandType);
|
||||
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>>> select(StringView string);
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@ namespace IMAP {
|
|||
enum class CommandType {
|
||||
Capability,
|
||||
List,
|
||||
Login,
|
||||
Logout,
|
||||
Noop,
|
||||
Select,
|
||||
};
|
||||
|
@ -50,6 +52,7 @@ enum class ResponseType : unsigned {
|
|||
UIDValidity = 1u << 6,
|
||||
Unseen = 1u << 7,
|
||||
PermanentFlags = 1u << 8,
|
||||
Bye = 1u << 13,
|
||||
};
|
||||
|
||||
class Parser;
|
||||
|
@ -208,6 +211,18 @@ public:
|
|||
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:
|
||||
unsigned m_response_type;
|
||||
|
||||
|
@ -222,6 +237,7 @@ private:
|
|||
unsigned m_unseen {};
|
||||
Vector<String> m_permanent_flags;
|
||||
Vector<String> m_flags;
|
||||
Optional<String> m_bye_message;
|
||||
};
|
||||
|
||||
class SolidResponse {
|
||||
|
|
|
@ -179,6 +179,10 @@ void Parser::parse_untagged()
|
|||
parse_while([](u8 x) { return x != '\r'; });
|
||||
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 {
|
||||
auto x = parse_while([](u8 x) { return x != '\r'; });
|
||||
consume("\r\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue