diff options
Diffstat (limited to 'src/operator-search.cc')
-rw-r--r-- | src/operator-search.cc | 195 |
1 files changed, 98 insertions, 97 deletions
diff --git a/src/operator-search.cc b/src/operator-search.cc index 1da4ee7..500e254 100644 --- a/src/operator-search.cc +++ b/src/operator-search.cc @@ -527,40 +527,40 @@ Operator::ProcessResult SearchOperator::process(Depot &depot, Request &command) return Operator::ProcessResult::OK; } -Parser::ParseResult SearchOperator::parse(Request &c_in) +Parser::ParseResult SearchOperator::parse(Request &c_in, Parser &p) { constexpr auto ACCEPT = Parser::ParseResult::ACCEPT; Session &session = Session::getInstance(); Parser::ParseResult res; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectThisString("CHARSET")) == ACCEPT) { - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectThisString("CHARSET")) == ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE after CHARSET"); return res; } string charset; - if ((res = expectAstring(charset)) != ACCEPT) { + if ((res = p.expectAstring(charset)) != ACCEPT) { session.setLastError("Expected astring after CHARSET SPACE"); return res; } c_in.setCharSet(charset); - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE after CHARSET SPACE astring"); return res; } } BincImapParserSearchKey b; - if ((res = expectSearchKey(b)) != ACCEPT) { + if ((res = expectSearchKey(b, p)) != ACCEPT) { session.setLastError("Expected search_key"); return res; } @@ -569,10 +569,10 @@ Parser::ParseResult SearchOperator::parse(Request &c_in) c_in.searchkey.children.push_back(b); while (1) { - if ((res = expectSPACE()) != ACCEPT) break; + if ((res = p.expectSPACE()) != ACCEPT) break; BincImapParserSearchKey c; - if ((res = expectSearchKey(c)) != ACCEPT) { + if ((res = expectSearchKey(c, p)) != ACCEPT) { session.setLastError("Expected search_key after search_key SPACE"); return res; } @@ -580,7 +580,7 @@ Parser::ParseResult SearchOperator::parse(Request &c_in) c_in.searchkey.children.push_back(c); } - if ((res = expectCRLF()) != ACCEPT) { + if ((res = p.expectCRLF()) != ACCEPT) { session.setLastError("Expected CRLF after search_key"); return res; } @@ -589,7 +589,8 @@ Parser::ParseResult SearchOperator::parse(Request &c_in) return ACCEPT; } -Parser::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in) const +Parser::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s_in, + Parser &p) const { constexpr auto ACCEPT = Parser::ParseResult::ACCEPT; @@ -597,322 +598,322 @@ Parser::ParseResult SearchOperator::expectSearchKey(BincImapParserSearchKey &s_i Parser::ParseResult res; s_in.type = BincImapParserSearchKey::KEY_OTHER; - if ((res = expectThisString("ALL")) == ACCEPT) { + if ((res = p.expectThisString("ALL")) == ACCEPT) { s_in.name = "ALL"; - } else if ((res = expectThisString("ANSWERED")) == ACCEPT) { + } else if ((res = p.expectThisString("ANSWERED")) == ACCEPT) { s_in.name = "ANSWERED"; - } else if ((res = expectThisString("BCC")) == ACCEPT) { + } else if ((res = p.expectThisString("BCC")) == ACCEPT) { s_in.name = "BCC"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectAstring(s_in.astring)) != ACCEPT) { + if ((res = p.expectAstring(s_in.astring)) != ACCEPT) { session.setLastError("Expected astring"); return res; } - } else if ((res = expectThisString("BEFORE")) == ACCEPT) { + } else if ((res = p.expectThisString("BEFORE")) == ACCEPT) { s_in.name = "BEFORE"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectDate(s_in.date)) != ACCEPT) { + if ((res = p.expectDate(s_in.date)) != ACCEPT) { session.setLastError("Expected date"); return res; } - } else if ((res = expectThisString("BODY")) == ACCEPT) { + } else if ((res = p.expectThisString("BODY")) == ACCEPT) { s_in.name = "BODY"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectAstring(s_in.astring)) != ACCEPT) { + if ((res = p.expectAstring(s_in.astring)) != ACCEPT) { session.setLastError("Expected astring"); return res; } - } else if ((res = expectThisString("CC")) == ACCEPT) { + } else if ((res = p.expectThisString("CC")) == ACCEPT) { s_in.name = "CC"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectAstring(s_in.astring)) != ACCEPT) { + if ((res = p.expectAstring(s_in.astring)) != ACCEPT) { session.setLastError("Expected astring"); return res; } - } else if ((res = expectThisString("DELETED")) == ACCEPT) { + } else if ((res = p.expectThisString("DELETED")) == ACCEPT) { s_in.name = "DELETED"; - } else if ((res = expectThisString("FLAGGED")) == ACCEPT) { + } else if ((res = p.expectThisString("FLAGGED")) == ACCEPT) { s_in.name = "FLAGGED"; - } else if ((res = expectThisString("FROM")) == ACCEPT) { + } else if ((res = p.expectThisString("FROM")) == ACCEPT) { s_in.name = "FROM"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectAstring(s_in.astring)) != ACCEPT) { + if ((res = p.expectAstring(s_in.astring)) != ACCEPT) { session.setLastError("Expected astring"); return res; } - } else if ((res = expectThisString("KEYWORD")) == ACCEPT) { + } else if ((res = p.expectThisString("KEYWORD")) == ACCEPT) { s_in.name = "KEYWORD"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectAtom(s_in.astring)) != ACCEPT) { + if ((res = p.expectAtom(s_in.astring)) != ACCEPT) { session.setLastError("Expected flag_keyword"); return res; } - } else if ((res = expectThisString("NEW")) == ACCEPT) { + } else if ((res = p.expectThisString("NEW")) == ACCEPT) { s_in.name = "NEW"; - } else if ((res = expectThisString("OLD")) == ACCEPT) { + } else if ((res = p.expectThisString("OLD")) == ACCEPT) { s_in.name = "OLD"; - } else if ((res = expectThisString("ON")) == ACCEPT) { + } else if ((res = p.expectThisString("ON")) == ACCEPT) { s_in.name = "ON"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectDate(s_in.date)) != ACCEPT) { + if ((res = p.expectDate(s_in.date)) != ACCEPT) { session.setLastError("Expected date"); return res; } - } else if ((res = expectThisString("RECENT")) == ACCEPT) { + } else if ((res = p.expectThisString("RECENT")) == ACCEPT) { s_in.name = "RECENT"; - } else if ((res = expectThisString("SEEN")) == ACCEPT) { + } else if ((res = p.expectThisString("SEEN")) == ACCEPT) { s_in.name = "SEEN"; - } else if ((res = expectThisString("SINCE")) == ACCEPT) { + } else if ((res = p.expectThisString("SINCE")) == ACCEPT) { s_in.name = "SINCE"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectDate(s_in.date)) != ACCEPT) { + if ((res = p.expectDate(s_in.date)) != ACCEPT) { session.setLastError("Expected date"); return res; } - } else if ((res = expectThisString("SUBJECT")) == ACCEPT) { + } else if ((res = p.expectThisString("SUBJECT")) == ACCEPT) { s_in.name = "SUBJECT"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectAstring(s_in.astring)) != ACCEPT) { + if ((res = p.expectAstring(s_in.astring)) != ACCEPT) { session.setLastError("Expected astring"); return res; } - } else if ((res = expectThisString("TEXT")) == ACCEPT) { + } else if ((res = p.expectThisString("TEXT")) == ACCEPT) { s_in.name = "TEXT"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectAstring(s_in.astring)) != ACCEPT) { + if ((res = p.expectAstring(s_in.astring)) != ACCEPT) { session.setLastError("Expected astring"); return res; } - } else if ((res = expectThisString("TO")) == ACCEPT) { + } else if ((res = p.expectThisString("TO")) == ACCEPT) { s_in.name = "TO"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectAstring(s_in.astring)) != ACCEPT) { + if ((res = p.expectAstring(s_in.astring)) != ACCEPT) { session.setLastError("Expected astring"); return res; } - } else if ((res = expectThisString("UNANSWERED")) == ACCEPT) { + } else if ((res = p.expectThisString("UNANSWERED")) == ACCEPT) { s_in.name = "UNANSWERED"; - } else if ((res = expectThisString("UNDELETED")) == ACCEPT) { + } else if ((res = p.expectThisString("UNDELETED")) == ACCEPT) { s_in.name = "UNDELETED"; - } else if ((res = expectThisString("UNFLAGGED")) == ACCEPT) { + } else if ((res = p.expectThisString("UNFLAGGED")) == ACCEPT) { s_in.name = "UNFLAGGED"; - } else if ((res = expectThisString("UNKEYWORD")) == ACCEPT) { + } else if ((res = p.expectThisString("UNKEYWORD")) == ACCEPT) { s_in.name = "UNKEYWORD"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectAtom(s_in.astring)) != ACCEPT) { + if ((res = p.expectAtom(s_in.astring)) != ACCEPT) { session.setLastError("Expected flag_keyword"); return res; } - } else if ((res = expectThisString("UNSEEN")) == ACCEPT) { + } else if ((res = p.expectThisString("UNSEEN")) == ACCEPT) { s_in.name = "UNSEEN"; - } else if ((res = expectThisString("DRAFT")) == ACCEPT) { + } else if ((res = p.expectThisString("DRAFT")) == ACCEPT) { s_in.name = "DRAFT"; - } else if ((res = expectThisString("HEADER")) == ACCEPT) { + } else if ((res = p.expectThisString("HEADER")) == ACCEPT) { s_in.name = "HEADER"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectAstring(s_in.astring)) != ACCEPT) { + if ((res = p.expectAstring(s_in.astring)) != ACCEPT) { session.setLastError("Expected astring"); return res; } - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectAstring(s_in.bstring)) != ACCEPT) { + if ((res = p.expectAstring(s_in.bstring)) != ACCEPT) { session.setLastError("Expected astring"); return res; } - } else if ((res = expectThisString("LARGER")) == ACCEPT) { + } else if ((res = p.expectThisString("LARGER")) == ACCEPT) { s_in.name = "LARGER"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectNumber(s_in.number)) != ACCEPT) { + if ((res = p.expectNumber(s_in.number)) != ACCEPT) { session.setLastError("Expected number"); return res; } - } else if ((res = expectThisString("NOT")) == ACCEPT) { + } else if ((res = p.expectThisString("NOT")) == ACCEPT) { s_in.name = "NOT"; s_in.type = BincImapParserSearchKey::KEY_NOT; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } BincImapParserSearchKey s; - if ((res = expectSearchKey(s)) != ACCEPT) { + if ((res = expectSearchKey(s, p)) != ACCEPT) { session.setLastError("Expected search_key"); return res; } s_in.children.push_back(s); - } else if ((res = expectThisString("OR")) == ACCEPT) { + } else if ((res = p.expectThisString("OR")) == ACCEPT) { s_in.name = "OR"; s_in.type = BincImapParserSearchKey::KEY_OR; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } BincImapParserSearchKey s; - if ((res = expectSearchKey(s)) != ACCEPT) { + if ((res = expectSearchKey(s, p)) != ACCEPT) { session.setLastError("Expected search_key"); return res; } s_in.children.push_back(s); - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } BincImapParserSearchKey t; - if ((res = expectSearchKey(t)) != ACCEPT) { + if ((res = expectSearchKey(t, p)) != ACCEPT) { session.setLastError("Expected search_key"); return res; } s_in.children.push_back(t); - } else if ((res = expectThisString("SENTBEFORE")) == ACCEPT) { + } else if ((res = p.expectThisString("SENTBEFORE")) == ACCEPT) { s_in.name = "SENTBEFORE"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectDate(s_in.date)) != ACCEPT) { + if ((res = p.expectDate(s_in.date)) != ACCEPT) { session.setLastError("Expected date"); return res; } - } else if ((res = expectThisString("SENTON")) == ACCEPT) { + } else if ((res = p.expectThisString("SENTON")) == ACCEPT) { s_in.name = "SENTON"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectDate(s_in.date)) != ACCEPT) { + if ((res = p.expectDate(s_in.date)) != ACCEPT) { session.setLastError("Expected date"); return res; } - } else if ((res = expectThisString("SENTSINCE")) == ACCEPT) { + } else if ((res = p.expectThisString("SENTSINCE")) == ACCEPT) { s_in.name = "SENTSINCE"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectDate(s_in.date)) != ACCEPT) { + if ((res = p.expectDate(s_in.date)) != ACCEPT) { session.setLastError("Expected date"); return res; } - } else if ((res = expectThisString("SMALLER")) == ACCEPT) { + } else if ((res = p.expectThisString("SMALLER")) == ACCEPT) { s_in.name = "SMALLER"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectNumber(s_in.number)) != ACCEPT) { + if ((res = p.expectNumber(s_in.number)) != ACCEPT) { session.setLastError("Expected number"); return res; } - } else if ((res = expectThisString("UID")) == ACCEPT) { + } else if ((res = p.expectThisString("UID")) == ACCEPT) { s_in.name = "UID"; - if ((res = expectSPACE()) != ACCEPT) { + if ((res = p.expectSPACE()) != ACCEPT) { session.setLastError("Expected SPACE"); return res; } - if ((res = expectSet(s_in.bset)) != ACCEPT) { + if ((res = p.expectSet(s_in.bset)) != ACCEPT) { session.setLastError("Expected number"); return res; } - } else if ((res = expectThisString("UNDRAFT")) == ACCEPT) { + } else if ((res = p.expectThisString("UNDRAFT")) == ACCEPT) { s_in.name = "UNDRAFT"; - } else if ((res = expectSet(s_in.bset)) == ACCEPT) { + } else if ((res = p.expectSet(s_in.bset)) == ACCEPT) { s_in.name = ""; s_in.type = BincImapParserSearchKey::KEY_SET; - } else if ((res = expectThisString("(")) == ACCEPT) { + } else if ((res = p.expectThisString("(")) == ACCEPT) { s_in.type = BincImapParserSearchKey::KEY_AND; while (1) { BincImapParserSearchKey c; - if ((res = expectSearchKey(c)) != ACCEPT) { + if ((res = expectSearchKey(c, p)) != ACCEPT) { session.setLastError("Expected search_key"); return res; } s_in.children.push_back(c); - if ((res = expectSPACE()) != ACCEPT) break; + if ((res = p.expectSPACE()) != ACCEPT) break; } - if ((res = expectThisString(")")) != ACCEPT) { + if ((res = p.expectThisString(")")) != ACCEPT) { session.setLastError("Expected )"); return res; } |