#ifndef __SMTPServer_h__ # define __SMTPServer_h__ # include # include "EPoll.h" # include "TCPServer.h" # include "SMTPSession.h" # include "MailFileSystem.h" # include "__SMTP_AUTH.h" # include "__SMTP_DATA.h" # include "__SMTP_EHLO.h" # include "__SMTP_HELO.h" # include "__SMTP_MAIL.h" # include "__SMTP_NOOP.h" # include "__SMTP_QUIT.h" # include "__SMTP_RCPT.h" # include "__SMTP_RSET.h" # include "__SMTP_VRFY.h" # include "INotify.h" # include "Log.h" namespace mail { class SMTPServer : public core::TCPServer, public core::INotify { public: SMTPServer(core::EPoll &ePoll, std::string hostName, std::string mailPath, core::IPAddress ipAddress) : core::TCPServer(ePoll, ipAddress, "SMTP Server"), core::INotify(ePoll), hostName(hostName), mailFileSystem(mailPath) { this->mailPath = mailPath; commands.add(_smtp_auth, "AUTH"); commands.add(_smtp_data, "DATA"); commands.add(_smtp_ehlo, "EHLO"); commands.add(_smtp_helo, "HELO"); commands.add(_smtp_mail, "MAIL"); commands.add(_smtp_noop, "NOOP"); commands.add(_smtp_quit, "QUIT"); commands.add(_smtp_rcpt, "RCPT"); commands.add(_smtp_rset, "RSET"); commands.add(_smtp_vrfy, "VRFY"); processExisting(); wd = addWatch(mailPath + "/.queue/"); } MailFileSystem mailFileSystem; std::string hostName; std::string mailPath; SMTPSession * getSocketAccept(core::EPoll &ePoll) override { return new SMTPSession(ePoll, *this); } void sessionErrorHandler(std::string errorString, std::stringstream &out) { 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 << "."; } } private: __SMTP_AUTH _smtp_auth; __SMTP_DATA _smtp_data; __SMTP_EHLO _smtp_ehlo; __SMTP_HELO _smtp_helo; __SMTP_MAIL _smtp_mail; __SMTP_NOOP _smtp_noop; __SMTP_QUIT _smtp_quit; __SMTP_RCPT _smtp_rcpt; __SMTP_RSET _smtp_rset; __SMTP_VRFY _smtp_vrfy; int wd; void processExisting() { } }; } #endif