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,20 +2,17 @@
|
|||||||
# define __IMAPCommand_h__
|
# define __IMAPCommand_h__
|
||||||
|
|
||||||
# include "Command.h"
|
# include "Command.h"
|
||||||
# include "TCPSession.h"
|
|
||||||
# include "IMAPSession.h"
|
# include "IMAPSession.h"
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
|
class IMAPServer;
|
||||||
|
|
||||||
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(std::string request, core::TCPSession *session, std::stringstream &data) override;
|
||||||
coreutils::PString parser(request);
|
virtual int processCommand(coreutils::PString request, IMAPSession &session, IMAPServer &server, std::stringstream &data) {}
|
||||||
return processCommand(parser, (IMAPSession &)*session, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
#ifndef __IMAPService_h__
|
#ifndef __IMAPServer_h__
|
||||||
#define __IMAPService_h__
|
# define __IMAPServer_h__
|
||||||
|
|
||||||
# include "TCPServer.h"
|
# include "TCPServer.h"
|
||||||
# include "Exception.h"
|
# include "Exception.h"
|
||||||
|
# include "MailFileSystem.h"
|
||||||
# include "__IMAP_APPEND.h"
|
# include "__IMAP_APPEND.h"
|
||||||
# include "__IMAP_AUTHENTICATE.h"
|
# include "__IMAP_AUTHENTICATE.h"
|
||||||
# include "__IMAP_CHECK.h"
|
# include "__IMAP_CHECK.h"
|
||||||
@ -28,11 +29,11 @@
|
|||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class IMAPService : public core::TCPServer {
|
class IMAPServer : public core::TCPServer {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IMAPService(core::EPoll &epoll, std::string hostName, std::string mailPath, core::IPAddress ipAddress)
|
IMAPServer(core::EPoll &epoll, std::string hostName, MailFileSystem &mailFileSystem, core::IPAddress ipAddress)
|
||||||
: TCPServer(epoll, ipAddress), mailFileSystem(mailPath), hostName(hostName) {
|
: TCPServer(epoll, ipAddress, "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");
|
||||||
@ -57,7 +58,7 @@ namespace mail {
|
|||||||
commands.add(_imap_unsubscribe, "UNSUBSCRIBE");
|
commands.add(_imap_unsubscribe, "UNSUBSCRIBE");
|
||||||
}
|
}
|
||||||
|
|
||||||
MailFileSystem mailFileSystem;
|
MailFileSystem &mailFileSystem;
|
||||||
std::string hostName;
|
std::string hostName;
|
||||||
|
|
||||||
private:
|
private:
|
@ -1,18 +1,26 @@
|
|||||||
#ifndef __IMAPSession_h__
|
#ifndef __IMAPSession_h__
|
||||||
# define __IMAPSession_h__
|
# define __IMAPSession_h__
|
||||||
|
|
||||||
|
# define CRLF "\r\n"
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class IMAPSession : public core::TCPSession {
|
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 clientDomainName;
|
||||||
std::string userName;
|
std::string userName;
|
||||||
std::string password;
|
std::string password;
|
||||||
AuthState authstate = USER_UNKNOWN;
|
State state = NOT_AUTHENTICATED;
|
||||||
bool relay = false;
|
|
||||||
|
|
||||||
|
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__
|
#ifndef __POP3Server_h__
|
||||||
#define __POP3Service_h__
|
#define __POP3Server_h__
|
||||||
|
|
||||||
#include "TCPServer.h"
|
#include "TCPServer.h"
|
||||||
#include "Exception.h"
|
#include "Exception.h"
|
||||||
@ -18,11 +18,11 @@
|
|||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
class POP3Service : public core::TCPServer {
|
class POP3Server : public core::TCPServer {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
POP3Service(core::EPoll &epoll, std::string hostName, std::string mailPath, core::IPAddress ipAddress)
|
POP3Server(core::EPoll &epoll, std::string hostName, MailFileSystem &mailFileSystem, core::IPAddress ipAddress)
|
||||||
: TCPServer(epoll, ipAddress), mailFileSystem(mailPath), hostName(hostName) {
|
: TCPServer(epoll, ipAddress, "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");
|
||||||
@ -37,7 +37,7 @@ namespace mail {
|
|||||||
commands.add(_pop3_user, "USER");
|
commands.add(_pop3_user, "USER");
|
||||||
}
|
}
|
||||||
|
|
||||||
MailFileSystem mailFileSystem;
|
MailFileSystem &mailFileSystem;
|
||||||
std::string hostName;
|
std::string hostName;
|
||||||
|
|
||||||
private:
|
private:
|
@ -24,9 +24,8 @@ namespace mail {
|
|||||||
class SMTPServer : public core::TCPServer, public core::INotify {
|
class SMTPServer : public core::TCPServer, public core::INotify {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SMTPServer(core::EPoll &ePoll, std::string hostName, std::string mailPath, 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(mailPath) {
|
: core::TCPServer(ePoll, ipAddress, "SMTP Server"), core::INotify(ePoll), hostName(hostName), mailFileSystem(mailFileSystem) {
|
||||||
this->mailPath = mailPath;
|
|
||||||
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");
|
||||||
@ -41,7 +40,7 @@ namespace mail {
|
|||||||
wd = addWatch(mailPath + "/.queue/");
|
wd = addWatch(mailPath + "/.queue/");
|
||||||
}
|
}
|
||||||
|
|
||||||
MailFileSystem mailFileSystem;
|
MailFileSystem &mailFileSystem;
|
||||||
std::string hostName;
|
std::string hostName;
|
||||||
std::string mailPath;
|
std::string mailPath;
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ namespace mail {
|
|||||||
SMTPSession(core::EPoll &ePoll, core::TCPServer &server)
|
SMTPSession(core::EPoll &ePoll, core::TCPServer &server)
|
||||||
: TCPSession(ePoll, server, "SMTP Client Session") {}
|
: TCPSession(ePoll, server, "SMTP Client Session") {}
|
||||||
|
|
||||||
void onConnected(std::stringstream &out) {
|
void onConnected() override {
|
||||||
out << "220 localhost BMAMail" << CRLF;
|
out << "220 localhost BMAMail" << CRLF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
class __IMAP_APPEND : public IMAPCommand {
|
||||||
|
|
||||||
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data) {
|
int processCommand(coreutils::PString request, IMAPSession &session, std::stringstream &data);
|
||||||
data << "250 OK" << CRLF;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
# include "IMAPCommand.h"
|
# include "IMAPCommand.h"
|
||||||
# include "IMAPSession.h"
|
# include "IMAPSession.h"
|
||||||
|
# include "PString.h"
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
|
19
main.cpp
19
main.cpp
@ -5,9 +5,10 @@
|
|||||||
#include "File.h"
|
#include "File.h"
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "IPAddress.h"
|
#include "IPAddress.h"
|
||||||
|
#include "MailFileSystem.h"
|
||||||
#include "SMTPServer.h"
|
#include "SMTPServer.h"
|
||||||
#include "POP3Service.h"
|
#include "POP3Server.h"
|
||||||
#include "IMAPService.h"
|
#include "IMAPServer.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
@ -20,13 +21,15 @@ int main(int argc, char **argv) {
|
|||||||
std::string ipAddress = "0.0.0.0";
|
std::string ipAddress = "0.0.0.0";
|
||||||
std::string mailPath = "/var/mail";
|
std::string mailPath = "/var/mail";
|
||||||
|
|
||||||
|
mail::MailFileSystem mailFileSystem(mailPath);
|
||||||
|
|
||||||
core::EPoll ePoll;
|
core::EPoll ePoll;
|
||||||
mail::SMTPServer smtpServer(ePoll, hostName, mailPath, core::IPAddress(ipAddress, 25));
|
mail::SMTPServer smtpServer(ePoll, hostName, mailFileSystem, core::IPAddress(ipAddress, 25));
|
||||||
mail::POP3Service pop3Service(ePoll, hostName, mailPath, core::IPAddress(ipAddress, 110));
|
mail::POP3Server pop3Server(ePoll, hostName, mailFileSystem, core::IPAddress(ipAddress, 110));
|
||||||
mail::IMAPService imapService(ePoll, hostName, mailPath, core::IPAddress(ipAddress, 143));
|
mail::IMAPServer imapServer(ePoll, hostName, mailFileSystem, core::IPAddress(ipAddress, 143));
|
||||||
core::ConsoleServer consoleService(ePoll, core::IPAddress(ipAddress, 1027));
|
core::ConsoleServer consoleServer(ePoll, core::IPAddress(ipAddress, 1027));
|
||||||
consoleService.commands.add(consoleService.commands, "help");
|
consoleServer.commands.add(consoleServer.commands, "help");
|
||||||
ePoll.start(2, 1000);
|
ePoll.start(1, 1000);
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
sleep(300);
|
sleep(300);
|
||||||
|
@ -13,4 +13,4 @@ rm -rf /var/mail/barant.com/barant/Inbox/*
|
|||||||
./testsmtp &
|
./testsmtp &
|
||||||
./testsmtp &
|
./testsmtp &
|
||||||
./testsmtp &
|
./testsmtp &
|
||||||
|
wait
|
@ -13,4 +13,4 @@ rm -rf /var/mail/barant.com/barant/Inbox/*
|
|||||||
./submitmailtest &
|
./submitmailtest &
|
||||||
./submitmailtest &
|
./submitmailtest &
|
||||||
./submitmailtest &
|
./submitmailtest &
|
||||||
|
wait
|
Loading…
x
Reference in New Issue
Block a user