mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
LibIMAP: Support for the LIST and SELECT commands
This commit is contained in:
parent
0f42ea6770
commit
2f04d24b66
5 changed files with 343 additions and 1 deletions
|
@ -18,11 +18,38 @@
|
|||
namespace IMAP {
|
||||
enum class CommandType {
|
||||
Capability,
|
||||
List,
|
||||
Noop,
|
||||
Select,
|
||||
};
|
||||
|
||||
enum class MailboxFlag : unsigned {
|
||||
All = 1u << 0,
|
||||
Drafts = 1u << 1,
|
||||
Flagged = 1u << 2,
|
||||
HasChildren = 1u << 3,
|
||||
HasNoChildren = 1u << 4,
|
||||
Important = 1u << 5,
|
||||
Junk = 1u << 6,
|
||||
Marked = 1u << 7,
|
||||
NoInferiors = 1u << 8,
|
||||
NoSelect = 1u << 9,
|
||||
Sent = 1u << 10,
|
||||
Trash = 1u << 11,
|
||||
Unmarked = 1u << 12,
|
||||
Unknown = 1u << 13,
|
||||
};
|
||||
|
||||
enum class ResponseType : unsigned {
|
||||
Capability = 1u << 0,
|
||||
List = 1u << 1,
|
||||
Exists = 1u << 2,
|
||||
Recent = 1u << 3,
|
||||
Flags = 1u << 4,
|
||||
UIDNext = 1u << 5,
|
||||
UIDValidity = 1u << 6,
|
||||
Unseen = 1u << 7,
|
||||
PermanentFlags = 1u << 8,
|
||||
};
|
||||
|
||||
class Parser;
|
||||
|
@ -40,6 +67,12 @@ enum class ResponseStatus {
|
|||
OK,
|
||||
};
|
||||
|
||||
struct ListItem {
|
||||
unsigned flags;
|
||||
String reference;
|
||||
String name;
|
||||
};
|
||||
|
||||
class ResponseData {
|
||||
public:
|
||||
[[nodiscard]] unsigned response_type() const
|
||||
|
@ -79,10 +112,116 @@ public:
|
|||
return m_capabilities;
|
||||
}
|
||||
|
||||
void add_list_item(ListItem&& item)
|
||||
{
|
||||
add_response_type(ResponseType::List);
|
||||
m_list_items.append(move(item));
|
||||
}
|
||||
|
||||
Vector<ListItem>& list_items()
|
||||
{
|
||||
VERIFY(contains_response_type(ResponseType::List));
|
||||
return m_list_items;
|
||||
}
|
||||
|
||||
void set_exists(unsigned exists)
|
||||
{
|
||||
add_response_type(ResponseType::Exists);
|
||||
m_exists = exists;
|
||||
}
|
||||
|
||||
[[nodiscard]] unsigned exists() const
|
||||
{
|
||||
VERIFY(contains_response_type(ResponseType::Exists));
|
||||
return m_exists;
|
||||
}
|
||||
|
||||
void set_recent(unsigned recent)
|
||||
{
|
||||
add_response_type(ResponseType::Recent);
|
||||
m_recent = recent;
|
||||
}
|
||||
|
||||
[[nodiscard]] unsigned recent() const
|
||||
{
|
||||
VERIFY(contains_response_type(ResponseType::Recent));
|
||||
return m_recent;
|
||||
}
|
||||
|
||||
void set_uid_next(unsigned uid_next)
|
||||
{
|
||||
add_response_type(ResponseType::UIDNext);
|
||||
m_uid_next = uid_next;
|
||||
}
|
||||
|
||||
[[nodiscard]] unsigned uid_next() const
|
||||
{
|
||||
VERIFY(contains_response_type(ResponseType::UIDNext));
|
||||
return m_uid_next;
|
||||
}
|
||||
|
||||
void set_uid_validity(unsigned uid_validity)
|
||||
{
|
||||
add_response_type(ResponseType::UIDValidity);
|
||||
m_uid_validity = uid_validity;
|
||||
}
|
||||
|
||||
[[nodiscard]] unsigned uid_validity() const
|
||||
{
|
||||
VERIFY(contains_response_type(ResponseType::UIDValidity));
|
||||
return m_uid_validity;
|
||||
}
|
||||
|
||||
void set_unseen(unsigned unseen)
|
||||
{
|
||||
add_response_type(ResponseType::Unseen);
|
||||
m_unseen = unseen;
|
||||
}
|
||||
|
||||
[[nodiscard]] unsigned unseen() const
|
||||
{
|
||||
VERIFY(contains_response_type(ResponseType::Unseen));
|
||||
return m_unseen;
|
||||
}
|
||||
|
||||
void set_flags(Vector<String>&& flags)
|
||||
{
|
||||
m_response_type |= static_cast<unsigned>(ResponseType::Flags);
|
||||
m_flags = move(flags);
|
||||
}
|
||||
|
||||
Vector<String>& flags()
|
||||
{
|
||||
VERIFY(contains_response_type(ResponseType::Flags));
|
||||
return m_flags;
|
||||
}
|
||||
|
||||
void set_permanent_flags(Vector<String>&& flags)
|
||||
{
|
||||
add_response_type(ResponseType::PermanentFlags);
|
||||
m_permanent_flags = move(flags);
|
||||
}
|
||||
|
||||
Vector<String>& permanent_flags()
|
||||
{
|
||||
VERIFY(contains_response_type(ResponseType::PermanentFlags));
|
||||
return m_permanent_flags;
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned m_response_type;
|
||||
|
||||
Vector<String> m_capabilities;
|
||||
Vector<ListItem> m_list_items;
|
||||
|
||||
unsigned m_recent {};
|
||||
unsigned m_exists {};
|
||||
|
||||
unsigned m_uid_next {};
|
||||
unsigned m_uid_validity {};
|
||||
unsigned m_unseen {};
|
||||
Vector<String> m_permanent_flags;
|
||||
Vector<String> m_flags;
|
||||
};
|
||||
|
||||
class SolidResponse {
|
||||
|
@ -154,7 +293,7 @@ public:
|
|||
|
||||
// Converts a Promise<A> to a Promise<B> using a function func: A -> B
|
||||
template<typename T>
|
||||
RefPtr<Promise<T>> map(Function<T(Result&)> func)
|
||||
RefPtr<Promise<T>> map(T func(Result&))
|
||||
{
|
||||
RefPtr<Promise<T>> new_promise = Promise<T>::construct();
|
||||
on_resolved = [new_promise, func](Result& result) mutable {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue