From ddd11b98d924d61ed4638b7623180edb606025ea Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 24 Jul 2021 20:54:30 +0100 Subject: [PATCH] LibIMAP: Add and use Parser::consume_until_end_of_line() --- Userland/Libraries/LibIMAP/Parser.cpp | 18 ++++++++++-------- Userland/Libraries/LibIMAP/Parser.h | 1 + 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibIMAP/Parser.cpp b/Userland/Libraries/LibIMAP/Parser.cpp index e7a5840858..3cdc856d6a 100644 --- a/Userland/Libraries/LibIMAP/Parser.cpp +++ b/Userland/Libraries/LibIMAP/Parser.cpp @@ -22,7 +22,7 @@ ParseStatus Parser::parse(ByteBuffer&& buffer, bool expecting_tag) if (try_consume("+")) { consume(" "); - auto data = consume_while([](u8 x) { return x != '\r'; }); + auto data = consume_until_end_of_line(); consume("\r\n"); return { true, { ContinueRequest { data } } }; } @@ -182,12 +182,9 @@ void Parser::parse_untagged() consume_while([](u8 x) { return x != ']'; }); } consume("]"); - consume_while([](u8 x) { return x != '\r'; }); - consume("\r\n"); - } else { - consume_while([](u8 x) { return x != '\r'; }); - consume("\r\n"); } + consume_until_end_of_line(); + consume("\r\n"); } else if (try_consume("SEARCH")) { Vector ids; while (!try_consume("\r\n")) { @@ -197,7 +194,7 @@ void Parser::parse_untagged() } m_response.data().set_search_results(move(ids)); } else if (try_consume("BYE")) { - auto message = consume_while([](u8 x) { return x != '\r'; }); + auto message = consume_until_end_of_line(); consume("\r\n"); m_response.data().set_bye(message.is_empty() ? Optional() : Optional(message)); } else if (try_consume("STATUS")) { @@ -236,7 +233,7 @@ void Parser::parse_untagged() try_consume(" "); // Not in the spec but the Outlook server sends a space for some reason. consume("\r\n"); } else { - auto x = consume_while([](u8 x) { return x != '\r'; }); + auto x = consume_until_end_of_line(); consume("\r\n"); dbgln("ignored {}", x); } @@ -687,6 +684,11 @@ StringView Parser::consume_while(Function should_consume) return StringView(m_buffer.data() + position - chars, chars); } +StringView Parser::consume_until_end_of_line() +{ + return consume_while([](u8 x) { return x != '\r'; }); +} + FetchCommand::DataItem Parser::parse_fetch_data_item() { auto msg_attr = consume_while([](u8 x) { return is_ascii_alpha(x) != 0; }); diff --git a/Userland/Libraries/LibIMAP/Parser.h b/Userland/Libraries/LibIMAP/Parser.h index 4ba1432336..281f3ce8d6 100644 --- a/Userland/Libraries/LibIMAP/Parser.h +++ b/Userland/Libraries/LibIMAP/Parser.h @@ -28,6 +28,7 @@ private: void consume(StringView); bool try_consume(StringView); StringView consume_while(Function should_consume); + StringView consume_until_end_of_line(); bool at_end() { return position >= m_buffer.size(); };