Compilable SMTP
This commit is contained in:
parent
6c844983d9
commit
e1f33291f7
@ -5,10 +5,8 @@
|
|||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
int IMAPCommand::processCommand(std::string request, core::TCPSession *session, std::stringstream &data) {
|
int IMAPCommand::processCommand(coreutils::ZString &request, core::TCPSession &session) {
|
||||||
coreutils::PString parser(request);
|
return processCommand(request, (IMAPSession &)session, (IMAPServer &)session.server);
|
||||||
parser.split(" ");
|
|
||||||
return processCommand(parser, (IMAPSession &)*session, (IMAPServer &)session->server, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,8 @@ namespace mail {
|
|||||||
class IMAPCommand : public core::Command {
|
class IMAPCommand : public core::Command {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual int processCommand(std::string request, core::TCPSession *session, std::stringstream &data) override;
|
virtual int processCommand(coreutils::ZString &request, core::TCPSession &session) override;
|
||||||
virtual int processCommand(coreutils::PString request, IMAPSession &session, IMAPServer &server, std::stringstream &data) { return 0; }
|
virtual int processCommand(coreutils::ZString &request, IMAPSession &session, IMAPServer &server) { return 0; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ namespace mail {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
IMAPServer(core::EPoll &epoll, std::string hostName, MailFileSystem &mailFileSystem, core::IPAddress ipAddress)
|
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_append, "APPEND");
|
||||||
commands.add(_imap_authenticate, "AUTHENTCATE");
|
commands.add(_imap_authenticate, "AUTHENTCATE");
|
||||||
commands.add(_imap_check, "CHECK");
|
commands.add(_imap_check, "CHECK");
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <sys/stat.h>
|
# include <sys/stat.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include "EPoll.h"
|
|
||||||
# include "INotify.h"
|
# include "INotify.h"
|
||||||
|
# include "ZString.h"
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ namespace mail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string getMailBoxPath(std::string mailbox) {
|
std::string getMailBoxPath(std::string mailbox) {
|
||||||
coreutils::PString email(mailbox);
|
coreutils::ZString email(mailbox);
|
||||||
email.split("@");
|
email.split("@");
|
||||||
std::string path = mailPath + "/" + email[1].str() + "/" + email[0].str();
|
std::string path = mailPath + "/" + email[1].str() + "/" + email[0].str();
|
||||||
return path;
|
return path;
|
||||||
|
@ -7,15 +7,16 @@
|
|||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
|
class POP3Server;
|
||||||
|
|
||||||
class POP3Command : public core::Command {
|
class POP3Command : public core::Command {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual int processCommand(std::string request, core::TCPSession *session, std::stringstream &data) override {
|
virtual int processCommand(coreutils::ZString &request, core::TCPSession &session) override {
|
||||||
coreutils::PString parser(request);
|
return processCommand(request, (POP3Session &)session, (POP3Server &)session.server);
|
||||||
return processCommand(parser, (POP3Session &)*session, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) {
|
virtual int processCommand(coreutils::ZString request, POP3Session &session, POP3Server &server) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ namespace mail {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
POP3Server(core::EPoll &epoll, std::string hostName, MailFileSystem &mailFileSystem, core::IPAddress ipAddress)
|
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_dele, "DELE");
|
||||||
commands.add(_pop3_last, "LAST");
|
commands.add(_pop3_last, "LAST");
|
||||||
commands.add(_pop3_list, "LIST");
|
commands.add(_pop3_list, "LIST");
|
||||||
|
@ -12,7 +12,6 @@ namespace mail {
|
|||||||
AuthState authstate = USER_UNKNOWN;
|
AuthState authstate = USER_UNKNOWN;
|
||||||
bool relay = false;
|
bool relay = false;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
37
SMTPCommand.h
Normal file
37
SMTPCommand.h
Normal file
@ -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
|
@ -25,7 +25,7 @@ namespace mail {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
SMTPServer(core::EPoll &ePoll, std::string hostName, MailFileSystem &mailFileSystem, core::IPAddress ipAddress)
|
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_auth, "AUTH");
|
||||||
commands.add(_smtp_data, "DATA");
|
commands.add(_smtp_data, "DATA");
|
||||||
commands.add(_smtp_ehlo, "EHLO");
|
commands.add(_smtp_ehlo, "EHLO");
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
int __IMAP_APPEND::processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int __IMAP_APPEND::processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,13 +2,12 @@
|
|||||||
# define ____IMAP_APPEND_h__
|
# define ____IMAP_APPEND_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_APPEND : public IMAPCommand {
|
class __IMAP_APPEND : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data);
|
int processCommand(coreutils::ZString request, IMAPSession &session);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,15 +2,13 @@
|
|||||||
# define ____IMAP_AUTHENTICATE_h__
|
# define ____IMAP_AUTHENTICATE_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
# include "PString.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_AUTHENTICATE : public IMAPCommand {
|
class __IMAP_AUTHENTICATE : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_CHECK_h__
|
# define ____IMAP_CHECK_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_CHECK : public IMAPCommand {
|
class __IMAP_CHECK : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_CLOSE_h__
|
# define ____IMAP_CLOSE_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_CLOSE : public IMAPCommand {
|
class __IMAP_CLOSE : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_COPY_h__
|
# define ____IMAP_COPY_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_COPY : public IMAPCommand {
|
class __IMAP_COPY : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_CREATE_h__
|
# define ____IMAP_CREATE_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_CREATE : public IMAPCommand {
|
class __IMAP_CREATE : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_DELETE_h__
|
# define ____IMAP_DELETE_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_DELETE : public IMAPCommand {
|
class __IMAP_DELETE : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_EXAMINE_h__
|
# define ____IMAP_EXAMINE_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_EXAMINE : public IMAPCommand {
|
class __IMAP_EXAMINE : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_EXPUNGE_h__
|
# define ____IMAP_EXPUNGE_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_EXPUNGE : public IMAPCommand {
|
class __IMAP_EXPUNGE : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_FETCH_h__
|
# define ____IMAP_FETCH_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_FETCH : public IMAPCommand {
|
class __IMAP_FETCH : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_LIST_h__
|
# define ____IMAP_LIST_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_LIST : public IMAPCommand {
|
class __IMAP_LIST : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_LOGIN_h__
|
# define ____IMAP_LOGIN_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_LOGIN : public IMAPCommand {
|
class __IMAP_LOGIN : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_LSUB_h__
|
# define ____IMAP_LSUB_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_LSUB : public IMAPCommand {
|
class __IMAP_LSUB : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_RENAME_h__
|
# define ____IMAP_RENAME_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_RENAME : public IMAPCommand {
|
class __IMAP_RENAME : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_SEARCH_h__
|
# define ____IMAP_SEARCH_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_SEARCH : public IMAPCommand {
|
class __IMAP_SEARCH : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_SELECT_h__
|
# define ____IMAP_SELECT_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_SELECT : public IMAPCommand {
|
class __IMAP_SELECT : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_STARTTLS_h__
|
# define ____IMAP_STARTTLS_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_STARTTLS : public IMAPCommand {
|
class __IMAP_STARTTLS : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_STATUS_h__
|
# define ____IMAP_STATUS_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_STATUS : public IMAPCommand {
|
class __IMAP_STATUS : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_STORE_h__
|
# define ____IMAP_STORE_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_STORE : public IMAPCommand {
|
class __IMAP_STORE : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_SUBSCRIBE_h__
|
# define ____IMAP_SUBSCRIBE_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_SUBSCRIBE : public IMAPCommand {
|
class __IMAP_SUBSCRIBE : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_UID_h__
|
# define ____IMAP_UID_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_UID : public IMAPCommand {
|
class __IMAP_UID : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____IMAP_UNSUBSCRIBE_h__
|
# define ____IMAP_UNSUBSCRIBE_h__
|
||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __IMAP_UNSUBSCRIBE : public IMAPCommand {
|
class __IMAP_UNSUBSCRIBE : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, IMAPSession &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____POP3_DELE_h__
|
# define ____POP3_DELE_h__
|
||||||
|
|
||||||
# include "POP3Command.h"
|
# include "POP3Command.h"
|
||||||
# include "POP3Session.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __POP3_DELE : public POP3Command {
|
class __POP3_DELE : public POP3Command {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString &request, POP3Session &session, POP3Server &server) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____POP3_LAST_h__
|
# define ____POP3_LAST_h__
|
||||||
|
|
||||||
# include "POP3Command.h"
|
# include "POP3Command.h"
|
||||||
# include "POP3Session.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __POP3_LAST : public POP3Command {
|
class __POP3_LAST : public POP3Command {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString &request, POP3Session &session, POP3Server &server) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____POP3_LIST_h__
|
# define ____POP3_LIST_h__
|
||||||
|
|
||||||
# include "POP3Command.h"
|
# include "POP3Command.h"
|
||||||
# include "POP3Session.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __POP3_LIST : public POP3Command {
|
class __POP3_LIST : public POP3Command {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, POP3Session &session, POP3Server &server) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____POP3_NOOP_h__
|
# define ____POP3_NOOP_h__
|
||||||
|
|
||||||
# include "POP3Command.h"
|
# include "POP3Command.h"
|
||||||
# include "POP3Session.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __POP3_NOOP : public POP3Command {
|
class __POP3_NOOP : public POP3Command {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, POP3Session &session, POP3Server &server) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____POP3_PASS_h__
|
# define ____POP3_PASS_h__
|
||||||
|
|
||||||
# include "POP3Command.h"
|
# include "POP3Command.h"
|
||||||
# include "POP3Session.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __POP3_PASS : public POP3Command {
|
class __POP3_PASS : public POP3Command {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, POP3Session &session, POP3Server &server) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____POP3_QUIT_h__
|
# define ____POP3_QUIT_h__
|
||||||
|
|
||||||
# include "POP3Command.h"
|
# include "POP3Command.h"
|
||||||
# include "POP3Session.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __POP3_QUIT : public POP3Command {
|
class __POP3_QUIT : public POP3Command {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, POP3Session &session, POP3Server &server) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____POP3_RETR_h__
|
# define ____POP3_RETR_h__
|
||||||
|
|
||||||
# include "POP3Command.h"
|
# include "POP3Command.h"
|
||||||
# include "POP3Session.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __POP3_RETR : public POP3Command {
|
class __POP3_RETR : public POP3Command {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, POP3Session &session, POP3Server &server) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____POP3_RPOP_h__
|
# define ____POP3_RPOP_h__
|
||||||
|
|
||||||
# include "POP3Command.h"
|
# include "POP3Command.h"
|
||||||
# include "POP3Session.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __POP3_RPOP : public POP3Command {
|
class __POP3_RPOP : public POP3Command {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString &request, POP3Session &session, POP3Server &server) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____POP3_RSET_h__
|
# define ____POP3_RSET_h__
|
||||||
|
|
||||||
# include "POP3Command.h"
|
# include "POP3Command.h"
|
||||||
# include "POP3Session.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __POP3_RSET : public POP3Command {
|
class __POP3_RSET : public POP3Command {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString &request, POP3Session &session, POP3Server &server) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____POP3_STAT_h__
|
# define ____POP3_STAT_h__
|
||||||
|
|
||||||
# include "POP3Command.h"
|
# include "POP3Command.h"
|
||||||
# include "POP3Session.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __POP3_STAT : public POP3Command {
|
class __POP3_STAT : public POP3Command {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString &request, POP3Session &session, POP3Server &server) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____POP3_TOP_h__
|
# define ____POP3_TOP_h__
|
||||||
|
|
||||||
# include "POP3Command.h"
|
# include "POP3Command.h"
|
||||||
# include "POP3Session.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __POP3_TOP : public POP3Command {
|
class __POP3_TOP : public POP3Command {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, POP3Session &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
# define ____POP3_USER_h__
|
# define ____POP3_USER_h__
|
||||||
|
|
||||||
# include "POP3Command.h"
|
# include "POP3Command.h"
|
||||||
# include "POP3Session.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __POP3_USER : public POP3Command {
|
class __POP3_USER : public POP3Command {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, POP3Session &session, std::stringstream &data) {
|
int processCommand(coreutils::ZString request, POP3Session &session) {
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,59 +1,56 @@
|
|||||||
#include "__SMTP_AUTH.h"
|
#include "__SMTP_AUTH.h"
|
||||||
#include "SMTPServer.h"
|
|
||||||
#include "Base64.h"
|
#include "Base64.h"
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
int __SMTP_AUTH::processCommand(coreutils::ZString &request, core::TCPSession &session) {
|
int __SMTP_AUTH::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
||||||
|
|
||||||
SMTPSession &s = dynamic_cast<SMTPSession &>(session);
|
switch(session.authState) {
|
||||||
SMTPServer &server = session.server;
|
|
||||||
|
|
||||||
switch((SMTPSession &)session.authState) {
|
|
||||||
|
|
||||||
case USER_UNKNOWN:
|
case USER_UNKNOWN:
|
||||||
if(request[1].equals("LOGIN") {
|
if(request[1].equals("LOGIN")) {
|
||||||
data << "334 VXNlcm5hbWU6" << CRLF;
|
session.out << "334 VXNlcm5hbWU6" << CRLF;
|
||||||
// setTimer(10.0f);
|
// setTimer(10.0f);
|
||||||
s.authState = USER_QUERY;
|
session.authState = USER_QUERY;
|
||||||
server.commands.grabInput(&session, *this);
|
grabInput(session);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
s.out << "504 AUTH method not supported." << CRLF;
|
session.out << "504 AUTH method not supported." << CRLF;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case USER_QUERY:
|
case USER_QUERY:
|
||||||
s.userName = request[0].str();
|
session.userName = request[0].str();
|
||||||
// setTimer(0.0f);
|
// setTimer(0.0f);
|
||||||
s.out << "334 UGFzc3dvcmQ6" << CRLF;
|
session.out << "334 UGFzc3dvcmQ6" << CRLF;
|
||||||
// setTimer(10.0f);
|
// setTimer(10.0f);
|
||||||
s.authState = USER_SECRET_QUERY;
|
session.authState = USER_SECRET_QUERY;
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
case USER_SECRET_QUERY:
|
case USER_SECRET_QUERY:
|
||||||
s.password = request[0].str();
|
session.password = request[0].str();
|
||||||
// setTimer(0.0f);
|
// setTimer(0.0f);
|
||||||
coreutils::Base64 base64;
|
coreutils::Base64 base64;
|
||||||
if(authLogin(s.userName, s.password, server)) {
|
if(authLogin(session.userName, session.password)) {
|
||||||
s.out << "235 2.7.0 Authentication successful" << CRLF;
|
session.out << "235 2.7.0 Authentication successful" << CRLF;
|
||||||
s.relay = true;
|
session.relay = true;
|
||||||
s.authState = USER_KNOWN;
|
session.authState = USER_KNOWN;
|
||||||
server.commands.clearGrab(&session);
|
clearGrab(session);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
s.out << "530 Login was unsuccessful." << CRLF;
|
session.out << "530 Login was unsuccessful." << CRLF;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool __SMTP_AUTH::authLogin(coreutils::ZString userName, coreutils::ZString password, SMTPServer &server) {
|
bool __SMTP_AUTH::authLogin(coreutils::ZString userName, coreutils::ZString password) {
|
||||||
std::string secretPath = server.mailFileSystem.getMailBoxPath(userName) + "/.password";
|
// std::string secretPath = server.mailFileSystem.getMailBoxPath(userName) + "/.password";
|
||||||
coreutils::File secret(secretPath);
|
// coreutils::File secret(secretPath);
|
||||||
secret.read();
|
// secret.read();
|
||||||
return secret.asString() == password;
|
// return secret.asString() == password;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
#ifndef ____SMTP_AUTH_h__
|
#ifndef ____SMTP_AUTH_h__
|
||||||
# define ____SMTP_AUTH_h__
|
# define ____SMTP_AUTH_h__
|
||||||
|
|
||||||
# include "Command.h"
|
# include "SMTPCommand.h"
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class SMTPServer;
|
class __SMTP_AUTH : public SMTPCommand {
|
||||||
|
|
||||||
class __SMTP_AUTH : public core::Command {
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int processCommand(coreutils::ZString &request, core::TCPSession &session) override;
|
int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override;
|
||||||
bool authLogin(coreutils::ZString userName, coreutils::ZString password, SMTPServer &server);
|
bool authLogin(coreutils::ZString userName, coreutils::ZString password);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include "__SMTP_DATA.h"
|
#include "__SMTP_DATA.h"
|
||||||
#include "SMTPSession.h"
|
|
||||||
#include "SMTPServer.h"
|
#include "SMTPServer.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@ -9,10 +8,7 @@
|
|||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
int __SMTP_DATA::processCommand(coreutils::ZString &request, core::TCPSession &session) {
|
int __SMTP_DATA::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
||||||
|
|
||||||
SMTPSession &s = dynamic_cast<SMTPSession &>(session);
|
|
||||||
SMTPServer &server = session.server;
|
|
||||||
|
|
||||||
switch(session.mode) {
|
switch(session.mode) {
|
||||||
|
|
||||||
@ -21,19 +17,19 @@ namespace mail {
|
|||||||
switch(session.state) {
|
switch(session.state) {
|
||||||
|
|
||||||
case RCPT:
|
case RCPT:
|
||||||
s.out << "354 Enter the mail message terminated by <CRLF>.<CRLF>" << CRLF;
|
session.out << "354 Enter the mail message terminated by <CRLF>.<CRLF>" << CRLF;
|
||||||
s.mailData.str("");
|
session.mailData.str("");
|
||||||
s.mode = RECEIVE_DATA;
|
session.mode = RECEIVE_DATA;
|
||||||
server.commands.grabInput(&session, *this);
|
grabInput(session);
|
||||||
// setTimer(120.0f);
|
// setTimer(120.0f);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MAIL:
|
case MAIL:
|
||||||
s.out << "503 Please use RCPT first" << CRLF;
|
session.out << "503 Please use RCPT first" << CRLF;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
s.out << "503 Please use MAIL first" << CRLF;
|
session.out << "503 Please use MAIL first" << CRLF;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -41,25 +37,25 @@ namespace mail {
|
|||||||
|
|
||||||
case RECEIVE_DATA:
|
case RECEIVE_DATA:
|
||||||
if(request.str() != ".")
|
if(request.str() != ".")
|
||||||
s.mailData << request.str() << CRLF;
|
session.mailData << request.str() << CRLF;
|
||||||
else {
|
else {
|
||||||
s.mode = WAIT_FOR_DATA;
|
session.mode = WAIT_FOR_DATA;
|
||||||
s.state = READY;
|
session.state = READY;
|
||||||
server.commands.clearGrab(&session);
|
clearGrab(session);
|
||||||
// if(filterMessage(session.mailData)) {
|
// if(filterMessage(session.mailData)) {
|
||||||
if(s.recipientList.size() > 0) {
|
if(session.recipientList.size() > 0) {
|
||||||
if(s.mailData.str().size() > 0) {
|
if(session.mailData.str().size() > 0) {
|
||||||
std::string ID = queueMail(server, session.sender, session.recipientList, session.mailData);
|
std::string ID = queueMail(server, session.sender, session.recipientList, session.mailData);
|
||||||
if(ID != "") {
|
if(ID != "") {
|
||||||
coreutils::Log(coreutils::LOG_INFO) << "Queued message " << ID << ".";
|
coreutils::Log(coreutils::LOG_INFO) << "Queued message " << ID << ".";
|
||||||
s.out << "250 OK Queued message " << ID << CRLF;
|
session.out << "250 OK Queued message " << ID << CRLF;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
s.out << "550 Mail message too big" << CRLF;
|
session.out << "550 Mail message too big" << CRLF;
|
||||||
} else
|
} else
|
||||||
s.out << "550 Mail message was empty" << CRLF;
|
session.out << "550 Mail message was empty" << CRLF;
|
||||||
} else
|
} else
|
||||||
s.out << "250 OK Queued message " << CRLF;
|
session.out << "250 OK Queued message " << CRLF;
|
||||||
// } else
|
// } else
|
||||||
// data << "550 Message is probably spam" << CRLF;
|
// data << "550 Message is probably spam" << CRLF;
|
||||||
}
|
}
|
||||||
@ -93,4 +89,3 @@ namespace mail {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -6,12 +6,11 @@
|
|||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class SMTPServer;
|
|
||||||
|
|
||||||
class __SMTP_DATA : public SMTPCommand {
|
class __SMTP_DATA : public SMTPCommand {
|
||||||
|
|
||||||
public:
|
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 generateMailFileName();
|
||||||
std::string queueMail(SMTPServer &server, std::string sender, std::vector<std::string> recipientList, std::stringstream &mailData);
|
std::string queueMail(SMTPServer &server, std::string sender, std::vector<std::string> recipientList, std::stringstream &mailData);
|
||||||
|
@ -1,23 +1,19 @@
|
|||||||
#include "__SMTP_EHLO.h"
|
#include "__SMTP_EHLO.h"
|
||||||
#include "SMTPSession.h"
|
#include "SMTPServer.h"
|
||||||
|
|
||||||
#define CRLF "\r\n"
|
|
||||||
|
|
||||||
namespace mail {
|
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<SMTPSession &>(session);
|
session.clientDomainName = request[1].str();
|
||||||
|
|
||||||
s.clientDomainName = request[1].str();
|
session.out << "250-" << server.hostName << CRLF;
|
||||||
|
|
||||||
s.out << "250-" << server.hostName << CRLF;
|
|
||||||
// cout << "250-STARTTLS" << CRLF;
|
// cout << "250-STARTTLS" << CRLF;
|
||||||
// cout << "250-PIPELINING" << CRLF;
|
// cout << "250-PIPELINING" << CRLF;
|
||||||
// cout << "250-8BITMIME" << CRLF;
|
// cout << "250-8BITMIME" << CRLF;
|
||||||
s.out << "250-AUTH LOGIN" << CRLF;
|
session.out << "250-AUTH LOGIN" << CRLF;
|
||||||
s.out << "250 HELP" << CRLF;
|
session.out << "250 HELP" << CRLF;
|
||||||
s.state = READY;
|
session.state = READY;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
# define ____SMTP_EHLO_h__
|
# define ____SMTP_EHLO_h__
|
||||||
|
|
||||||
# include "SMTPCommand.h"
|
# include "SMTPCommand.h"
|
||||||
# include "SMTPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
@ -11,7 +10,7 @@ namespace mail {
|
|||||||
class __SMTP_EHLO : public SMTPCommand {
|
class __SMTP_EHLO : public SMTPCommand {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int processCommand(coreutils::ZString &request, core::TCPSession &session) override;
|
int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
#include "__SMTP_EXPN.h"
|
#include "__SMTP_EXPN.h"
|
||||||
#include "SMTPServer.h"
|
#include "SMTPServer.h"
|
||||||
|
|
||||||
#define CRLF "\r\n"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
int __SMTP_EXPN::processCommand(coreutils::ZString &request, core::TCPSession &session) {
|
int __SMTP_EXPN::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
||||||
SMTPSession &s = dynamic_cast<SMTPSession &>(session);
|
session.out << "252 You must know recipient." << CRLF;
|
||||||
s.out << "252 You must know recipient." << CRLF;
|
session.state = READY;
|
||||||
s.state = READY;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
# define ____SMTP_EXPN_h__
|
# define ____SMTP_EXPN_h__
|
||||||
|
|
||||||
# include "SMTPCommand.h"
|
# include "SMTPCommand.h"
|
||||||
# include "SMTPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
@ -11,7 +10,7 @@ namespace mail {
|
|||||||
class __SMTP_EXPN : public SMTPCommand {
|
class __SMTP_EXPN : public SMTPCommand {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int processCommand(coreutils::ZString &request, core::TCPSession &session) override;
|
int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,11 +3,10 @@
|
|||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
int __SMTP_HELO::processCommand(coreutils::ZString &request, core::TCPSession &session) {
|
int __SMTP_HELO::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
||||||
SMTPSession &s = dynamic_cast<SMTPSession &>(session);
|
session.clientDomainName = request[1].str();
|
||||||
s.clientName = request[1].str();
|
session.out << "250 " << server.hostName << CRLF;
|
||||||
s.out << "250 " << server.hostName << CRLF;
|
session.state = READY;
|
||||||
s.state = READY;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
#ifndef ____SMTP_HELO_h__
|
#ifndef ____SMTP_HELO_h__
|
||||||
# define ____SMTP_HELO_h__
|
# define ____SMTP_HELO_h__
|
||||||
|
|
||||||
# include "Command.h"
|
# include "SMTPCommand.h"
|
||||||
# include "SMTPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class SMTPServer;
|
class SMTPServer;
|
||||||
|
|
||||||
class __SMTP_HELO : public core::Command {
|
class __SMTP_HELO : public SMTPCommand {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int processCommand(coreutils::ZString &request, core::TCPSession &session) override;
|
int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
#include "__SMTP_HELP.h"
|
#include "__SMTP_HELP.h"
|
||||||
#include "SMTPServer.h"
|
#include "SMTPServer.h"
|
||||||
|
|
||||||
#define CRLF "\r\n"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
int __SMTP_HELP::processCommand(coreutils::ZString &request, core::TCPSession &session) {
|
int __SMTP_HELP::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
||||||
s.out << "250 Sure you need help." << CRLF;
|
session.out << "250 Sure you need help." << CRLF;
|
||||||
s.state = READY;
|
session.state = READY;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,12 +2,11 @@
|
|||||||
# define ____SMTP_HELP_h__
|
# define ____SMTP_HELP_h__
|
||||||
|
|
||||||
# include "SMTPCommand.h"
|
# include "SMTPCommand.h"
|
||||||
# include "SMTPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __SMTP_HELP : public SMTPCommand {
|
class __SMTP_HELP : public SMTPCommand {
|
||||||
int processCommand(coreutils::ZString &request, core::TCPSession &session) override;
|
int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,22 @@
|
|||||||
#include "__SMTP_MAIL.h"
|
#include "__SMTP_MAIL.h"
|
||||||
#include "SMTPSession.h"
|
|
||||||
|
|
||||||
#define CRLF "\r\n"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
int __SMTP_MAIL::processCommand(coreutils::ZString &request, core::TCPSession &session) {
|
int __SMTP_MAIL::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
||||||
|
|
||||||
SMTPSession &s = dynamic_cast<SMTPSession &>(session);
|
|
||||||
|
|
||||||
if(request.ifNext("MAIL FROM:")) {
|
if(request.ifNext("MAIL FROM:")) {
|
||||||
request.skipWhitespace();
|
request.skipWhitespace();
|
||||||
if(request.ifNext("<")) {
|
if(request.ifNext("<")) {
|
||||||
s.sender = request.getTokenExclude(">");
|
session.sender = request.getTokenExclude(">").str();
|
||||||
if(s.authState = USER_KNOWN) {
|
if(session.authState = USER_KNOWN) {
|
||||||
s.out << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
s.recipientList.clear();
|
session.recipientList.clear();
|
||||||
s.state = MAIL;
|
session.state = MAIL;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
s.out << "550 Usage: MAIL FROM:<email-address>" << CRLF;
|
session.out << "550 Usage: MAIL FROM:<email-address>" << CRLF;
|
||||||
} else
|
} else
|
||||||
s.out << "550 Usage: MAIL FROM:<email-address>" << CRLF;
|
session.out << "550 Usage: MAIL FROM:<email-address>" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,16 +2,15 @@
|
|||||||
# define ____SMTP_MAIL_h__
|
# define ____SMTP_MAIL_h__
|
||||||
|
|
||||||
# include "SMTPCommand.h"
|
# include "SMTPCommand.h"
|
||||||
# include "SMTPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class SMTPServer;
|
// class SMTPServer;
|
||||||
|
|
||||||
class __SMTP_MAIL : public Command {
|
class __SMTP_MAIL : public SMTPCommand {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int processCommand(coreutils::ZString &request, core::TCPSession &session) override;
|
int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,10 @@
|
|||||||
#ifndef ____SMTP_NOOP_h__
|
|
||||||
# define ____SMTP_NOOP_h__
|
|
||||||
|
|
||||||
# include "SMTPSession.h"
|
|
||||||
# include "__SMTP_NOOP.h"
|
# include "__SMTP_NOOP.h"
|
||||||
# include "ZString.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
int __SMTP_NOOP::processCommand(coreutils::ZString &request, core::TCPSession &session) {
|
int __SMTP_NOOP::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
||||||
SMTPSession &s = dynamic_cast<SMTPSession &>(session);
|
session.out << "250 OK" << CRLF;
|
||||||
s.out << "250 OK" << CRLF;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
}
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
#ifndef ____SMTP_NOOP_h__
|
#ifndef ____SMTP_NOOP_h__
|
||||||
# define ____SMTP_NOOP_h__
|
# define ____SMTP_NOOP_h__
|
||||||
|
|
||||||
# include "SMTPSession.h"
|
# include "SMTPCommand.h"
|
||||||
# include "ZString.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __SMTP_NOOP : public Command {
|
class __SMTP_NOOP : public SMTPCommand {
|
||||||
int processCommand(coreutils::ZString &request, core::TCPSession &session) override;
|
int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
# include "__SMTP_QUIT.h"
|
# include "__SMTP_QUIT.h"
|
||||||
# include "SMTPServer.h"
|
|
||||||
|
#include "SMTPServer.h"
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
int __SMTP_QUIT::processCommand(coreutils::PString request, SMTPSession &session, SMTPServer &server, std::stringstream &data) {
|
int __SMTP_QUIT::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
||||||
data << "221 " << server.hostName << CRLF;
|
session.out << "221 " << server.hostName << CRLF;
|
||||||
session.terminate();
|
session.terminate();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,15 @@
|
|||||||
# define ____SMTP_QUIT_h__
|
# define ____SMTP_QUIT_h__
|
||||||
|
|
||||||
# include "SMTPCommand.h"
|
# include "SMTPCommand.h"
|
||||||
# include "SMTPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class SMTPServer;
|
class SMTPServer;
|
||||||
|
|
||||||
class __SMTP_QUIT : public Command {
|
class __SMTP_QUIT : public SMTPCommand {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int processCommand(coreutils::ZString &request, core::TCPSession &session) override;
|
int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,30 +3,30 @@
|
|||||||
|
|
||||||
namespace mail {
|
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)) {
|
if((session.state == MAIL) || (session.state == RCPT)) {
|
||||||
std::string recipient;
|
std::string recipient;
|
||||||
if(request.ifNext("RCPT TO:")) {
|
if(request.ifNext("RCPT TO:")) {
|
||||||
request.skipWhitespace();
|
request.skipWhitespace();
|
||||||
if(request.ifNext("<")) {
|
if(request.ifNext("<")) {
|
||||||
recipient = request.getTokenExclude(">");
|
recipient = request.getTokenExclude(">").str();
|
||||||
if(server.mailFileSystem.ifMailBoxExists(recipient)) {
|
if(server.mailFileSystem.ifMailBoxExists(recipient)) {
|
||||||
session.recipientList.push_back(recipient);
|
session.recipientList.push_back(recipient);
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
session.state = RCPT;
|
session.state = RCPT;
|
||||||
} else if(session.relay) {
|
} else if(session.relay) {
|
||||||
session.recipientList.push_back(recipient);
|
session.recipientList.push_back(recipient);
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
session.state = RCPT;
|
session.state = RCPT;
|
||||||
} else
|
} else
|
||||||
data << "550 Mailbox does not exist" << CRLF;
|
session.out << "550 Mailbox does not exist" << CRLF;
|
||||||
} else
|
} else
|
||||||
data << "550 Usage: RCPT TO:<email-address>" << CRLF;
|
session.out << "550 Usage: RCPT TO:<email-address>" << CRLF;
|
||||||
} else
|
} else
|
||||||
data << "550 Usage: RCPT TO:<email-address>" << CRLF;
|
session.out << "550 Usage: RCPT TO:<email-address>" << CRLF;
|
||||||
} else
|
} else
|
||||||
data << "503 Please use MAIL first" << CRLF;
|
session.out << "503 Please use MAIL first" << CRLF;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
#ifndef ____SMTP_RCPT_h__
|
#ifndef ____SMTP_RCPT_h__
|
||||||
# define ____SMTP_RCPT_h__
|
# define ____SMTP_RCPT_h__
|
||||||
|
|
||||||
# include "Command.h"
|
# include "SMTPCommand.h"
|
||||||
# include "TCPSession.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __SMTP_RCPT : public core::Command {
|
class __SMTP_RCPT : public SMTPCommand {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int processCommand(coreutils::ZString &request, core::TCPSession &session) override;
|
int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,11 @@
|
|||||||
#ifndef ____SMTP_RSET_h__
|
#include "__SMTP_RSET.h"
|
||||||
#define ____SMTP_RSET_h__
|
|
||||||
|
|
||||||
#include "SMTPCommand.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __SMTP_RSET : public SMTPCommand {
|
int __SMTP_RSET::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, SMTPSession &session, std::stringstream &data) {
|
|
||||||
session.state = READY;
|
session.state = READY;
|
||||||
data << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
#ifndef ____SMTP_RSET_h__
|
#ifndef ____SMTP_RSET_h__
|
||||||
#define ____SMTP_RSET_h__
|
#define ____SMTP_RSET_h__
|
||||||
|
|
||||||
#include "Command.h"
|
#include "SMTPCommand.h"
|
||||||
#include "TCPSession.h"
|
|
||||||
#include "ZString.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __SMTP_RSET : public core::Command {
|
class __SMTP_RSET : public SMTPCommand {
|
||||||
int processCommand(coreutils::ZString &request, core::TCPSession &session) override;
|
int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
#include "__SMTP_VRFY.h"
|
#include "__SMTP_VRFY.h"
|
||||||
#define CRLF "\r\n"
|
|
||||||
|
|
||||||
namespace mail {
|
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;
|
session.out << "252 You must know who the mail is for" << CRLF;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,12 @@
|
|||||||
#ifndef ____SMTP_VRFY_h__
|
#ifndef ____SMTP_VRFY_h__
|
||||||
# define ____SMTP_VRFY_h__
|
# define ____SMTP_VRFY_h__
|
||||||
|
|
||||||
# include "Command.h"
|
# include "SMTPCommand.h"
|
||||||
# include "TCPSession.h"
|
|
||||||
# include "ZString.h"
|
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class __SMTP_VRFY : public core::Command {
|
class __SMTP_VRFY : public SMTPCommand {
|
||||||
int processCommand(coreutils::ZString &request, core::TCPSession &session) override;
|
int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
2
main.cpp
2
main.cpp
@ -29,7 +29,7 @@ int main(int argc, char **argv) {
|
|||||||
mail::IMAPServer imapServer(ePoll, hostName, mailFileSystem, core::IPAddress(ipAddress, 143));
|
mail::IMAPServer imapServer(ePoll, hostName, mailFileSystem, core::IPAddress(ipAddress, 143));
|
||||||
core::ConsoleServer consoleServer(ePoll, core::IPAddress(ipAddress, 1027));
|
core::ConsoleServer consoleServer(ePoll, core::IPAddress(ipAddress, 1027));
|
||||||
consoleServer.commands.add(consoleServer.commands, "help");
|
consoleServer.commands.add(consoleServer.commands, "help");
|
||||||
ePoll.start(8, 1000);
|
ePoll.start(2, 1000);
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
sleep(300);
|
sleep(300);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user