/* * Copyright (c) 2021, Kyle Pereira * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include namespace IMAP { class Client; struct ParseStatus { bool successful; Optional 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 try_parse_number(); void parse_untagged(); StringView parse_atom(); StringView parse_quoted_string(); StringView parse_string(); Optional parse_nstring(); ResponseStatus parse_status(); template Vector parse_list(T (*converter)(StringView)); static MailboxFlag parse_mailbox_flag(StringView s); StringView parse_while(Function should_consume); void parse_capability_response(); ListItem parse_list_item(); FetchCommand::DataItem parse_fetch_data_item(); FetchResponseData parse_fetch_response(); StringView parse_literal_string(); Optional> parse_address_list(); Address parse_address(); StringView parse_astring(); HashMap parse_body_fields_params(); BodyStructure parse_body_structure(); BodyStructure parse_one_part_body(); Tuple> parse_disposition(); Vector parse_langs(); BodyExtension parse_body_extension(); Envelope parse_envelope(); }; }