소스 검색

LibIMAP: Support for the IDLE command

x-yl 4 년 전
부모
커밋
1e9dfdcdcc
3개의 변경된 파일18개의 추가작업 그리고 0개의 파일을 삭제
  1. 15 0
      Userland/Libraries/LibIMAP/Client.cpp
  2. 2 0
      Userland/Libraries/LibIMAP/Client.h
  3. 1 0
      Userland/Libraries/LibIMAP/Objects.h

+ 15 - 0
Userland/Libraries/LibIMAP/Client.cpp

@@ -116,6 +116,8 @@ static ReadonlyBytes command_byte_buffer(CommandType command)
         return "CAPABILITY"sv.bytes();
     case CommandType::Logout:
         return "LOGOUT"sv.bytes();
+    case CommandType ::Idle:
+        return "IDLE"sv.bytes();
     case CommandType::Login:
         return "LOGIN"sv.bytes();
     case CommandType::List:
@@ -232,6 +234,19 @@ void Client::send_next_command()
     send_raw(buffer);
     m_expecting_response = true;
 }
+RefPtr<Promise<Optional<ContinueRequest>>> Client::idle()
+{
+    auto promise = send_simple_command(CommandType::Idle);
+    return cast_promise<ContinueRequest>(promise);
+}
+RefPtr<Promise<Optional<SolidResponse>>> Client::finish_idle()
+{
+    auto promise = Promise<Optional<Response>>::construct();
+    m_pending_promises.append(promise);
+    send_raw("DONE");
+    m_expecting_response = true;
+    return cast_promise<SolidResponse>(promise);
+}
 
 void Client::close()
 {

+ 2 - 0
Userland/Libraries/LibIMAP/Client.h

@@ -24,6 +24,8 @@ public:
     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);
+    RefPtr<Promise<Optional<ContinueRequest>>> idle();
+    RefPtr<Promise<Optional<SolidResponse>>> finish_idle();
 
     void close();
 

+ 1 - 0
Userland/Libraries/LibIMAP/Objects.h

@@ -18,6 +18,7 @@
 namespace IMAP {
 enum class CommandType {
     Capability,
+    Idle,
     List,
     Login,
     Logout,