mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:57:44 +00:00
LibIMAP: Support for APPEND
This commit is contained in:
parent
7021413d30
commit
16995dc3d9
3 changed files with 35 additions and 0 deletions
|
@ -144,6 +144,8 @@ static ReadonlyBytes command_byte_buffer(CommandType command)
|
|||
return "UID COPY"sv.bytes();
|
||||
case CommandType::UIDSearch:
|
||||
return "UID SEARCH"sv.bytes();
|
||||
case CommandType::Append:
|
||||
return "APPEND"sv.bytes();
|
||||
case CommandType::Rename:
|
||||
return "RENAME"sv.bytes();
|
||||
case CommandType::Status:
|
||||
|
@ -360,6 +362,37 @@ RefPtr<Promise<Optional<SolidResponse>>> Client::status(StringView mailbox, Vect
|
|||
return cast_promise<SolidResponse>(send_command(move(command)));
|
||||
}
|
||||
|
||||
RefPtr<Promise<Optional<SolidResponse>>> Client::append(StringView mailbox, Message&& message, Optional<Vector<String>> flags, Optional<Core::DateTime> date_time)
|
||||
{
|
||||
Vector<String> args = { mailbox };
|
||||
if (flags.has_value()) {
|
||||
StringBuilder flags_sb;
|
||||
flags_sb.append('(');
|
||||
flags_sb.join(" ", flags.value());
|
||||
flags_sb.append(')');
|
||||
args.append(flags_sb.build());
|
||||
}
|
||||
if (date_time.has_value())
|
||||
args.append(date_time.value().to_string("\"%d-%b-%Y %H:%M:%S +0000\""));
|
||||
|
||||
args.append(String::formatted("{{{}}}", message.data.length()));
|
||||
|
||||
auto continue_req = send_command(Command { CommandType::Append, m_current_command, args });
|
||||
|
||||
auto response_promise = Promise<Optional<Response>>::construct();
|
||||
m_pending_promises.append(response_promise);
|
||||
|
||||
continue_req->on_resolved = [this, message2 { move(message) }](auto& data) {
|
||||
if (!data.has_value()) {
|
||||
handle_parsed_response({ .successful = false, .response = {} });
|
||||
} else {
|
||||
send_raw(message2.data);
|
||||
m_expecting_response = true;
|
||||
}
|
||||
};
|
||||
|
||||
return cast_promise<SolidResponse>(response_promise);
|
||||
}
|
||||
RefPtr<Promise<Optional<SolidResponse>>> Client::rename(StringView from, StringView to)
|
||||
{
|
||||
auto command = Command { CommandType::Rename, m_current_command, { from, to } };
|
||||
|
|
|
@ -34,6 +34,7 @@ public:
|
|||
RefPtr<Promise<Optional<ContinueRequest>>> idle();
|
||||
RefPtr<Promise<Optional<SolidResponse>>> finish_idle();
|
||||
RefPtr<Promise<Optional<SolidResponse>>> status(StringView mailbox, Vector<StatusItemType> const& types);
|
||||
RefPtr<Promise<Optional<SolidResponse>>> append(StringView mailbox, Message&& message, Optional<Vector<String>> flags = {}, Optional<Core::DateTime> date_time = {});
|
||||
|
||||
void close();
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
namespace IMAP {
|
||||
enum class CommandType {
|
||||
Append,
|
||||
Capability,
|
||||
Copy,
|
||||
Create,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue