Continued work.
This commit is contained in:
parent
30cd31c171
commit
c9cdc822a2
@ -1,15 +1,20 @@
|
||||
|
||||
#include "MailFileSystem.h"
|
||||
# include "INotify.h"
|
||||
# include "Log.h"
|
||||
|
||||
namespace mail {
|
||||
|
||||
MailFileSystem::MailFileSystem(coreutils::ZString &mailPath) : mailPath(mailPath) {}
|
||||
MailFileSystem::MailFileSystem(coreutils::ZString &mailPath) : mailPath(mailPath) {
|
||||
queuePath << mailPath << "/.queue/";
|
||||
}
|
||||
|
||||
bool MailFileSystem::ifMailBoxExists(coreutils::ZString &mailbox) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "if exists mailbox: " << mailbox << ".";
|
||||
if(stat(getMailBoxPath(mailbox).c_str(), &statbuf) != -1)
|
||||
if(S_ISDIR(statbuf.st_mode))
|
||||
return true;
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "doesnt exist mailbox: " << mailbox << ".";
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -36,4 +41,8 @@ namespace mail {
|
||||
return mailPath;
|
||||
}
|
||||
|
||||
coreutils::ZString& MailFileSystem::getQueuePath() {
|
||||
return queuePath;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,13 +17,17 @@ namespace mail {
|
||||
coreutils::MString getMailBoxPath(coreutils::ZString &mailbox);
|
||||
std::vector<coreutils::MString> getAliasMailboxes(coreutils::ZString &alias);
|
||||
coreutils::ZString& getMailPath();
|
||||
coreutils::ZString& getQueuePath();
|
||||
|
||||
private:
|
||||
coreutils::ZString &mailPath;
|
||||
coreutils::MString queuePath;
|
||||
struct stat statbuf;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -9,17 +9,17 @@
|
||||
namespace mail {
|
||||
|
||||
class SMTPServer;
|
||||
|
||||
|
||||
class SMTPCommand : public core::Command {
|
||||
|
||||
|
||||
public:
|
||||
virtual int processCommand(coreutils::ZString &request, core::TCPSession &session);
|
||||
virtual int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server);
|
||||
void grabInput(SMTPSession &session);
|
||||
void clearGrab(SMTPSession &session);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
76
SMTPServer.h
76
SMTPServer.h
@ -2,6 +2,8 @@
|
||||
# define __SMTPServer_h__
|
||||
|
||||
# include <string>
|
||||
# include <vector>
|
||||
# include <filesystem>
|
||||
# include "EPoll.h"
|
||||
# include "TCPServer.h"
|
||||
# include "SMTPSession.h"
|
||||
@ -18,14 +20,15 @@
|
||||
# include "__SMTP_VRFY.h"
|
||||
# include "INotify.h"
|
||||
# include "Log.h"
|
||||
# include "SendMail.h"
|
||||
|
||||
namespace mail {
|
||||
|
||||
|
||||
class SMTPServer : public core::TCPServer, public core::INotify {
|
||||
|
||||
|
||||
public:
|
||||
SMTPServer(core::EPoll &ePoll, std::string hostName, MailFileSystem &mailFileSystem, core::IPAddress ipAddress)
|
||||
: core::TCPServer(ePoll, ipAddress, " ", 1, "SMTP Server"), core::INotify(ePoll), hostName(hostName), mailFileSystem(mailFileSystem) {
|
||||
SMTPServer(core::EPoll &ePoll, std::string hostName, MailFileSystem &mailFileSystem, core::IPAddress ipAddress)
|
||||
: core::TCPServer(ePoll, ipAddress, " ", 1, "SMTP Server"), core::INotify(ePoll), ePoll(ePoll), hostName(hostName), mailFileSystem(mailFileSystem) {
|
||||
commands.add(_smtp_auth, "AUTH");
|
||||
commands.add(_smtp_data, "DATA");
|
||||
commands.add(_smtp_ehlo, "EHLO");
|
||||
@ -37,37 +40,41 @@ namespace mail {
|
||||
commands.add(_smtp_rset, "RSET");
|
||||
commands.add(_smtp_vrfy, "VRFY");
|
||||
processExisting();
|
||||
wd = addWatch(mailPath + "/.queue/");
|
||||
}
|
||||
|
||||
wd = addWatch(mailFileSystem.getQueuePath());
|
||||
}
|
||||
|
||||
MailFileSystem &mailFileSystem;
|
||||
std::string hostName;
|
||||
std::string mailPath;
|
||||
|
||||
SMTPSession * getSocketAccept(core::EPoll &ePoll) override {
|
||||
core::EPoll &ePoll;
|
||||
|
||||
SMTPSession * getSocketAccept(core::EPoll &ePoll) override {
|
||||
return new SMTPSession(ePoll, *this);
|
||||
}
|
||||
|
||||
void sessionErrorHandler(std::string errorString, std::stringstream &out) {
|
||||
out << "252 " << errorString << CRLF;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
coreutils::ZString recipient = name.substr(pos);
|
||||
if(recipient != "") {
|
||||
coreutils::MString fileName;
|
||||
fileName << mailPath << "/.queue/" << name;
|
||||
coreutils::MString path;
|
||||
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 << ".";
|
||||
}
|
||||
void inCreate(coreutils::ZString &name) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "inCreate; [" << name << "]";
|
||||
name.split("|");
|
||||
if(name.getList().size() > 1) {
|
||||
bool exists = mailFileSystem.ifMailBoxExists(name[1]);
|
||||
coreutils::MString path;
|
||||
path << mailFileSystem.getMailBoxPath(name[1]) << "/Inbox/" << name[0];
|
||||
coreutils::MString from;
|
||||
from << mailFileSystem.getQueuePath() << "/" << name;
|
||||
if(exists) {
|
||||
int rc = link(from.c_str(), path.c_str());
|
||||
rc = unlink(from.c_str());
|
||||
coreutils::Log(coreutils::LOG_INFO) << "Message " << name[0] << " delivered to recipient " << name[1] << ".";
|
||||
} else {
|
||||
mailQueue.emplace_back(SendMail(ePoll, name[1].str(), name[1].str(), from.str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
__SMTP_AUTH _smtp_auth;
|
||||
__SMTP_DATA _smtp_data;
|
||||
@ -80,11 +87,16 @@ namespace mail {
|
||||
__SMTP_RSET _smtp_rset;
|
||||
__SMTP_VRFY _smtp_vrfy;
|
||||
int wd;
|
||||
|
||||
std::vector<SendMail> mailQueue;
|
||||
|
||||
void processExisting() {
|
||||
|
||||
for (const auto & entry : std::filesystem::directory_iterator(mailFileSystem.getQueuePath().str())) {
|
||||
std::string temp(entry.path().filename().string());
|
||||
coreutils::ZString temp2(temp);
|
||||
inCreate(temp2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -1,12 +1,14 @@
|
||||
# include "SMTPSession.h"
|
||||
# include "Log.h"
|
||||
|
||||
namespace mail {
|
||||
|
||||
SMTPSession::SMTPSession(core::EPoll &ePoll, core::TCPServer &server)
|
||||
|
||||
SMTPSession::SMTPSession(core::EPoll &ePoll, core::TCPServer &server)
|
||||
: TCPSession(ePoll, server, "SMTP Client Session") {}
|
||||
|
||||
void SMTPSession::onConnected() {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "onConnected -> sending 220";
|
||||
out << "220 localhost BMAMail" << CRLF;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,31 +8,31 @@
|
||||
# define CRLF "\r\n"
|
||||
|
||||
namespace mail {
|
||||
|
||||
enum State {CONNECT, READY, MAIL, RCPT, DATA};
|
||||
|
||||
enum State {CONNECT, READY, READYX, MAIL, RCPT, DATA, SENT};
|
||||
enum AuthState {USER_UNKNOWN, USER_QUERY, USER_SECRET_QUERY, USER_KNOWN};
|
||||
enum Mode {WAIT_FOR_DATA, RECEIVE_DATA};
|
||||
|
||||
|
||||
class SMTPSession : public core::TCPSession {
|
||||
|
||||
public:
|
||||
SMTPSession(core::EPoll &ePoll, core::TCPServer &server);
|
||||
|
||||
|
||||
public:
|
||||
SMTPSession(core::EPoll &ePoll, core::TCPServer &server);
|
||||
|
||||
void onConnected() override;
|
||||
|
||||
|
||||
coreutils::MString clientDomainName;
|
||||
coreutils::MString userName;
|
||||
coreutils::MString password;
|
||||
std::stringstream mailData;
|
||||
coreutils::MString password;
|
||||
coreutils::MString mailData;
|
||||
State state = CONNECT;
|
||||
AuthState authState = USER_UNKNOWN;
|
||||
AuthState authState = USER_UNKNOWN;
|
||||
Mode mode = WAIT_FOR_DATA;
|
||||
bool relay = false;
|
||||
coreutils::MString sender;
|
||||
bool relay = true;
|
||||
coreutils::MString from;
|
||||
std::vector<coreutils::MString> recipientList;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
100
SendMail.cpp
Normal file
100
SendMail.cpp
Normal file
@ -0,0 +1,100 @@
|
||||
#include "SendMail.h"
|
||||
#include <chrono>
|
||||
|
||||
namespace mail {
|
||||
|
||||
SendMail::SendMail(core::EPoll &ePoll, std::string from, std::string recipient, std::string mailFileName)
|
||||
: core::TCPSession2(ePoll, "Send Mail Agent"), from(from), recipient(recipient), mailFileName(mailFileName),
|
||||
mailData(mailFileName), Timer(ePoll, 0.00f), ePoll(ePoll) {
|
||||
|
||||
core::IPAddress mxAddress("127.0.0.1", 9025);
|
||||
|
||||
connect(mxAddress);
|
||||
ePoll.registerSocket((TCPSession2 *)(this));
|
||||
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "SendMail initiated...";
|
||||
|
||||
}
|
||||
|
||||
SendMail::~SendMail() {
|
||||
ePoll.unregisterSocket((TCPSession2 *)(this));
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "SendMail destructing...";
|
||||
}
|
||||
|
||||
void SendMail::onTimeout() {
|
||||
state = stateOnTimeout;
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "onTimeout...";
|
||||
protocol(buffer);
|
||||
TCPSession2::send();
|
||||
}
|
||||
|
||||
void SendMail::protocol(coreutils::ZString &data) {
|
||||
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "[" << data << "..." << state;
|
||||
|
||||
switch (state) {
|
||||
|
||||
case CONNECT:
|
||||
// read recipient
|
||||
// parse email for name and domain name
|
||||
// open tcpsocket with connect
|
||||
// wait for greeting
|
||||
if(data.asInteger() == 220) {
|
||||
out << "EHLO " << from << CRLF;
|
||||
state = READY;
|
||||
}
|
||||
break;
|
||||
|
||||
case READY:
|
||||
buffer = data;
|
||||
setTimer(.05);
|
||||
stateOnTimeout = READYX;
|
||||
break;
|
||||
|
||||
case READYX:
|
||||
if(buffer.asInteger() == 250) {
|
||||
out << "MAIL FROM:<" << from << ">" << CRLF;
|
||||
state = MAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case MAIL:
|
||||
if(data.asInteger() == 250) {
|
||||
out << "RCPT TO:<" << recipient << ">" << CRLF;
|
||||
state = RCPT;
|
||||
}
|
||||
break;
|
||||
|
||||
case RCPT:
|
||||
if(data.asInteger() == 250) {
|
||||
out << "DATA" << CRLF;
|
||||
state = DATA;
|
||||
}
|
||||
break;
|
||||
|
||||
case DATA:
|
||||
if(data.asInteger() == 354) {
|
||||
while(!mailData.eof()) {
|
||||
mailData.readLine();
|
||||
out << mailData.asZString() << CRLF;
|
||||
}
|
||||
out << "." << CRLF;
|
||||
state = SENT;
|
||||
}
|
||||
break;
|
||||
|
||||
case SENT:
|
||||
if(data.asInteger() == 250) {
|
||||
out << "QUIT" << CRLF;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::vector<coreutils::MString>& SendMail::extractRecipientList() {
|
||||
return recipientList;
|
||||
}
|
||||
|
||||
}
|
43
SendMail.h
Normal file
43
SendMail.h
Normal file
@ -0,0 +1,43 @@
|
||||
#ifndef __SendMail_h__
|
||||
#define __SendMail_h__
|
||||
|
||||
#include "EPoll.h"
|
||||
#include "SMTPSession.h"
|
||||
#include "TCPSession2.h"
|
||||
#include "MString.h"
|
||||
#include "Timer.h"
|
||||
|
||||
#define CRLF "\r\n"
|
||||
|
||||
namespace mail {
|
||||
|
||||
class SendMail : public core::TCPSession2, private core::Timer {
|
||||
|
||||
public:
|
||||
SendMail(core::EPoll &ePoll, std::string from, std::string recipient, std::string mailFileName);
|
||||
~SendMail();
|
||||
coreutils::MString& send();
|
||||
|
||||
void protocol(coreutils::ZString &data) override;
|
||||
|
||||
private:
|
||||
std::vector<coreutils::MString>& extractRecipientList();
|
||||
void onTimeout() override;
|
||||
|
||||
core::EPoll &ePoll;
|
||||
|
||||
coreutils::File mailData;
|
||||
coreutils::MString from;
|
||||
coreutils::MString recipient;
|
||||
coreutils::MString mailFileName;
|
||||
coreutils::MString buffer;
|
||||
std::vector<coreutils::MString> recipientList;
|
||||
|
||||
State state = CONNECT;
|
||||
State stateOnTimeout = CONNECT;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -3,55 +3,55 @@
|
||||
#include "SMTPServer.h"
|
||||
|
||||
namespace mail {
|
||||
|
||||
|
||||
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;
|
||||
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;
|
||||
|
||||
session.authState = USER_QUERY;
|
||||
grabInput(session);
|
||||
}
|
||||
else {
|
||||
session.out << "504 AUTH method not supported." << CRLF;
|
||||
}
|
||||
return 1;
|
||||
|
||||
case USER_QUERY:
|
||||
session.userName = request[0];
|
||||
session.userName = request[0];
|
||||
// setTimer(0.0f);
|
||||
session.out << "334 UGFzc3dvcmQ6" << CRLF;
|
||||
session.out << "334 UGFzc3dvcmQ6" << CRLF;
|
||||
// setTimer(10.0f);
|
||||
session.authState = USER_SECRET_QUERY;
|
||||
return 1;
|
||||
|
||||
session.authState = USER_SECRET_QUERY;
|
||||
return 1;
|
||||
|
||||
case USER_SECRET_QUERY:
|
||||
session.password = request[0];
|
||||
session.password = request[0];
|
||||
// setTimer(0.0f);
|
||||
coreutils::Base64 base64;
|
||||
if(authLogin(session.userName, session.password, server)) {
|
||||
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;
|
||||
coreutils::Base64 base64;
|
||||
if(authLogin(session.userName, session.password, server)) {
|
||||
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) {
|
||||
coreutils::MString secretPath;
|
||||
secretPath << server.mailFileSystem.getMailBoxPath(userName) << "/.password";
|
||||
secretPath << server.mailFileSystem.getMailBoxPath(userName) << "/.password";
|
||||
coreutils::File secret(secretPath);
|
||||
secret.read();
|
||||
return password == secret.asString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace mail {
|
||||
|
||||
case RCPT:
|
||||
session.out << "354 Enter the mail message terminated by <CRLF>.<CRLF>" << CRLF;
|
||||
session.mailData.str("");
|
||||
session.mailData = "";
|
||||
session.mode = RECEIVE_DATA;
|
||||
grabInput(session);
|
||||
// session.setTimer(120.0f);
|
||||
@ -34,16 +34,17 @@ namespace mail {
|
||||
break;
|
||||
|
||||
case RECEIVE_DATA:
|
||||
if(request != ".")
|
||||
if(request != ".") {
|
||||
session.mailData << request << 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) {
|
||||
coreutils::MString ID = queueMail(server, session.sender, session.recipientList, session.mailData);
|
||||
if(session.mailData.getLength() > 0) {
|
||||
coreutils::MString ID = queueMail(server, session.from, session.recipientList, session.mailData);
|
||||
if(ID != "") {
|
||||
coreutils::Log(coreutils::LOG_INFO) << "Queued message " << ID << ".";
|
||||
session.out << "250 OK Queued message " << ID << CRLF;
|
||||
@ -57,7 +58,7 @@ namespace mail {
|
||||
// } else
|
||||
// data << "550 Message is probably spam" << CRLF;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -73,15 +74,16 @@ namespace mail {
|
||||
coreutils::MString __SMTP_DATA::queueMail(SMTPServer &server,
|
||||
coreutils::MString &sender,
|
||||
std::vector<coreutils::MString> &recipientList,
|
||||
std::stringstream &mailData) {
|
||||
coreutils::MString &mailData) {
|
||||
coreutils::MString fileName;
|
||||
fileName << server.mailFileSystem.getMailPath() << "/.queue/" << generateMailFileName();
|
||||
fileName << server.mailFileSystem.getMailPath() << "/.queue/" << generateMailFileName();
|
||||
coreutils::File mailFile(fileName, O_CREAT | O_WRONLY, 0660);
|
||||
mailFile.write(mailData.str());
|
||||
mailFile.write(mailData);
|
||||
|
||||
for(coreutils::MString recipient: recipientList) {
|
||||
coreutils::MString newName(fileName.write(recipient));
|
||||
link(fileName.c_str(), newName.c_str());
|
||||
coreutils::MString newName;
|
||||
newName << fileName << "|" << recipient;
|
||||
link(fileName.c_str(), newName.c_str());
|
||||
}
|
||||
|
||||
unlink(fileName.c_str());
|
||||
|
@ -13,7 +13,7 @@ namespace mail {
|
||||
int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override;
|
||||
|
||||
coreutils::MString generateMailFileName();
|
||||
coreutils::MString queueMail(SMTPServer &server, coreutils::MString &sender, std::vector<coreutils::MString> &recipientList, std::stringstream &mailData);
|
||||
coreutils::MString queueMail(SMTPServer &server, coreutils::MString &sender, std::vector<coreutils::MString> &recipientList, coreutils::MString &mailData);
|
||||
|
||||
};
|
||||
|
||||
|
@ -2,11 +2,11 @@
|
||||
#include "SMTPServer.h"
|
||||
|
||||
namespace mail {
|
||||
|
||||
|
||||
int __SMTP_EHLO::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
||||
|
||||
session.clientDomainName = request[1];
|
||||
std::cout << "{" << session.clientDomainName << "}" << std::endl;
|
||||
// std::cout << "{" << session.clientDomainName << "}" << std::endl;
|
||||
session.out << "250-" << server.hostName << CRLF;
|
||||
// cout << "250-STARTTLS" << CRLF;
|
||||
// cout << "250-PIPELINING" << CRLF;
|
||||
@ -16,5 +16,5 @@ namespace mail {
|
||||
session.state = READY;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ namespace mail {
|
||||
if(request[1].ifNext("FROM:")) {
|
||||
request[1].skipWhitespace();
|
||||
if(request[1].ifNext("<")) {
|
||||
session.sender = request[1].getTokenExclude(">");
|
||||
session.from = request[1].getTokenExclude(">");
|
||||
if(session.authState = USER_KNOWN) {
|
||||
session.out << "250 OK" << CRLF;
|
||||
session.recipientList.clear();
|
||||
@ -20,11 +20,11 @@ namespace mail {
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string domainOnly(std::string email) {
|
||||
coreutils::ZString split(email);
|
||||
split.split("@");
|
||||
return split[1].str();
|
||||
}
|
||||
// std::string domainOnly(std::string email) {
|
||||
// coreutils::ZString split(email);
|
||||
// split.split("@");
|
||||
// return split[1].str();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
@ -2,39 +2,30 @@
|
||||
# include "SMTPServer.h"
|
||||
|
||||
namespace mail {
|
||||
|
||||
int __SMTP_RCPT::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
||||
std::cout << "001" << std::endl;
|
||||
|
||||
int __SMTP_RCPT::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
||||
if((session.state == MAIL) || (session.state == RCPT)) {
|
||||
std::cout << "002" << std::endl;
|
||||
if(request[1].ifNext("TO:")) {
|
||||
std::cout << "003" << std::endl;
|
||||
if(request[1].ifNext("TO:")) {
|
||||
request[1].skipWhitespace();
|
||||
if(request[1].ifNext("<")) {
|
||||
std::cout << "004" << std::endl;
|
||||
coreutils::MString recipient(request[1].getTokenExclude(">"));
|
||||
if(server.mailFileSystem.ifMailBoxExists(recipient)) {
|
||||
std::cout << "005" << std::endl;
|
||||
session.recipientList.push_back(recipient);
|
||||
std::cout << "006" << std::endl;
|
||||
session.out << "250 OK" << CRLF;
|
||||
std::cout << "007" << std::endl;
|
||||
session.state = RCPT;
|
||||
std::cout << "008" << std::endl;
|
||||
} else if(session.relay) {
|
||||
if(server.mailFileSystem.ifMailBoxExists(recipient)) {
|
||||
session.recipientList.push_back(recipient);
|
||||
session.out << "250 OK" << CRLF;
|
||||
session.state = RCPT;
|
||||
} else
|
||||
session.out << "550 Mailbox does not exist" << CRLF;
|
||||
session.state = RCPT;
|
||||
} else if(session.relay) {
|
||||
session.recipientList.push_back(recipient);
|
||||
session.out << "250 OK" << CRLF;
|
||||
session.state = RCPT;
|
||||
} else
|
||||
session.out << "550 Mailbox does not exist" << CRLF;
|
||||
} else
|
||||
session.out << "550 Usage: RCPT TO:<email-address>" << CRLF;
|
||||
} else
|
||||
session.out << "550 Usage: RCPT TO:<email-address>" << CRLF;
|
||||
} else
|
||||
session.out << "550 Usage: RCPT TO:<email-address>" << CRLF;
|
||||
} else
|
||||
session.out << "503 Please use MAIL first" << CRLF;
|
||||
std::cout << "009" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
2
compile
2
compile
@ -5,7 +5,7 @@ do
|
||||
filename="${file%.*}"
|
||||
list="$list $filename.o"
|
||||
echo -n "Compiling $filename..."
|
||||
g++ -g -c -std=c++17 -I../CoreUtils -I../ServerCore $file
|
||||
g++ -g -c -std=c++17 -I../CoreUtils -I../ServerCore $file &
|
||||
if [ $? = '0' ]
|
||||
then
|
||||
echo "OK"
|
||||
|
5
main.cpp
5
main.cpp
@ -24,15 +24,16 @@ int main(int argc, char **argv) {
|
||||
mail::MailFileSystem mailFileSystem(mailPath);
|
||||
|
||||
core::EPoll ePoll;
|
||||
ePoll.start(2, 1000);
|
||||
mail::SMTPServer smtpServer(ePoll, hostName, mailFileSystem, core::IPAddress(ipAddress, 9025));
|
||||
// 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(2, 1000);
|
||||
consoleServer.commands.add(smtpServer.commands, "smtp");
|
||||
|
||||
while(true)
|
||||
sleep(300);
|
||||
sleep(3600);
|
||||
|
||||
ePoll.stop();
|
||||
|
||||
|
17
scripts/makemaildir
Executable file
17
scripts/makemaildir
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
cd /var/mail
|
||||
mkdir .queue
|
||||
mkdir barant.com
|
||||
cd barant.com
|
||||
mkdir barant
|
||||
mkdir brad.arant
|
||||
cd barant
|
||||
mkdir Inbox
|
||||
mkdir Sent
|
||||
mdkdir Trash
|
||||
mkdir Spam
|
||||
cd ../brad.arant
|
||||
mkdir Inbox
|
||||
mkdir Sent
|
||||
mdkdir Trash
|
||||
mkdir Spam
|
@ -3,14 +3,10 @@ rm -rf /var/mail/.queue/*
|
||||
rm -rf /var/mail/barant.com/brad.arant/Inbox/*
|
||||
rm -rf /var/mail/barant.com/barant/Inbox/*
|
||||
|
||||
./testsmtp &
|
||||
./testsmtp &
|
||||
./testsmtp &
|
||||
./testsmtp &
|
||||
./testsmtp &
|
||||
./testsmtp &
|
||||
./testsmtp &
|
||||
./testsmtp &
|
||||
./testsmtp &
|
||||
./testsmtp &
|
||||
for count in {1..256};
|
||||
do
|
||||
echo $count
|
||||
./testsmtp &
|
||||
sleep .005
|
||||
done
|
||||
wait
|
||||
|
@ -1,17 +1,16 @@
|
||||
#!/bin/bash
|
||||
nc localhost 9025 > /dev/null << EOL
|
||||
nc localhost 9025 > /dev/null << EOL
|
||||
EHLO barant.com
|
||||
MAIL FROM: <brad.arant@barant.com>
|
||||
RCPT TO: <barant@barant.com>
|
||||
RCPT TO: <brad.arant@barant.com>
|
||||
RCPT TO: <brad.arant@gmail.com>
|
||||
DATA
|
||||
From: barant@barant.com
|
||||
To: barant@barant.com
|
||||
Subject: test email system
|
||||
|
||||
This is a test
|
||||
|
||||
.
|
||||
|
||||
QUIT
|
||||
EOL
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user