Continued development...
This commit is contained in:
parent
db3e82a18e
commit
967a03563a
15
IMAPCommand.cpp
Normal file
15
IMAPCommand.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
# include "Command.h"
|
||||
# include "IMAPSession.h"
|
||||
# include "IMAPServer.h"
|
||||
# include "Log.h"
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,21 +2,18 @@
|
||||
# define __IMAPCommand_h__
|
||||
|
||||
# include "Command.h"
|
||||
# include "TCPSession.h"
|
||||
# include "IMAPSession.h"
|
||||
|
||||
namespace mail {
|
||||
|
||||
class IMAPServer;
|
||||
|
||||
class IMAPCommand : public core::Command {
|
||||
|
||||
public:
|
||||
virtual int processCommand(std::string request, core::TCPSession *session, std::stringstream &data) override {
|
||||
coreutils::PString parser(request);
|
||||
return processCommand(parser, (IMAPSession &)*session, data);
|
||||
}
|
||||
|
||||
virtual int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {}
|
||||
|
||||
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) {}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,38 +1,39 @@
|
||||
#ifndef __IMAPService_h__
|
||||
#define __IMAPService_h__
|
||||
#ifndef __IMAPServer_h__
|
||||
# define __IMAPServer_h__
|
||||
|
||||
#include "TCPServer.h"
|
||||
#include "Exception.h"
|
||||
#include "__IMAP_APPEND.h"
|
||||
#include "__IMAP_AUTHENTICATE.h"
|
||||
#include "__IMAP_CHECK.h"
|
||||
#include "__IMAP_CLOSE.h"
|
||||
#include "__IMAP_COPY.h"
|
||||
#include "__IMAP_CREATE.h"
|
||||
#include "__IMAP_DELETE.h"
|
||||
#include "__IMAP_EXAMINE.h"
|
||||
#include "__IMAP_EXPUNGE.h"
|
||||
#include "__IMAP_FETCH.h"
|
||||
#include "__IMAP_LIST.h"
|
||||
#include "__IMAP_LOGIN.h"
|
||||
#include "__IMAP_LSUB.h"
|
||||
#include "__IMAP_RENAME.h"
|
||||
#include "__IMAP_SEARCH.h"
|
||||
#include "__IMAP_SELECT.h"
|
||||
#include "__IMAP_STARTTLS.h"
|
||||
#include "__IMAP_STATUS.h"
|
||||
#include "__IMAP_STORE.h"
|
||||
#include "__IMAP_SUBSCRIBE.h"
|
||||
#include "__IMAP_UID.h"
|
||||
#include "__IMAP_UNSUBSCRIBE.h"
|
||||
# include "TCPServer.h"
|
||||
# include "Exception.h"
|
||||
# include "MailFileSystem.h"
|
||||
# include "__IMAP_APPEND.h"
|
||||
# include "__IMAP_AUTHENTICATE.h"
|
||||
# include "__IMAP_CHECK.h"
|
||||
# include "__IMAP_CLOSE.h"
|
||||
# include "__IMAP_COPY.h"
|
||||
# include "__IMAP_CREATE.h"
|
||||
# include "__IMAP_DELETE.h"
|
||||
# include "__IMAP_EXAMINE.h"
|
||||
# include "__IMAP_EXPUNGE.h"
|
||||
# include "__IMAP_FETCH.h"
|
||||
# include "__IMAP_LIST.h"
|
||||
# include "__IMAP_LOGIN.h"
|
||||
# include "__IMAP_LSUB.h"
|
||||
# include "__IMAP_RENAME.h"
|
||||
# include "__IMAP_SEARCH.h"
|
||||
# include "__IMAP_SELECT.h"
|
||||
# include "__IMAP_STARTTLS.h"
|
||||
# include "__IMAP_STATUS.h"
|
||||
# include "__IMAP_STORE.h"
|
||||
# include "__IMAP_SUBSCRIBE.h"
|
||||
# include "__IMAP_UID.h"
|
||||
# include "__IMAP_UNSUBSCRIBE.h"
|
||||
|
||||
namespace mail {
|
||||
|
||||
class IMAPService : public core::TCPServer {
|
||||
|
||||
class IMAPServer : public core::TCPServer {
|
||||
|
||||
public:
|
||||
IMAPService(core::EPoll &epoll, std::string hostName, std::string mailPath, core::IPAddress ipAddress)
|
||||
: TCPServer(epoll, ipAddress), mailFileSystem(mailPath), hostName(hostName) {
|
||||
IMAPServer(core::EPoll &epoll, std::string hostName, MailFileSystem &mailFileSystem, core::IPAddress ipAddress)
|
||||
: TCPServer(epoll, ipAddress, "IMAP Server"), mailFileSystem(mailFileSystem), hostName(hostName) {
|
||||
commands.add(_imap_append, "APPEND");
|
||||
commands.add(_imap_authenticate, "AUTHENTCATE");
|
||||
commands.add(_imap_check, "CHECK");
|
||||
@ -57,7 +58,7 @@ namespace mail {
|
||||
commands.add(_imap_unsubscribe, "UNSUBSCRIBE");
|
||||
}
|
||||
|
||||
MailFileSystem mailFileSystem;
|
||||
MailFileSystem &mailFileSystem;
|
||||
std::string hostName;
|
||||
|
||||
private:
|
@ -1,18 +1,26 @@
|
||||
#ifndef __IMAPSession_h__
|
||||
#define __IMAPSession_h__
|
||||
# define __IMAPSession_h__
|
||||
|
||||
# define CRLF "\r\n"
|
||||
|
||||
namespace mail {
|
||||
|
||||
|
||||
class IMAPSession : public core::TCPSession {
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
IMAPSession(core::EPoll &ePoll, core::TCPServer &server)
|
||||
: TCPSession(ePoll, server, "IMAP Client Session") {}
|
||||
|
||||
enum State { NOT_AUTHENTICATED, AUTHENTICATED, SELECTED };
|
||||
|
||||
std::string clientDomainName;
|
||||
std::string userName;
|
||||
std::string password;
|
||||
AuthState authstate = USER_UNKNOWN;
|
||||
bool relay = false;
|
||||
|
||||
State state = NOT_AUTHENTICATED;
|
||||
|
||||
void onConnected() override {
|
||||
out << "* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE STARTTLS AUTH=PLAIN AUTH=LOGIN] Dovecot (Ubuntu) ready." << CRLF;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef __POP3Service_h__
|
||||
#define __POP3Service_h__
|
||||
#ifndef __POP3Server_h__
|
||||
#define __POP3Server_h__
|
||||
|
||||
#include "TCPServer.h"
|
||||
#include "Exception.h"
|
||||
@ -18,11 +18,11 @@
|
||||
|
||||
namespace mail {
|
||||
|
||||
class POP3Service : public core::TCPServer {
|
||||
class POP3Server : public core::TCPServer {
|
||||
|
||||
public:
|
||||
POP3Service(core::EPoll &epoll, std::string hostName, std::string mailPath, core::IPAddress ipAddress)
|
||||
: TCPServer(epoll, ipAddress), mailFileSystem(mailPath), hostName(hostName) {
|
||||
POP3Server(core::EPoll &epoll, std::string hostName, MailFileSystem &mailFileSystem, core::IPAddress ipAddress)
|
||||
: TCPServer(epoll, ipAddress, "POP3 Server"), mailFileSystem(mailFileSystem), hostName(hostName) {
|
||||
commands.add(_pop3_dele, "DELE");
|
||||
commands.add(_pop3_last, "LAST");
|
||||
commands.add(_pop3_list, "LIST");
|
||||
@ -37,7 +37,7 @@ namespace mail {
|
||||
commands.add(_pop3_user, "USER");
|
||||
}
|
||||
|
||||
MailFileSystem mailFileSystem;
|
||||
MailFileSystem &mailFileSystem;
|
||||
std::string hostName;
|
||||
|
||||
private:
|
@ -24,9 +24,8 @@ 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;
|
||||
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) {
|
||||
commands.add(_smtp_auth, "AUTH");
|
||||
commands.add(_smtp_data, "DATA");
|
||||
commands.add(_smtp_ehlo, "EHLO");
|
||||
@ -41,7 +40,7 @@ namespace mail {
|
||||
wd = addWatch(mailPath + "/.queue/");
|
||||
}
|
||||
|
||||
MailFileSystem mailFileSystem;
|
||||
MailFileSystem &mailFileSystem;
|
||||
std::string hostName;
|
||||
std::string mailPath;
|
||||
|
||||
|
@ -18,8 +18,8 @@ namespace mail {
|
||||
SMTPSession(core::EPoll &ePoll, core::TCPServer &server)
|
||||
: TCPSession(ePoll, server, "SMTP Client Session") {}
|
||||
|
||||
void onConnected(std::stringstream &out) {
|
||||
out << "220 localhost BMAMail" << CRLF;
|
||||
void onConnected() override {
|
||||
out << "220 localhost BMAMail" << CRLF;
|
||||
}
|
||||
|
||||
std::string clientDomainName;
|
||||
|
9
__IMAP_APPEND.cpp
Normal file
9
__IMAP_APPEND.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include "__IMAP_APPEND.h"
|
||||
|
||||
namespace mail {
|
||||
|
||||
int __IMAP_APPEND::processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
||||
data << "250 OK" << CRLF;
|
||||
}
|
||||
|
||||
}
|
@ -8,9 +8,7 @@ namespace mail {
|
||||
|
||||
class __IMAP_APPEND : public IMAPCommand {
|
||||
|
||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
||||
data << "250 OK" << CRLF;
|
||||
}
|
||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data);
|
||||
|
||||
};
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
# include "IMAPCommand.h"
|
||||
# include "IMAPSession.h"
|
||||
# include "PString.h"
|
||||
|
||||
namespace mail {
|
||||
|
||||
|
19
main.cpp
19
main.cpp
@ -5,9 +5,10 @@
|
||||
#include "File.h"
|
||||
#include "Log.h"
|
||||
#include "IPAddress.h"
|
||||
#include "MailFileSystem.h"
|
||||
#include "SMTPServer.h"
|
||||
#include "POP3Service.h"
|
||||
#include "IMAPService.h"
|
||||
#include "POP3Server.h"
|
||||
#include "IMAPServer.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
@ -19,14 +20,16 @@ int main(int argc, char **argv) {
|
||||
std::string hostName = "localhost";
|
||||
std::string ipAddress = "0.0.0.0";
|
||||
std::string mailPath = "/var/mail";
|
||||
|
||||
mail::MailFileSystem mailFileSystem(mailPath);
|
||||
|
||||
core::EPoll ePoll;
|
||||
mail::SMTPServer smtpServer(ePoll, hostName, mailPath, core::IPAddress(ipAddress, 25));
|
||||
mail::POP3Service pop3Service(ePoll, hostName, mailPath, core::IPAddress(ipAddress, 110));
|
||||
mail::IMAPService imapService(ePoll, hostName, mailPath, core::IPAddress(ipAddress, 143));
|
||||
core::ConsoleServer consoleService(ePoll, core::IPAddress(ipAddress, 1027));
|
||||
consoleService.commands.add(consoleService.commands, "help");
|
||||
ePoll.start(2, 1000);
|
||||
mail::SMTPServer smtpServer(ePoll, hostName, mailFileSystem, core::IPAddress(ipAddress, 25));
|
||||
mail::POP3Server pop3Server(ePoll, hostName, mailFileSystem, core::IPAddress(ipAddress, 110));
|
||||
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(1, 1000);
|
||||
|
||||
while(true)
|
||||
sleep(300);
|
||||
|
@ -13,4 +13,4 @@ rm -rf /var/mail/barant.com/barant/Inbox/*
|
||||
./testsmtp &
|
||||
./testsmtp &
|
||||
./testsmtp &
|
||||
|
||||
wait
|
@ -13,4 +13,4 @@ rm -rf /var/mail/barant.com/barant/Inbox/*
|
||||
./submitmailtest &
|
||||
./submitmailtest &
|
||||
./submitmailtest &
|
||||
|
||||
wait
|
Loading…
x
Reference in New Issue
Block a user