Skip to content

Commit f00c2c0

Browse files
X-ylalimpfard
authored andcommitted
LibIMAP: Support for LOGIN and LOGOUT
1 parent 2f04d24 commit f00c2c0

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

Userland/Libraries/LibIMAP/Client.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ static ReadonlyBytes command_byte_buffer(CommandType command)
114114
return "NOOP"sv.bytes();
115115
case CommandType::Capability:
116116
return "CAPABILITY"sv.bytes();
117+
case CommandType::Logout:
118+
return "LOGOUT"sv.bytes();
119+
case CommandType::Login:
120+
return "LOGIN"sv.bytes();
117121
case CommandType::List:
118122
return "LIST"sv.bytes();
119123
case CommandType::Select:
@@ -157,6 +161,12 @@ RefPtr<Promise<Optional<T>>> cast_promise(RefPtr<Promise<Optional<Response>>> pr
157161
return new_promise;
158162
}
159163

164+
RefPtr<Promise<Optional<SolidResponse>>> Client::login(StringView username, StringView password)
165+
{
166+
auto command = Command { CommandType::Login, m_current_command, { username, password } };
167+
return cast_promise<SolidResponse>(send_command(move(command)));
168+
}
169+
160170
RefPtr<Promise<Optional<SolidResponse>>> Client::list(StringView reference_name, StringView mailbox)
161171
{
162172
auto command = Command { CommandType::List, m_current_command,

Userland/Libraries/LibIMAP/Client.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Client {
2121
RefPtr<Promise<Optional<Response>>> send_command(Command&&);
2222
RefPtr<Promise<Optional<Response>>> send_simple_command(CommandType);
2323
void send_raw(StringView data);
24+
RefPtr<Promise<Optional<SolidResponse>>> login(StringView username, StringView password);
2425
RefPtr<Promise<Optional<SolidResponse>>> list(StringView reference_name, StringView mailbox_name);
2526
RefPtr<Promise<Optional<SolidResponse>>> select(StringView string);
2627

Userland/Libraries/LibIMAP/Objects.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace IMAP {
1919
enum class CommandType {
2020
Capability,
2121
List,
22+
Login,
23+
Logout,
2224
Noop,
2325
Select,
2426
};
@@ -50,6 +52,7 @@ enum class ResponseType : unsigned {
5052
UIDValidity = 1u << 6,
5153
Unseen = 1u << 7,
5254
PermanentFlags = 1u << 8,
55+
Bye = 1u << 13,
5356
};
5457

5558
class Parser;
@@ -208,6 +211,18 @@ class ResponseData {
208211
return m_permanent_flags;
209212
}
210213

214+
void set_bye(Optional<String> message)
215+
{
216+
add_response_type(ResponseType::Bye);
217+
m_bye_message = move(message);
218+
}
219+
220+
Optional<String>& bye_message()
221+
{
222+
VERIFY(contains_response_type(ResponseType::Bye));
223+
return m_bye_message;
224+
}
225+
211226
private:
212227
unsigned m_response_type;
213228

@@ -222,6 +237,7 @@ class ResponseData {
222237
unsigned m_unseen {};
223238
Vector<String> m_permanent_flags;
224239
Vector<String> m_flags;
240+
Optional<String> m_bye_message;
225241
};
226242

227243
class SolidResponse {

Userland/Libraries/LibIMAP/Parser.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ void Parser::parse_untagged()
179179
parse_while([](u8 x) { return x != '\r'; });
180180
consume("\r\n");
181181
}
182+
} else if (try_consume("BYE")) {
183+
auto message = parse_while([](u8 x) { return x != '\r'; });
184+
consume("\r\n");
185+
m_response.data().set_bye(message.is_empty() ? Optional<String>() : Optional<String>(message));
182186
} else {
183187
auto x = parse_while([](u8 x) { return x != '\r'; });
184188
consume("\r\n");

0 commit comments

Comments
 (0)