/** * @file operators.h * @brief Declaration of all operators. * @author Andreas Aardal Hanssen, Erwin Hoffmann * @date 2002-2005, 2023 */ #ifndef operators_h_included #define operators_h_included #include "depot.h" #include "imapparser.h" #include "message.h" #include #include namespace Binc { class Operator { public: enum ProcessResult { OK, BAD, NO, NOTHING, ABORT }; enum ParseResult { ACCEPT, REJECT, ERROR, TIMEOUT }; virtual ProcessResult process(Depot &, Request &) = 0; virtual ParseResult parse(Request &) const = 0; virtual int getState() const = 0; virtual const std::string getName() const = 0; virtual ~Operator(){}; }; class AppendOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; AppendOperator(); ~AppendOperator(); }; class AuthenticateOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; ProcessResult Login(std::string &username, std::string &password); ProcessResult Plain(std::string &username, std::string &password); ProcessResult Cram(std::string &username, std::string &password, std::string &challenge); AuthenticateOperator(); ~AuthenticateOperator(); }; class CapabilityOperator : public Operator { std::vector capabilities; public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; void addCapability(const std::string &cap); CapabilityOperator(); ~CapabilityOperator(); }; class CheckOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; CheckOperator(); ~CheckOperator(); }; class CreateOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; CreateOperator(); ~CreateOperator(); }; class CloseOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; CloseOperator(); ~CloseOperator(); }; class CopyOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; CopyOperator(); ~CopyOperator(); }; class DeleteOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; DeleteOperator(); ~DeleteOperator(); }; class ExpungeOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; ExpungeOperator(); ~ExpungeOperator(); }; class FetchOperator : public Operator { protected: ParseResult expectSectionText(BincImapParserFetchAtt &f_in) const; ParseResult expectSection(BincImapParserFetchAtt &f_in) const; ParseResult expectFetchAtt(BincImapParserFetchAtt &f_in) const; ParseResult expectOffset(BincImapParserFetchAtt &f_in) const; ParseResult expectHeaderList(BincImapParserFetchAtt &f_in) const; public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; FetchOperator(); ~FetchOperator(); }; class IdOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; IdOperator(); ~IdOperator(); }; class IdleOperator : public Operator { protected: ParseResult expectSectionText(BincImapParserFetchAtt &f_in) const; ParseResult expectSection(BincImapParserFetchAtt &f_in) const; ParseResult expectFetchAtt(BincImapParserFetchAtt &f_in) const; ParseResult expectOffset(BincImapParserFetchAtt &f_in) const; ParseResult expectHeaderList(BincImapParserFetchAtt &f_in) const; public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; IdleOperator(); ~IdleOperator(); }; class ListOperator : public Operator { protected: enum MailboxFlags { DIR_SELECT = 0x01, DIR_MARKED = 0x02, DIR_NOINFERIORS = 0x04, DIR_LEAF = 0x08 }; std::map cache; time_t cacheTimeout; public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; ListOperator(); ~ListOperator(); }; class LoginOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; LoginOperator(); ~LoginOperator(); }; class LogoutOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; LogoutOperator(); ~LogoutOperator(); }; class LsubOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; LsubOperator(); ~LsubOperator(); }; class NamespaceOperator : public Operator { public: virtual ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; NamespaceOperator(); ~NamespaceOperator(); }; class NoopOperator : public Operator { public: virtual ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; NoopOperator(); ~NoopOperator(); }; class NoopPendingOperator : public NoopOperator { public: ProcessResult process(Depot &, Request &); NoopPendingOperator(); ~NoopPendingOperator(); }; class RenameOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; RenameOperator(); ~RenameOperator(); }; class SearchOperator : public Operator { protected: ParseResult expectSearchKey(BincImapParserSearchKey &s_in) const; class SearchNode { std::string date; std::string astring; std::string bstring; unsigned int number; int type; mutable int weight; const SequenceSet *bset; std::vector children; public: enum { S_ALL, S_ANSWERED, S_BCC, S_BEFORE, S_BODY, S_CC, S_DELETED, S_FLAGGED, S_FROM, S_KEYWORD, S_NEW, S_OLD, S_ON, S_RECENT, S_SEEN, S_SINCE, S_SUBJECT, S_TEXT, S_TO, S_UNANSWERED, S_UNDELETED, S_UNFLAGGED, S_UNKEYWORD, S_UNSEEN, S_DRAFT, S_HEADER, S_LARGER, S_NOT, S_OR, S_SENTBEFORE, S_SENTON, S_SENTSINCE, S_SMALLER, S_UID, S_UNDRAFT, S_SET, S_AND }; static bool convertDate(const std::string &date, time_t &t, const std::string &delim = "-"); static bool convertDateHeader(const std::string &d_in, time_t &t); void order(); bool match(Mailbox *, Message *, unsigned seqnr, unsigned int lastmessage, unsigned int lastuid) const; int getType() const; int getWeight() const; void setWeight(int i); void init(const BincImapParserSearchKey &a); static bool compareNodes(const SearchNode &a, const SearchNode &b) { return a.getWeight() < b.getWeight(); } SearchNode(); SearchNode(const BincImapParserSearchKey &a); }; public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; SearchOperator(); ~SearchOperator(); }; class SelectOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; SelectOperator(); ~SelectOperator(); }; class ExamineOperator : public SelectOperator { public: const std::string getName() const; ExamineOperator(); ~ExamineOperator(); }; class StarttlsOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; int goStartTLS() const; StarttlsOperator(); ~StarttlsOperator(); }; class StatusOperator : public Operator { std::map statuses; public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; StatusOperator(); ~StatusOperator(); }; class StoreOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; StoreOperator(); ~StoreOperator(); }; class SubscribeOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; SubscribeOperator(); ~SubscribeOperator(); }; class UnsubscribeOperator : public Operator { public: ProcessResult process(Depot &, Request &); virtual ParseResult parse(Request &) const; const std::string getName() const; int getState() const; UnsubscribeOperator(); ~UnsubscribeOperator(); }; } #endif