2021-06-01 17:21:01 +04:00
|
|
|
/*
|
|
|
|
|
* 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:
|
2021-07-24 20:51:42 +01:00
|
|
|
static MailboxFlag parse_mailbox_flag(StringView);
|
2021-06-01 17:21:01 +04:00
|
|
|
|
2023-10-07 15:53:30 +01:00
|
|
|
ErrorOr<ParseStatus> try_parse(ByteBuffer&& buffer, bool expecting_tag);
|
|
|
|
|
|
|
|
|
|
ErrorOr<void> consume(StringView);
|
2023-10-07 23:43:06 +01:00
|
|
|
bool consume_if(StringView);
|
2021-07-24 20:45:27 +01:00
|
|
|
StringView consume_while(Function<bool(u8)> should_consume);
|
2021-07-24 20:54:30 +01:00
|
|
|
StringView consume_until_end_of_line();
|
2021-06-01 17:42:12 +04:00
|
|
|
|
2023-07-28 23:54:04 +03:00
|
|
|
bool at_end() { return m_position >= m_buffer.size(); }
|
2021-07-24 20:51:42 +01:00
|
|
|
|
2023-07-31 23:21:52 +03:00
|
|
|
ErrorOr<unsigned> parse_number();
|
2021-06-01 17:21:01 +04:00
|
|
|
Optional<unsigned> try_parse_number();
|
2021-06-01 17:42:12 +04:00
|
|
|
|
2023-10-07 15:53:30 +01:00
|
|
|
ErrorOr<void> parse_response_done();
|
|
|
|
|
ErrorOr<void> parse_untagged();
|
|
|
|
|
ErrorOr<void> parse_capability_response();
|
2021-06-01 17:42:12 +04:00
|
|
|
|
2023-11-07 13:34:12 +00:00
|
|
|
ErrorOr<StringView> parse_atom();
|
2023-10-07 15:53:30 +01:00
|
|
|
ErrorOr<StringView> parse_quoted_string();
|
|
|
|
|
ErrorOr<StringView> parse_literal_string();
|
|
|
|
|
ErrorOr<StringView> parse_string();
|
|
|
|
|
ErrorOr<StringView> parse_astring();
|
|
|
|
|
ErrorOr<StringView> parse_nstring();
|
2021-06-01 17:42:12 +04:00
|
|
|
|
2023-10-07 15:53:30 +01:00
|
|
|
ErrorOr<ResponseStatus> parse_status();
|
|
|
|
|
ErrorOr<ListItem> parse_list_item();
|
|
|
|
|
ErrorOr<FetchCommand::DataItem> parse_fetch_data_item();
|
|
|
|
|
ErrorOr<FetchResponseData> parse_fetch_response();
|
|
|
|
|
ErrorOr<Vector<Address>> parse_address_list();
|
|
|
|
|
ErrorOr<Address> parse_address();
|
2023-12-16 17:49:34 +03:30
|
|
|
ErrorOr<HashMap<ByteString, ByteString>> parse_body_fields_params();
|
2023-10-07 15:53:30 +01:00
|
|
|
ErrorOr<BodyStructure> parse_body_structure();
|
|
|
|
|
ErrorOr<BodyStructure> parse_one_part_body();
|
|
|
|
|
ErrorOr<BodyExtension> parse_body_extension();
|
2023-12-16 17:49:34 +03:30
|
|
|
ErrorOr<Tuple<ByteString, HashMap<ByteString, ByteString>>> parse_disposition();
|
|
|
|
|
ErrorOr<Vector<ByteString>> parse_langs();
|
2023-10-07 15:53:30 +01:00
|
|
|
ErrorOr<Envelope> parse_envelope();
|
2021-07-24 20:51:42 +01:00
|
|
|
|
|
|
|
|
template<typename T>
|
2023-10-07 15:53:30 +01:00
|
|
|
ErrorOr<Vector<T>> parse_list(T (*converter)(StringView));
|
2021-07-24 20:51:42 +01:00
|
|
|
|
|
|
|
|
// To retain state if parsing is not finished
|
|
|
|
|
ByteBuffer m_buffer;
|
|
|
|
|
SolidResponse m_response;
|
2023-07-28 23:54:04 +03:00
|
|
|
unsigned m_position { 0 };
|
2021-07-24 20:51:42 +01:00
|
|
|
bool m_incomplete { false };
|
2021-06-01 17:21:01 +04:00
|
|
|
};
|
|
|
|
|
}
|