diff --git a/BMAMail b/BMAMail index c014706..ff2a408 100755 Binary files a/BMAMail and b/BMAMail differ diff --git a/IMAPCommand.cpp b/IMAPCommand.cpp index 4ea5c46..e12497b 100644 --- a/IMAPCommand.cpp +++ b/IMAPCommand.cpp @@ -5,10 +5,8 @@ namespace mail { - int IMAPCommand::processCommand(std::string request, core::TCPSession *session, std::stringstream &data) { - coreutils::PString parser(request); - parser.split(" "); - return processCommand(parser, (IMAPSession &)*session, (IMAPServer &)session->server, data); + int IMAPCommand::processCommand(coreutils::ZString &request, core::TCPSession &session) { + return processCommand(request, (IMAPSession &)session, (IMAPServer &)session.server); } } diff --git a/IMAPCommand.h b/IMAPCommand.h index d2c4aec..89e8840 100644 --- a/IMAPCommand.h +++ b/IMAPCommand.h @@ -11,8 +11,8 @@ namespace mail { class IMAPCommand : public core::Command { public: - virtual int processCommand(std::string request, core::TCPSession *session, std::stringstream &data) override; - virtual int processCommand(coreutils::PString request, IMAPSession &session, IMAPServer &server, std::stringstream &data) { return 0; } + virtual int processCommand(coreutils::ZString &request, core::TCPSession &session) override; + virtual int processCommand(coreutils::ZString &request, IMAPSession &session, IMAPServer &server) { return 0; } }; diff --git a/IMAPServer.h b/IMAPServer.h index 91c3276..e80cc85 100644 --- a/IMAPServer.h +++ b/IMAPServer.h @@ -33,7 +33,7 @@ namespace mail { public: IMAPServer(core::EPoll &epoll, std::string hostName, MailFileSystem &mailFileSystem, core::IPAddress ipAddress) - : TCPServer(epoll, ipAddress, "IMAP Server"), mailFileSystem(mailFileSystem), hostName(hostName) { + : TCPServer(epoll, ipAddress, " ", 10, "IMAP Server"), mailFileSystem(mailFileSystem), hostName(hostName) { commands.add(_imap_append, "APPEND"); commands.add(_imap_authenticate, "AUTHENTCATE"); commands.add(_imap_check, "CHECK"); diff --git a/MailFileSystem.h b/MailFileSystem.h index 5aa6978..d61a67f 100644 --- a/MailFileSystem.h +++ b/MailFileSystem.h @@ -4,8 +4,8 @@ # include # include # include -# include "EPoll.h" # include "INotify.h" +# include "ZString.h" namespace mail { @@ -29,7 +29,7 @@ namespace mail { } std::string getMailBoxPath(std::string mailbox) { - coreutils::PString email(mailbox); + coreutils::ZString email(mailbox); email.split("@"); std::string path = mailPath + "/" + email[1].str() + "/" + email[0].str(); return path; diff --git a/POP3Command.h b/POP3Command.h index dad6a6f..a6e179e 100644 --- a/POP3Command.h +++ b/POP3Command.h @@ -6,16 +6,17 @@ # include "POP3Session.h" namespace mail { + + class POP3Server; class POP3Command : public core::Command { public: - virtual int processCommand(std::string request, core::TCPSession *session, std::stringstream &data) override { - coreutils::PString parser(request); - return processCommand(parser, (POP3Session &)*session, data); + virtual int processCommand(coreutils::ZString &request, core::TCPSession &session) override { + return processCommand(request, (POP3Session &)session, (POP3Server &)session.server); } - virtual int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) { + virtual int processCommand(coreutils::ZString request, POP3Session &session, POP3Server &server) { return 0; } diff --git a/POP3Server.h b/POP3Server.h index 14d46b1..3864a6b 100644 --- a/POP3Server.h +++ b/POP3Server.h @@ -22,7 +22,7 @@ namespace mail { public: POP3Server(core::EPoll &epoll, std::string hostName, MailFileSystem &mailFileSystem, core::IPAddress ipAddress) - : TCPServer(epoll, ipAddress, "POP3 Server"), mailFileSystem(mailFileSystem), hostName(hostName) { + : TCPServer(epoll, ipAddress, " ", 10, "POP3 Server"), mailFileSystem(mailFileSystem), hostName(hostName) { commands.add(_pop3_dele, "DELE"); commands.add(_pop3_last, "LAST"); commands.add(_pop3_list, "LIST"); diff --git a/POP3Session.h b/POP3Session.h index 037461c..d2f70da 100644 --- a/POP3Session.h +++ b/POP3Session.h @@ -10,9 +10,8 @@ namespace mail { std::string userName; std::string password; AuthState authstate = USER_UNKNOWN; - bool relay = false; - - + bool relay = false; + }; } diff --git a/SMTPCommand.h b/SMTPCommand.h new file mode 100644 index 0000000..ce96663 --- /dev/null +++ b/SMTPCommand.h @@ -0,0 +1,37 @@ +#ifndef __SMTPCommand_h__ +# define __SMTPCommand_h__ + +# include "Command.h" +# include "SMTPSession.h" + +#define CRLF "\r\n" + +namespace mail { + + class SMTPServer; + + class SMTPCommand : public core::Command { + + public: + + virtual int processCommand(coreutils::ZString &request, core::TCPSession &session) override { + return processCommand(request, (SMTPSession &)session, (SMTPServer &)session.server); + } + + virtual int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) { + return 0; + } + + void grabInput(SMTPSession &session) { + session.server.commands.grabInput(session, *this); + } + + void clearGrab(SMTPSession &session) { + session.server.commands.clearGrab(session); + } + + }; + +} + +#endif diff --git a/SMTPServer.h b/SMTPServer.h index bde4dea..743cc7a 100644 --- a/SMTPServer.h +++ b/SMTPServer.h @@ -25,7 +25,7 @@ namespace mail { public: SMTPServer(core::EPoll &ePoll, std::string hostName, MailFileSystem &mailFileSystem, core::IPAddress ipAddress) - : core::TCPServer(ePoll, ipAddress, "SMTP Server"), core::INotify(ePoll), hostName(hostName), mailFileSystem(mailFileSystem) { + : core::TCPServer(ePoll, ipAddress, " ", 10, "SMTP Server"), core::INotify(ePoll), hostName(hostName), mailFileSystem(mailFileSystem) { commands.add(_smtp_auth, "AUTH"); commands.add(_smtp_data, "DATA"); commands.add(_smtp_ehlo, "EHLO"); @@ -49,23 +49,23 @@ namespace mail { } void sessionErrorHandler(std::string errorString, std::stringstream &out) { - out << "252 " << errorString << CRLF; + out << "252 " << errorString << CRLF; } protected: void inCreate(std::string name) { - int pos = name.find(".") + 10; - std::string mail = name.substr(0, pos); - std::string recipient = name.substr(pos); - if(recipient != "") { - std::string fileName = mailPath + "/.queue/" + name; - std::string path = mailFileSystem.getMailBoxPath(recipient) + "/Inbox/" + mail; - int rc = link(fileName.c_str(), path.c_str()); - rc = unlink(fileName.c_str()); - coreutils::Log(coreutils::LOG_INFO) << "Message " << mail << " delivered to " << recipient << "."; - } + int pos = name.find(".") + 10; + std::string mail = name.substr(0, pos); + std::string recipient = name.substr(pos); + if(recipient != "") { + std::string fileName = mailPath + "/.queue/" + name; + std::string path = mailFileSystem.getMailBoxPath(recipient) + "/Inbox/" + mail; + int rc = link(fileName.c_str(), path.c_str()); + rc = unlink(fileName.c_str()); + coreutils::Log(coreutils::LOG_INFO) << "Message " << mail << " delivered to " << recipient << "."; + } } - + private: __SMTP_AUTH _smtp_auth; __SMTP_DATA _smtp_data; diff --git a/__IMAP_APPEND.cpp b/__IMAP_APPEND.cpp index 790639a..7ec6614 100644 --- a/__IMAP_APPEND.cpp +++ b/__IMAP_APPEND.cpp @@ -2,8 +2,8 @@ namespace mail { - int __IMAP_APPEND::processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int __IMAP_APPEND::processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_APPEND.h b/__IMAP_APPEND.h index 8bdd6df..83a3528 100644 --- a/__IMAP_APPEND.h +++ b/__IMAP_APPEND.h @@ -2,13 +2,12 @@ # define ____IMAP_APPEND_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_APPEND : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data); + int processCommand(coreutils::ZString request, IMAPSession &session); }; diff --git a/__IMAP_AUTHENTICATE.h b/__IMAP_AUTHENTICATE.h index 8a18e47..983b471 100644 --- a/__IMAP_AUTHENTICATE.h +++ b/__IMAP_AUTHENTICATE.h @@ -2,15 +2,13 @@ # define ____IMAP_AUTHENTICATE_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" -# include "PString.h" namespace mail { class __IMAP_AUTHENTICATE : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_CHECK.h b/__IMAP_CHECK.h index 46b9a8d..7215600 100644 --- a/__IMAP_CHECK.h +++ b/__IMAP_CHECK.h @@ -2,14 +2,13 @@ # define ____IMAP_CHECK_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_CHECK : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_CLOSE.h b/__IMAP_CLOSE.h index f9f4d3b..1089284 100644 --- a/__IMAP_CLOSE.h +++ b/__IMAP_CLOSE.h @@ -2,14 +2,13 @@ # define ____IMAP_CLOSE_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_CLOSE : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_COPY.h b/__IMAP_COPY.h index 94da1d7..7c4e26d 100644 --- a/__IMAP_COPY.h +++ b/__IMAP_COPY.h @@ -2,14 +2,13 @@ # define ____IMAP_COPY_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_COPY : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_CREATE.h b/__IMAP_CREATE.h index 07ad232..73d5649 100644 --- a/__IMAP_CREATE.h +++ b/__IMAP_CREATE.h @@ -2,14 +2,13 @@ # define ____IMAP_CREATE_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_CREATE : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_DELETE.h b/__IMAP_DELETE.h index c3a9d97..f3b200f 100644 --- a/__IMAP_DELETE.h +++ b/__IMAP_DELETE.h @@ -2,14 +2,13 @@ # define ____IMAP_DELETE_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_DELETE : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_EXAMINE.h b/__IMAP_EXAMINE.h index e9919dc..f7af1bc 100644 --- a/__IMAP_EXAMINE.h +++ b/__IMAP_EXAMINE.h @@ -2,14 +2,13 @@ # define ____IMAP_EXAMINE_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_EXAMINE : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_EXPUNGE.h b/__IMAP_EXPUNGE.h index 5f27401..ec49ce4 100644 --- a/__IMAP_EXPUNGE.h +++ b/__IMAP_EXPUNGE.h @@ -2,14 +2,13 @@ # define ____IMAP_EXPUNGE_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_EXPUNGE : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_FETCH.h b/__IMAP_FETCH.h index 794fa72..b97a49a 100644 --- a/__IMAP_FETCH.h +++ b/__IMAP_FETCH.h @@ -2,14 +2,13 @@ # define ____IMAP_FETCH_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_FETCH : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_LIST.h b/__IMAP_LIST.h index cfa7778..068b048 100644 --- a/__IMAP_LIST.h +++ b/__IMAP_LIST.h @@ -2,14 +2,13 @@ # define ____IMAP_LIST_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_LIST : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_LOGIN.h b/__IMAP_LOGIN.h index ba250b7..4663ec9 100644 --- a/__IMAP_LOGIN.h +++ b/__IMAP_LOGIN.h @@ -2,14 +2,13 @@ # define ____IMAP_LOGIN_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_LOGIN : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_LSUB.h b/__IMAP_LSUB.h index 601f624..25b915c 100644 --- a/__IMAP_LSUB.h +++ b/__IMAP_LSUB.h @@ -2,14 +2,13 @@ # define ____IMAP_LSUB_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_LSUB : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_RENAME.h b/__IMAP_RENAME.h index 59742da..a391c1f 100644 --- a/__IMAP_RENAME.h +++ b/__IMAP_RENAME.h @@ -2,14 +2,13 @@ # define ____IMAP_RENAME_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_RENAME : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_SEARCH.h b/__IMAP_SEARCH.h index e0b823b..9ef8373 100644 --- a/__IMAP_SEARCH.h +++ b/__IMAP_SEARCH.h @@ -2,14 +2,13 @@ # define ____IMAP_SEARCH_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_SEARCH : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_SELECT.h b/__IMAP_SELECT.h index 31de587..6e294f4 100644 --- a/__IMAP_SELECT.h +++ b/__IMAP_SELECT.h @@ -2,14 +2,13 @@ # define ____IMAP_SELECT_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_SELECT : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_STARTTLS.h b/__IMAP_STARTTLS.h index 7851f84..f133316 100644 --- a/__IMAP_STARTTLS.h +++ b/__IMAP_STARTTLS.h @@ -2,14 +2,13 @@ # define ____IMAP_STARTTLS_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_STARTTLS : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_STATUS.h b/__IMAP_STATUS.h index ae858cc..17f1d14 100644 --- a/__IMAP_STATUS.h +++ b/__IMAP_STATUS.h @@ -2,14 +2,13 @@ # define ____IMAP_STATUS_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_STATUS : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_STORE.h b/__IMAP_STORE.h index 52195ec..ba2f5f3 100644 --- a/__IMAP_STORE.h +++ b/__IMAP_STORE.h @@ -2,14 +2,13 @@ # define ____IMAP_STORE_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_STORE : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_SUBSCRIBE.h b/__IMAP_SUBSCRIBE.h index e725342..3ead3bf 100644 --- a/__IMAP_SUBSCRIBE.h +++ b/__IMAP_SUBSCRIBE.h @@ -2,14 +2,13 @@ # define ____IMAP_SUBSCRIBE_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_SUBSCRIBE : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_UID.h b/__IMAP_UID.h index 5d79e75..af56c29 100644 --- a/__IMAP_UID.h +++ b/__IMAP_UID.h @@ -2,14 +2,13 @@ # define ____IMAP_UID_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_UID : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__IMAP_UNSUBSCRIBE.h b/__IMAP_UNSUBSCRIBE.h index 897213a..af42880 100644 --- a/__IMAP_UNSUBSCRIBE.h +++ b/__IMAP_UNSUBSCRIBE.h @@ -2,14 +2,13 @@ # define ____IMAP_UNSUBSCRIBE_h__ # include "IMAPCommand.h" -# include "IMAPSession.h" namespace mail { class __IMAP_UNSUBSCRIBE : public IMAPCommand { - int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, IMAPSession &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__POP3_DELE.h b/__POP3_DELE.h index 8681ac0..259f747 100644 --- a/__POP3_DELE.h +++ b/__POP3_DELE.h @@ -2,14 +2,13 @@ # define ____POP3_DELE_h__ # include "POP3Command.h" -# include "POP3Session.h" namespace mail { class __POP3_DELE : public POP3Command { - int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString &request, POP3Session &session, POP3Server &server) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__POP3_LAST.h b/__POP3_LAST.h index 46a6603..4fae742 100644 --- a/__POP3_LAST.h +++ b/__POP3_LAST.h @@ -2,14 +2,13 @@ # define ____POP3_LAST_h__ # include "POP3Command.h" -# include "POP3Session.h" namespace mail { class __POP3_LAST : public POP3Command { - int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString &request, POP3Session &session, POP3Server &server) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__POP3_LIST.h b/__POP3_LIST.h index 03f821d..9601628 100644 --- a/__POP3_LIST.h +++ b/__POP3_LIST.h @@ -2,14 +2,13 @@ # define ____POP3_LIST_h__ # include "POP3Command.h" -# include "POP3Session.h" namespace mail { class __POP3_LIST : public POP3Command { - int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, POP3Session &session, POP3Server &server) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__POP3_NOOP.h b/__POP3_NOOP.h index c4f21f9..d451c71 100644 --- a/__POP3_NOOP.h +++ b/__POP3_NOOP.h @@ -2,14 +2,13 @@ # define ____POP3_NOOP_h__ # include "POP3Command.h" -# include "POP3Session.h" namespace mail { class __POP3_NOOP : public POP3Command { - int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, POP3Session &session, POP3Server &server) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__POP3_PASS.h b/__POP3_PASS.h index 70cdb66..a284031 100644 --- a/__POP3_PASS.h +++ b/__POP3_PASS.h @@ -2,14 +2,13 @@ # define ____POP3_PASS_h__ # include "POP3Command.h" -# include "POP3Session.h" namespace mail { class __POP3_PASS : public POP3Command { - int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, POP3Session &session, POP3Server &server) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__POP3_QUIT.h b/__POP3_QUIT.h index c94f6a4..ccec6f6 100644 --- a/__POP3_QUIT.h +++ b/__POP3_QUIT.h @@ -2,14 +2,13 @@ # define ____POP3_QUIT_h__ # include "POP3Command.h" -# include "POP3Session.h" namespace mail { class __POP3_QUIT : public POP3Command { - int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, POP3Session &session, POP3Server &server) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__POP3_RETR.h b/__POP3_RETR.h index a2ea9a0..1881ec1 100644 --- a/__POP3_RETR.h +++ b/__POP3_RETR.h @@ -2,14 +2,13 @@ # define ____POP3_RETR_h__ # include "POP3Command.h" -# include "POP3Session.h" namespace mail { class __POP3_RETR : public POP3Command { - int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, POP3Session &session, POP3Server &server) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__POP3_RPOP.h b/__POP3_RPOP.h index e168cc0..80acef0 100644 --- a/__POP3_RPOP.h +++ b/__POP3_RPOP.h @@ -2,14 +2,13 @@ # define ____POP3_RPOP_h__ # include "POP3Command.h" -# include "POP3Session.h" namespace mail { class __POP3_RPOP : public POP3Command { - int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString &request, POP3Session &session, POP3Server &server) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__POP3_RSET.h b/__POP3_RSET.h index 1ffc6f0..c659282 100644 --- a/__POP3_RSET.h +++ b/__POP3_RSET.h @@ -2,14 +2,13 @@ # define ____POP3_RSET_h__ # include "POP3Command.h" -# include "POP3Session.h" namespace mail { class __POP3_RSET : public POP3Command { - int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString &request, POP3Session &session, POP3Server &server) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__POP3_STAT.h b/__POP3_STAT.h index 681a6d7..d8715b7 100644 --- a/__POP3_STAT.h +++ b/__POP3_STAT.h @@ -2,14 +2,13 @@ # define ____POP3_STAT_h__ # include "POP3Command.h" -# include "POP3Session.h" namespace mail { class __POP3_STAT : public POP3Command { - int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString &request, POP3Session &session, POP3Server &server) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__POP3_TOP.h b/__POP3_TOP.h index 8c9f6f6..3d82926 100644 --- a/__POP3_TOP.h +++ b/__POP3_TOP.h @@ -2,14 +2,13 @@ # define ____POP3_TOP_h__ # include "POP3Command.h" -# include "POP3Session.h" namespace mail { class __POP3_TOP : public POP3Command { - int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, POP3Session &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__POP3_USER.h b/__POP3_USER.h index 88ec34b..a948620 100644 --- a/__POP3_USER.h +++ b/__POP3_USER.h @@ -2,14 +2,13 @@ # define ____POP3_USER_h__ # include "POP3Command.h" -# include "POP3Session.h" namespace mail { class __POP3_USER : public POP3Command { - int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) { - data << "250 OK" << CRLF; + int processCommand(coreutils::ZString request, POP3Session &session) { + session.out << "250 OK" << CRLF; return 1; } diff --git a/__SMTP_AUTH.cpp b/__SMTP_AUTH.cpp index 1565c2f..1c9caa2 100644 --- a/__SMTP_AUTH.cpp +++ b/__SMTP_AUTH.cpp @@ -1,59 +1,56 @@ #include "__SMTP_AUTH.h" -#include "SMTPServer.h" #include "Base64.h" namespace mail { - int __SMTP_AUTH::processCommand(coreutils::ZString &request, core::TCPSession &session) { - - SMTPSession &s = dynamic_cast(session); - SMTPServer &server = session.server; - - switch((SMTPSession &)session.authState) { - - case USER_UNKNOWN: - if(request[1].equals("LOGIN") { - data << "334 VXNlcm5hbWU6" << CRLF; - // setTimer(10.0f); - s.authState = USER_QUERY; - server.commands.grabInput(&session, *this); - } - else { - s.out << "504 AUTH method not supported." << CRLF; - } - return 1; + int __SMTP_AUTH::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) { + + switch(session.authState) { + + case USER_UNKNOWN: + if(request[1].equals("LOGIN")) { + session.out << "334 VXNlcm5hbWU6" << CRLF; + // setTimer(10.0f); + session.authState = USER_QUERY; + grabInput(session); + } + else { + session.out << "504 AUTH method not supported." << CRLF; + } + return 1; case USER_QUERY: - s.userName = request[0].str(); - // setTimer(0.0f); - s.out << "334 UGFzc3dvcmQ6" << CRLF; - // setTimer(10.0f); - s.authState = USER_SECRET_QUERY; - return 1; + session.userName = request[0].str(); + // setTimer(0.0f); + session.out << "334 UGFzc3dvcmQ6" << CRLF; + // setTimer(10.0f); + session.authState = USER_SECRET_QUERY; + return 1; case USER_SECRET_QUERY: - s.password = request[0].str(); - // setTimer(0.0f); - coreutils::Base64 base64; - if(authLogin(s.userName, s.password, server)) { - s.out << "235 2.7.0 Authentication successful" << CRLF; - s.relay = true; - s.authState = USER_KNOWN; - server.commands.clearGrab(&session); - } - else { - s.out << "530 Login was unsuccessful." << CRLF; - } - return 1; + session.password = request[0].str(); + // setTimer(0.0f); + coreutils::Base64 base64; + if(authLogin(session.userName, session.password)) { + session.out << "235 2.7.0 Authentication successful" << CRLF; + session.relay = true; + session.authState = USER_KNOWN; + clearGrab(session); + } + else { + session.out << "530 Login was unsuccessful." << CRLF; + } + return 1; } return 0; } - bool __SMTP_AUTH::authLogin(coreutils::ZString userName, coreutils::ZString password, SMTPServer &server) { - std::string secretPath = server.mailFileSystem.getMailBoxPath(userName) + "/.password"; - coreutils::File secret(secretPath); - secret.read(); - return secret.asString() == password; + bool __SMTP_AUTH::authLogin(coreutils::ZString userName, coreutils::ZString password) { +// std::string secretPath = server.mailFileSystem.getMailBoxPath(userName) + "/.password"; +// coreutils::File secret(secretPath); +// secret.read(); +// return secret.asString() == password; + return true; } } diff --git a/__SMTP_AUTH.h b/__SMTP_AUTH.h index 642f355..3bc6859 100644 --- a/__SMTP_AUTH.h +++ b/__SMTP_AUTH.h @@ -1,18 +1,16 @@ #ifndef ____SMTP_AUTH_h__ # define ____SMTP_AUTH_h__ -# include "Command.h" +# include "SMTPCommand.h" namespace mail { - class SMTPServer; - - class __SMTP_AUTH : public core::Command { + class __SMTP_AUTH : public SMTPCommand { public: - int processCommand(coreutils::ZString &request, core::TCPSession &session) override; - bool authLogin(coreutils::ZString userName, coreutils::ZString password, SMTPServer &server); - + int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override; + bool authLogin(coreutils::ZString userName, coreutils::ZString password); + }; } diff --git a/__SMTP_DATA.cpp b/__SMTP_DATA.cpp index fc966b0..db27c00 100644 --- a/__SMTP_DATA.cpp +++ b/__SMTP_DATA.cpp @@ -1,5 +1,4 @@ #include "__SMTP_DATA.h" -#include "SMTPSession.h" #include "SMTPServer.h" #include "Log.h" #include @@ -9,63 +8,60 @@ namespace mail { - int __SMTP_DATA::processCommand(coreutils::ZString &request, core::TCPSession &session) { - - SMTPSession &s = dynamic_cast(session); - SMTPServer &server = session.server; + int __SMTP_DATA::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) { switch(session.mode) { case WAIT_FOR_DATA: - - switch(session.state) { - - case RCPT: - s.out << "354 Enter the mail message terminated by ." << CRLF; - s.mailData.str(""); - s.mode = RECEIVE_DATA; - server.commands.grabInput(&session, *this); - // setTimer(120.0f); - break; - - case MAIL: - s.out << "503 Please use RCPT first" << CRLF; - break; - - default: - s.out << "503 Please use MAIL first" << CRLF; - break; - - } + + switch(session.state) { + + case RCPT: + session.out << "354 Enter the mail message terminated by ." << CRLF; + session.mailData.str(""); + session.mode = RECEIVE_DATA; + grabInput(session); + // setTimer(120.0f); break; - - case RECEIVE_DATA: - if(request.str() != ".") - s.mailData << request.str() << CRLF; - else { - s.mode = WAIT_FOR_DATA; - s.state = READY; - server.commands.clearGrab(&session); - // if(filterMessage(session.mailData)) { - if(s.recipientList.size() > 0) { - if(s.mailData.str().size() > 0) { - std::string ID = queueMail(server, session.sender, session.recipientList, session.mailData); - if(ID != "") { - coreutils::Log(coreutils::LOG_INFO) << "Queued message " << ID << "."; - s.out << "250 OK Queued message " << ID << CRLF; - } - else - s.out << "550 Mail message too big" << CRLF; - } else - s.out << "550 Mail message was empty" << CRLF; - } else - s.out << "250 OK Queued message " << CRLF; - // } else - // data << "550 Message is probably spam" << CRLF; - } - break; - } - return 1; + + case MAIL: + session.out << "503 Please use RCPT first" << CRLF; + break; + + default: + session.out << "503 Please use MAIL first" << CRLF; + break; + + } + break; + + case RECEIVE_DATA: + if(request.str() != ".") + session.mailData << request.str() << CRLF; + else { + session.mode = WAIT_FOR_DATA; + session.state = READY; + clearGrab(session); + // if(filterMessage(session.mailData)) { + if(session.recipientList.size() > 0) { + if(session.mailData.str().size() > 0) { + std::string ID = queueMail(server, session.sender, session.recipientList, session.mailData); + if(ID != "") { + coreutils::Log(coreutils::LOG_INFO) << "Queued message " << ID << "."; + session.out << "250 OK Queued message " << ID << CRLF; + } + else + session.out << "550 Mail message too big" << CRLF; + } else + session.out << "550 Mail message was empty" << CRLF; + } else + session.out << "250 OK Queued message " << CRLF; + // } else + // data << "550 Message is probably spam" << CRLF; + } + break; + } + return 1; } std::string __SMTP_DATA::generateMailFileName() { @@ -80,17 +76,16 @@ namespace mail { std::string fileName = server.mailFileSystem.getMailPath() + "/.queue/" + generateMailFileName(); coreutils::File mailFile(fileName, O_CREAT | O_WRONLY, 0660); mailFile.write(mailData.str()); - + for(std::string recipient: recipientList) { - std::string newName = fileName + recipient; - link(fileName.c_str(), newName.c_str()); + std::string newName = fileName + recipient; + link(fileName.c_str(), newName.c_str()); } unlink(fileName.c_str()); return fileName; } - + } - \ No newline at end of file diff --git a/__SMTP_DATA.h b/__SMTP_DATA.h index fb98ca4..37f7959 100644 --- a/__SMTP_DATA.h +++ b/__SMTP_DATA.h @@ -6,12 +6,11 @@ namespace mail { - class SMTPServer; - class __SMTP_DATA : public SMTPCommand { public: - int processCommand(coreutils::ZString &request, core::TCPSession &session) override; + + int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override; std::string generateMailFileName(); std::string queueMail(SMTPServer &server, std::string sender, std::vector recipientList, std::stringstream &mailData); diff --git a/__SMTP_EHLO.cpp b/__SMTP_EHLO.cpp index d9974d5..08686a6 100644 --- a/__SMTP_EHLO.cpp +++ b/__SMTP_EHLO.cpp @@ -1,23 +1,19 @@ #include "__SMTP_EHLO.h" -#include "SMTPSession.h" - -#define CRLF "\r\n" +#include "SMTPServer.h" namespace mail { - int __SMTP_EHLO::processCommand(coreutils::ZString &request, core::TCPSession &session) { + int __SMTP_EHLO::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) { - SMTPSession &s = dynamic_cast(session); - - s.clientDomainName = request[1].str(); + session.clientDomainName = request[1].str(); - s.out << "250-" << server.hostName << CRLF; + session.out << "250-" << server.hostName << CRLF; // cout << "250-STARTTLS" << CRLF; // cout << "250-PIPELINING" << CRLF; // cout << "250-8BITMIME" << CRLF; - s.out << "250-AUTH LOGIN" << CRLF; - s.out << "250 HELP" << CRLF; - s.state = READY; + session.out << "250-AUTH LOGIN" << CRLF; + session.out << "250 HELP" << CRLF; + session.state = READY; return 1; } diff --git a/__SMTP_EHLO.h b/__SMTP_EHLO.h index 40c2dd9..3a4651b 100644 --- a/__SMTP_EHLO.h +++ b/__SMTP_EHLO.h @@ -2,7 +2,6 @@ # define ____SMTP_EHLO_h__ # include "SMTPCommand.h" -# include "SMTPSession.h" namespace mail { @@ -11,7 +10,7 @@ namespace mail { class __SMTP_EHLO : public SMTPCommand { public: - int processCommand(coreutils::ZString &request, core::TCPSession &session) override; + int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override; }; diff --git a/__SMTP_EXPN.cpp b/__SMTP_EXPN.cpp index 15ad103..a4214df 100644 --- a/__SMTP_EXPN.cpp +++ b/__SMTP_EXPN.cpp @@ -1,14 +1,11 @@ #include "__SMTP_EXPN.h" #include "SMTPServer.h" -#define CRLF "\r\n" - namespace mail { - int __SMTP_EXPN::processCommand(coreutils::ZString &request, core::TCPSession &session) { - SMTPSession &s = dynamic_cast(session); - s.out << "252 You must know recipient." << CRLF; - s.state = READY; + int __SMTP_EXPN::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) { + session.out << "252 You must know recipient." << CRLF; + session.state = READY; return 1; } diff --git a/__SMTP_EXPN.h b/__SMTP_EXPN.h index fe24f08..b15fae9 100644 --- a/__SMTP_EXPN.h +++ b/__SMTP_EXPN.h @@ -2,7 +2,6 @@ # define ____SMTP_EXPN_h__ # include "SMTPCommand.h" -# include "SMTPSession.h" namespace mail { @@ -11,7 +10,7 @@ namespace mail { class __SMTP_EXPN : public SMTPCommand { public: - int processCommand(coreutils::ZString &request, core::TCPSession &session) override; + int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override; }; } diff --git a/__SMTP_HELO.cpp b/__SMTP_HELO.cpp index eb9400b..b5daf21 100644 --- a/__SMTP_HELO.cpp +++ b/__SMTP_HELO.cpp @@ -3,11 +3,10 @@ namespace mail { - int __SMTP_HELO::processCommand(coreutils::ZString &request, core::TCPSession &session) { - SMTPSession &s = dynamic_cast(session); - s.clientName = request[1].str(); - s.out << "250 " << server.hostName << CRLF; - s.state = READY; + int __SMTP_HELO::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) { + session.clientDomainName = request[1].str(); + session.out << "250 " << server.hostName << CRLF; + session.state = READY; return 1; } diff --git a/__SMTP_HELO.h b/__SMTP_HELO.h index 09fac75..dbb4c14 100644 --- a/__SMTP_HELO.h +++ b/__SMTP_HELO.h @@ -1,17 +1,16 @@ #ifndef ____SMTP_HELO_h__ # define ____SMTP_HELO_h__ -# include "Command.h" -# include "SMTPSession.h" +# include "SMTPCommand.h" namespace mail { class SMTPServer; - class __SMTP_HELO : public core::Command { + class __SMTP_HELO : public SMTPCommand { public: - int processCommand(coreutils::ZString &request, core::TCPSession &session) override; + int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override; }; } diff --git a/__SMTP_HELP.cpp b/__SMTP_HELP.cpp index f122ccf..f0c5450 100644 --- a/__SMTP_HELP.cpp +++ b/__SMTP_HELP.cpp @@ -1,13 +1,11 @@ #include "__SMTP_HELP.h" #include "SMTPServer.h" -#define CRLF "\r\n" - namespace mail { - int __SMTP_HELP::processCommand(coreutils::ZString &request, core::TCPSession &session) { - s.out << "250 Sure you need help." << CRLF; - s.state = READY; + int __SMTP_HELP::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) { + session.out << "250 Sure you need help." << CRLF; + session.state = READY; return 1; } diff --git a/__SMTP_HELP.h b/__SMTP_HELP.h index bf799ed..9aaac71 100644 --- a/__SMTP_HELP.h +++ b/__SMTP_HELP.h @@ -2,12 +2,11 @@ # define ____SMTP_HELP_h__ # include "SMTPCommand.h" -# include "SMTPSession.h" namespace mail { class __SMTP_HELP : public SMTPCommand { - int processCommand(coreutils::ZString &request, core::TCPSession &session) override; + int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override; }; } diff --git a/__SMTP_MAIL.cpp b/__SMTP_MAIL.cpp index 03d7829..4c9852a 100644 --- a/__SMTP_MAIL.cpp +++ b/__SMTP_MAIL.cpp @@ -1,27 +1,22 @@ #include "__SMTP_MAIL.h" -#include "SMTPSession.h" - -#define CRLF "\r\n" namespace mail { - int __SMTP_MAIL::processCommand(coreutils::ZString &request, core::TCPSession &session) { - - SMTPSession &s = dynamic_cast(session); + int __SMTP_MAIL::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) { if(request.ifNext("MAIL FROM:")) { request.skipWhitespace(); if(request.ifNext("<")) { - s.sender = request.getTokenExclude(">"); - if(s.authState = USER_KNOWN) { - s.out << "250 OK" << CRLF; - s.recipientList.clear(); - s.state = MAIL; + session.sender = request.getTokenExclude(">").str(); + if(session.authState = USER_KNOWN) { + session.out << "250 OK" << CRLF; + session.recipientList.clear(); + session.state = MAIL; } } else - s.out << "550 Usage: MAIL FROM:" << CRLF; + session.out << "550 Usage: MAIL FROM:" << CRLF; } else - s.out << "550 Usage: MAIL FROM:" << CRLF; + session.out << "550 Usage: MAIL FROM:" << CRLF; return 1; } diff --git a/__SMTP_MAIL.h b/__SMTP_MAIL.h index a2b7ec1..e4426ae 100644 --- a/__SMTP_MAIL.h +++ b/__SMTP_MAIL.h @@ -2,16 +2,15 @@ # define ____SMTP_MAIL_h__ # include "SMTPCommand.h" -# include "SMTPSession.h" namespace mail { - class SMTPServer; +// class SMTPServer; - class __SMTP_MAIL : public Command { + class __SMTP_MAIL : public SMTPCommand { public: - int processCommand(coreutils::ZString &request, core::TCPSession &session) override; + int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override; }; } diff --git a/__SMTP_NOOP.cpp b/__SMTP_NOOP.cpp index 2dece60..7d71fc7 100644 --- a/__SMTP_NOOP.cpp +++ b/__SMTP_NOOP.cpp @@ -1,17 +1,10 @@ -#ifndef ____SMTP_NOOP_h__ -# define ____SMTP_NOOP_h__ - -# include "SMTPSession.h" # include "__SMTP_NOOP.h" -# include "ZString.h" namespace mail { - int __SMTP_NOOP::processCommand(coreutils::ZString &request, core::TCPSession &session) { - SMTPSession &s = dynamic_cast(session); - s.out << "250 OK" << CRLF; - return 1; - } -} + int __SMTP_NOOP::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) { + session.out << "250 OK" << CRLF; + return 1; + } -#endif +} diff --git a/__SMTP_NOOP.h b/__SMTP_NOOP.h index c6a032e..f3865df 100644 --- a/__SMTP_NOOP.h +++ b/__SMTP_NOOP.h @@ -1,13 +1,12 @@ #ifndef ____SMTP_NOOP_h__ # define ____SMTP_NOOP_h__ -# include "SMTPSession.h" -# include "ZString.h" +# include "SMTPCommand.h" namespace mail { - class __SMTP_NOOP : public Command { - int processCommand(coreutils::ZString &request, core::TCPSession &session) override; + class __SMTP_NOOP : public SMTPCommand { + int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override; }; } diff --git a/__SMTP_QUIT.cpp b/__SMTP_QUIT.cpp index ed762d2..fb086c5 100644 --- a/__SMTP_QUIT.cpp +++ b/__SMTP_QUIT.cpp @@ -1,10 +1,11 @@ # include "__SMTP_QUIT.h" -# include "SMTPServer.h" + +#include "SMTPServer.h" namespace mail { - int __SMTP_QUIT::processCommand(coreutils::PString request, SMTPSession &session, SMTPServer &server, std::stringstream &data) { - data << "221 " << server.hostName << CRLF; + int __SMTP_QUIT::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) { + session.out << "221 " << server.hostName << CRLF; session.terminate(); return 1; } diff --git a/__SMTP_QUIT.h b/__SMTP_QUIT.h index 8f6ac51..2eeb267 100644 --- a/__SMTP_QUIT.h +++ b/__SMTP_QUIT.h @@ -2,16 +2,15 @@ # define ____SMTP_QUIT_h__ # include "SMTPCommand.h" -# include "SMTPSession.h" namespace mail { class SMTPServer; - class __SMTP_QUIT : public Command { + class __SMTP_QUIT : public SMTPCommand { public: - int processCommand(coreutils::ZString &request, core::TCPSession &session) override; + int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override; }; } diff --git a/__SMTP_RCPT.cpp b/__SMTP_RCPT.cpp index 7857454..c5d46cf 100644 --- a/__SMTP_RCPT.cpp +++ b/__SMTP_RCPT.cpp @@ -3,30 +3,30 @@ namespace mail { - int __SMTP_RCPT::processCommand(coreutils::PString request, SMTPSession &session, SMTPServer &server, std::stringstream &data) { + int __SMTP_RCPT::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) { if((session.state == MAIL) || (session.state == RCPT)) { std::string recipient; if(request.ifNext("RCPT TO:")) { request.skipWhitespace(); if(request.ifNext("<")) { - recipient = request.getTokenExclude(">"); + recipient = request.getTokenExclude(">").str(); if(server.mailFileSystem.ifMailBoxExists(recipient)) { session.recipientList.push_back(recipient); - data << "250 OK" << CRLF; + session.out << "250 OK" << CRLF; session.state = RCPT; } else if(session.relay) { session.recipientList.push_back(recipient); - data << "250 OK" << CRLF; + session.out << "250 OK" << CRLF; session.state = RCPT; } else - data << "550 Mailbox does not exist" << CRLF; + session.out << "550 Mailbox does not exist" << CRLF; } else - data << "550 Usage: RCPT TO:" << CRLF; + session.out << "550 Usage: RCPT TO:" << CRLF; } else - data << "550 Usage: RCPT TO:" << CRLF; + session.out << "550 Usage: RCPT TO:" << CRLF; } else - data << "503 Please use MAIL first" << CRLF; + session.out << "503 Please use MAIL first" << CRLF; return 1; } diff --git a/__SMTP_RCPT.h b/__SMTP_RCPT.h index 3b18730..1f605f3 100644 --- a/__SMTP_RCPT.h +++ b/__SMTP_RCPT.h @@ -1,15 +1,14 @@ #ifndef ____SMTP_RCPT_h__ # define ____SMTP_RCPT_h__ -# include "Command.h" -# include "TCPSession.h" +# include "SMTPCommand.h" namespace mail { - - class __SMTP_RCPT : public core::Command { + + class __SMTP_RCPT : public SMTPCommand { public: - int processCommand(coreutils::ZString &request, core::TCPSession &session) override; + int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override; }; } diff --git a/__SMTP_RSET.cpp b/__SMTP_RSET.cpp index ce3815d..4100bae 100644 --- a/__SMTP_RSET.cpp +++ b/__SMTP_RSET.cpp @@ -1,20 +1,11 @@ -#ifndef ____SMTP_RSET_h__ -#define ____SMTP_RSET_h__ - -#include "SMTPCommand.h" +#include "__SMTP_RSET.h" namespace mail { - - class __SMTP_RSET : public SMTPCommand { - int processCommand(coreutils::PString request, SMTPSession &session, std::stringstream &data) { - session.state = READY; - data << "250 OK" << CRLF; - return 0; - } - - }; + int __SMTP_RSET::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) { + session.state = READY; + session.out << "250 OK" << CRLF; + return 1; + } } - -#endif diff --git a/__SMTP_RSET.h b/__SMTP_RSET.h index cb5d151..2701e42 100644 --- a/__SMTP_RSET.h +++ b/__SMTP_RSET.h @@ -1,14 +1,12 @@ #ifndef ____SMTP_RSET_h__ #define ____SMTP_RSET_h__ -#include "Command.h" -#include "TCPSession.h" -#include "ZString.h" +#include "SMTPCommand.h" namespace mail { - class __SMTP_RSET : public core::Command { - int processCommand(coreutils::ZString &request, core::TCPSession &session) override; + class __SMTP_RSET : public SMTPCommand { + int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override; }; } diff --git a/__SMTP_VRFY.cpp b/__SMTP_VRFY.cpp index 23b6838..4935f94 100644 --- a/__SMTP_VRFY.cpp +++ b/__SMTP_VRFY.cpp @@ -1,9 +1,8 @@ #include "__SMTP_VRFY.h" -#define CRLF "\r\n" namespace mail { - int __SMTP_VRFY::processCommand(coreutils::ZString &request, core::TCPSession &session) { + int __SMTP_VRFY::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) { session.out << "252 You must know who the mail is for" << CRLF; return 1; } diff --git a/__SMTP_VRFY.h b/__SMTP_VRFY.h index dcc73f2..f8c27fb 100644 --- a/__SMTP_VRFY.h +++ b/__SMTP_VRFY.h @@ -1,14 +1,12 @@ #ifndef ____SMTP_VRFY_h__ # define ____SMTP_VRFY_h__ -# include "Command.h" -# include "TCPSession.h" -# include "ZString.h" +# include "SMTPCommand.h" namespace mail { - class __SMTP_VRFY : public core::Command { - int processCommand(coreutils::ZString &request, core::TCPSession &session) override; + class __SMTP_VRFY : public SMTPCommand { + int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override; }; } diff --git a/main.cpp b/main.cpp index c8fc944..23b6719 100644 --- a/main.cpp +++ b/main.cpp @@ -29,7 +29,7 @@ int main(int argc, char **argv) { mail::IMAPServer imapServer(ePoll, hostName, mailFileSystem, core::IPAddress(ipAddress, 143)); core::ConsoleServer consoleServer(ePoll, core::IPAddress(ipAddress, 1027)); consoleServer.commands.add(consoleServer.commands, "help"); - ePoll.start(8, 1000); + ePoll.start(2, 1000); while(true) sleep(300);