summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibIMAP/Client.h
diff options
context:
space:
mode:
authorx-yl <kylepereira@mail.com>2021-06-01 17:21:01 +0400
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-06-11 23:58:28 +0430
commit8c6061fc4af79984e2c9fbbb2300567a9f5ebbfe (patch)
tree0dd70e8c5bf45482b79e3db002c56a524d02cbca /Userland/Libraries/LibIMAP/Client.h
parent904322e75400eabe00f60d74f2c08d03cdb9d3a2 (diff)
downloadserenity-8c6061fc4af79984e2c9fbbb2300567a9f5ebbfe.zip
LibIMAP: Add a new IMAP client and support NOOP
A large commit, but sets up the framework for how the IMAP library will work. Right now only the NOOP command and response is supported.
Diffstat (limited to 'Userland/Libraries/LibIMAP/Client.h')
-rw-r--r--Userland/Libraries/LibIMAP/Client.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/Userland/Libraries/LibIMAP/Client.h b/Userland/Libraries/LibIMAP/Client.h
new file mode 100644
index 0000000000..1481d92eb7
--- /dev/null
+++ b/Userland/Libraries/LibIMAP/Client.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2021, Kyle Pereira <hey@xylepereira.me>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Function.h>
+#include <LibIMAP/Parser.h>
+#include <LibTLS/TLSv12.h>
+
+namespace IMAP {
+class Client {
+ friend class Parser;
+
+public:
+ Client(StringView host, unsigned port, bool start_with_tls);
+
+ Optional<RefPtr<Promise<Empty>>> connect();
+ RefPtr<Promise<Optional<Response>>> send_command(Command&&);
+ RefPtr<Promise<Optional<Response>>> send_simple_command(CommandType);
+ void send_raw(StringView data);
+ void close();
+
+ Function<void(ResponseData&&)> unrequested_response_callback;
+
+private:
+ StringView m_host;
+ unsigned m_port;
+ RefPtr<Core::Socket> m_socket;
+ RefPtr<TLS::TLSv12> m_tls_socket;
+
+ void on_ready_to_receive();
+ void on_tls_ready_to_receive();
+
+ bool m_tls;
+ int m_current_command = 1;
+
+ bool connect_tls();
+ bool connect_plaintext();
+
+ // Sent but response not received
+ Vector<RefPtr<Promise<Optional<Response>>>> m_pending_promises;
+ // Not yet sent
+ Vector<Command> m_command_queue {};
+
+ RefPtr<Promise<bool>> m_connect_pending {};
+
+ ByteBuffer m_buffer;
+ Parser m_parser;
+
+ bool m_expecting_response { false };
+ void handle_parsed_response(ParseStatus&& parse_status);
+ void send_next_command();
+};
+}