// IMAP Handler // // Douglas Thrift // // IMAPHandler.h #ifndef _IMAPHandler_h_ #define _IMAPHandler_h_ #include #include #include #include using namespace std; // Lovely C Sockets! #ifdef _WIN32 // Windows Sockets #include #include #else // BSD Sockets #include #include #include #include #include #define INVALID_SOCKET -1 #define SOCKET_ERROR -1 typedef int SOCKET; inline int closesocket(SOCKET s) { return close(s); } #endif // _WIN32 #include #include #include extern string program; extern bool debug; class IMAPHandler { private: #ifdef _WIN32 WSADATA data; #endif // _WIN32 SOCKET sock; SSL_CTX* ctx; SSL* ssl; bool tls; char* buffer; char letter; unsigned number; bool success; string command(); string imap(const string& imap); string imap(const string& imap, const string& args); string imap(const string& imap, const string& args, const string& message); void putline(const string line = ""); string getline(); void error(const string& prefix, bool host = false); void error(const string& prefix, int code); public: IMAPHandler(const string& server, bool tls = false); ~IMAPHandler(); string capability() { return imap("CAPABILITY"); } string starttls(); string noop() { return imap("NOOP"); } string logout() { return imap("LOGOUT"); } string login(const string& args) { return imap("LOGIN", args); } string select(const string& args) { return imap("select", args); } string examine(const string& args) { return imap("examine", args); } string create(const string& args) { return imap("create", args); } string delete_(const string& args) { return imap("delete", args); } string rename(const string& args) { return imap("rename", args); } string subscribe(const string& args) { return imap("subscribe", args); } string unsubscribe(const string& args) { return imap("unsubscribe", args); } string list(const string& args) { return imap("list", args); } string lsub(const string& args) { return imap("lsub", args); } string status_(const string& args) { return imap("status", args); } string append(const string& args, const string& message) { return imap("append", args, message); } string check() { return imap("check"); } string close() { return imap("close"); } string expunge() { return imap("expunge"); } string search(const string& args) { return imap("search", args); } string fetch(const string& args) { return imap("fetch", args); } string store(const string& args) { return imap("store", args); } string copy(const string& args) { return imap("copy", args); } string uid(const string& args) { return imap("uid", args); } bool successful() { return success; } }; #endif // _IMAPHandler_h_