1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:07:36 +00:00

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.
This commit is contained in:
x-yl 2021-06-01 17:21:01 +04:00 committed by Ali Mohammad Pur
parent 904322e754
commit 8c6061fc4a
8 changed files with 644 additions and 0 deletions

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2021, Kyle Pereira <hey@xylepereira.me>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/ByteBuffer.h>
#include <AK/Result.h>
#include <LibIMAP/Objects.h>
namespace IMAP {
class Client;
struct ParseStatus {
bool successful;
Optional<Response> response;
};
class Parser {
public:
ParseStatus parse(ByteBuffer&& buffer, bool expecting_tag);
private:
// To retain state if parsing is not finished
ByteBuffer m_buffer;
SolidResponse m_response;
unsigned position { 0 };
bool m_incomplete { false };
bool m_parsing_failed { false };
bool try_consume(StringView);
bool at_end() { return position >= m_buffer.size(); };
void parse_response_done();
void consume(StringView x);
unsigned parse_number();
Optional<unsigned> try_parse_number();
void parse_untagged();
StringView parse_atom();
ResponseStatus parse_status();
StringView parse_while(Function<bool(u8)> should_consume);
};
}