Continued work.
This commit is contained in:
parent
30cd31c171
commit
c9cdc822a2
@ -1,15 +1,20 @@
|
|||||||
|
|
||||||
#include "MailFileSystem.h"
|
#include "MailFileSystem.h"
|
||||||
# include "INotify.h"
|
# include "INotify.h"
|
||||||
|
# include "Log.h"
|
||||||
|
|
||||||
namespace mail {
|
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) {
|
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(stat(getMailBoxPath(mailbox).c_str(), &statbuf) != -1)
|
||||||
if(S_ISDIR(statbuf.st_mode))
|
if(S_ISDIR(statbuf.st_mode))
|
||||||
return true;
|
return true;
|
||||||
|
coreutils::Log(coreutils::LOG_DEBUG_2) << "doesnt exist mailbox: " << mailbox << ".";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,4 +41,8 @@ namespace mail {
|
|||||||
return mailPath;
|
return mailPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
coreutils::ZString& MailFileSystem::getQueuePath() {
|
||||||
|
return queuePath;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,17 @@ namespace mail {
|
|||||||
coreutils::MString getMailBoxPath(coreutils::ZString &mailbox);
|
coreutils::MString getMailBoxPath(coreutils::ZString &mailbox);
|
||||||
std::vector<coreutils::MString> getAliasMailboxes(coreutils::ZString &alias);
|
std::vector<coreutils::MString> getAliasMailboxes(coreutils::ZString &alias);
|
||||||
coreutils::ZString& getMailPath();
|
coreutils::ZString& getMailPath();
|
||||||
|
coreutils::ZString& getQueuePath();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
coreutils::ZString &mailPath;
|
coreutils::ZString &mailPath;
|
||||||
|
coreutils::MString queuePath;
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
42
SMTPServer.h
42
SMTPServer.h
@ -2,6 +2,8 @@
|
|||||||
# define __SMTPServer_h__
|
# define __SMTPServer_h__
|
||||||
|
|
||||||
# include <string>
|
# include <string>
|
||||||
|
# include <vector>
|
||||||
|
# include <filesystem>
|
||||||
# include "EPoll.h"
|
# include "EPoll.h"
|
||||||
# include "TCPServer.h"
|
# include "TCPServer.h"
|
||||||
# include "SMTPSession.h"
|
# include "SMTPSession.h"
|
||||||
@ -18,6 +20,7 @@
|
|||||||
# include "__SMTP_VRFY.h"
|
# include "__SMTP_VRFY.h"
|
||||||
# include "INotify.h"
|
# include "INotify.h"
|
||||||
# include "Log.h"
|
# include "Log.h"
|
||||||
|
# include "SendMail.h"
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
@ -25,7 +28,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, " ", 1, "SMTP Server"), core::INotify(ePoll), hostName(hostName), mailFileSystem(mailFileSystem) {
|
: core::TCPServer(ePoll, ipAddress, " ", 1, "SMTP Server"), core::INotify(ePoll), ePoll(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");
|
||||||
@ -37,12 +40,12 @@ namespace mail {
|
|||||||
commands.add(_smtp_rset, "RSET");
|
commands.add(_smtp_rset, "RSET");
|
||||||
commands.add(_smtp_vrfy, "VRFY");
|
commands.add(_smtp_vrfy, "VRFY");
|
||||||
processExisting();
|
processExisting();
|
||||||
wd = addWatch(mailPath + "/.queue/");
|
wd = addWatch(mailFileSystem.getQueuePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
MailFileSystem &mailFileSystem;
|
MailFileSystem &mailFileSystem;
|
||||||
std::string hostName;
|
std::string hostName;
|
||||||
std::string mailPath;
|
core::EPoll &ePoll;
|
||||||
|
|
||||||
SMTPSession * getSocketAccept(core::EPoll &ePoll) override {
|
SMTPSession * getSocketAccept(core::EPoll &ePoll) override {
|
||||||
return new SMTPSession(ePoll, *this);
|
return new SMTPSession(ePoll, *this);
|
||||||
@ -53,18 +56,22 @@ namespace mail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void inCreate(std::string name) {
|
void inCreate(coreutils::ZString &name) {
|
||||||
int pos = name.find(".") + 10;
|
coreutils::Log(coreutils::LOG_DEBUG_2) << "inCreate; [" << name << "]";
|
||||||
std::string mail = name.substr(0, pos);
|
name.split("|");
|
||||||
coreutils::ZString recipient = name.substr(pos);
|
if(name.getList().size() > 1) {
|
||||||
if(recipient != "") {
|
bool exists = mailFileSystem.ifMailBoxExists(name[1]);
|
||||||
coreutils::MString fileName;
|
|
||||||
fileName << mailPath << "/.queue/" << name;
|
|
||||||
coreutils::MString path;
|
coreutils::MString path;
|
||||||
path << mailFileSystem.getMailBoxPath(recipient) << "/Inbox/" << mail;
|
path << mailFileSystem.getMailBoxPath(name[1]) << "/Inbox/" << name[0];
|
||||||
int rc = link(fileName.c_str(), path.c_str());
|
coreutils::MString from;
|
||||||
rc = unlink(fileName.c_str());
|
from << mailFileSystem.getQueuePath() << "/" << name;
|
||||||
coreutils::Log(coreutils::LOG_INFO) << "Message " << mail << " delivered to " << recipient << ".";
|
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()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,9 +87,14 @@ namespace mail {
|
|||||||
__SMTP_RSET _smtp_rset;
|
__SMTP_RSET _smtp_rset;
|
||||||
__SMTP_VRFY _smtp_vrfy;
|
__SMTP_VRFY _smtp_vrfy;
|
||||||
int wd;
|
int wd;
|
||||||
|
std::vector<SendMail> mailQueue;
|
||||||
|
|
||||||
void processExisting() {
|
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,4 +1,5 @@
|
|||||||
# include "SMTPSession.h"
|
# include "SMTPSession.h"
|
||||||
|
# include "Log.h"
|
||||||
|
|
||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
@ -6,6 +7,7 @@ namespace mail {
|
|||||||
: TCPSession(ePoll, server, "SMTP Client Session") {}
|
: TCPSession(ePoll, server, "SMTP Client Session") {}
|
||||||
|
|
||||||
void SMTPSession::onConnected() {
|
void SMTPSession::onConnected() {
|
||||||
|
coreutils::Log(coreutils::LOG_DEBUG_2) << "onConnected -> sending 220";
|
||||||
out << "220 localhost BMAMail" << CRLF;
|
out << "220 localhost BMAMail" << CRLF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
namespace mail {
|
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 AuthState {USER_UNKNOWN, USER_QUERY, USER_SECRET_QUERY, USER_KNOWN};
|
||||||
enum Mode {WAIT_FOR_DATA, RECEIVE_DATA};
|
enum Mode {WAIT_FOR_DATA, RECEIVE_DATA};
|
||||||
|
|
||||||
@ -23,12 +23,12 @@ namespace mail {
|
|||||||
coreutils::MString clientDomainName;
|
coreutils::MString clientDomainName;
|
||||||
coreutils::MString userName;
|
coreutils::MString userName;
|
||||||
coreutils::MString password;
|
coreutils::MString password;
|
||||||
std::stringstream mailData;
|
coreutils::MString mailData;
|
||||||
State state = CONNECT;
|
State state = CONNECT;
|
||||||
AuthState authState = USER_UNKNOWN;
|
AuthState authState = USER_UNKNOWN;
|
||||||
Mode mode = WAIT_FOR_DATA;
|
Mode mode = WAIT_FOR_DATA;
|
||||||
bool relay = false;
|
bool relay = true;
|
||||||
coreutils::MString sender;
|
coreutils::MString from;
|
||||||
std::vector<coreutils::MString> recipientList;
|
std::vector<coreutils::MString> recipientList;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
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
|
@ -16,7 +16,7 @@ namespace mail {
|
|||||||
|
|
||||||
case RCPT:
|
case RCPT:
|
||||||
session.out << "354 Enter the mail message terminated by <CRLF>.<CRLF>" << CRLF;
|
session.out << "354 Enter the mail message terminated by <CRLF>.<CRLF>" << CRLF;
|
||||||
session.mailData.str("");
|
session.mailData = "";
|
||||||
session.mode = RECEIVE_DATA;
|
session.mode = RECEIVE_DATA;
|
||||||
grabInput(session);
|
grabInput(session);
|
||||||
// session.setTimer(120.0f);
|
// session.setTimer(120.0f);
|
||||||
@ -34,16 +34,17 @@ namespace mail {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case RECEIVE_DATA:
|
case RECEIVE_DATA:
|
||||||
if(request != ".")
|
if(request != ".") {
|
||||||
session.mailData << request << CRLF;
|
session.mailData << request << CRLF;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
session.mode = WAIT_FOR_DATA;
|
session.mode = WAIT_FOR_DATA;
|
||||||
session.state = READY;
|
session.state = READY;
|
||||||
clearGrab(session);
|
clearGrab(session);
|
||||||
// if(filterMessage(session.mailData)) {
|
// if(filterMessage(session.mailData)) {
|
||||||
if(session.recipientList.size() > 0) {
|
if(session.recipientList.size() > 0) {
|
||||||
if(session.mailData.str().size() > 0) {
|
if(session.mailData.getLength() > 0) {
|
||||||
coreutils::MString ID = queueMail(server, session.sender, session.recipientList, session.mailData);
|
coreutils::MString ID = queueMail(server, session.from, session.recipientList, session.mailData);
|
||||||
if(ID != "") {
|
if(ID != "") {
|
||||||
coreutils::Log(coreutils::LOG_INFO) << "Queued message " << ID << ".";
|
coreutils::Log(coreutils::LOG_INFO) << "Queued message " << ID << ".";
|
||||||
session.out << "250 OK Queued message " << ID << CRLF;
|
session.out << "250 OK Queued message " << ID << CRLF;
|
||||||
@ -73,14 +74,15 @@ namespace mail {
|
|||||||
coreutils::MString __SMTP_DATA::queueMail(SMTPServer &server,
|
coreutils::MString __SMTP_DATA::queueMail(SMTPServer &server,
|
||||||
coreutils::MString &sender,
|
coreutils::MString &sender,
|
||||||
std::vector<coreutils::MString> &recipientList,
|
std::vector<coreutils::MString> &recipientList,
|
||||||
std::stringstream &mailData) {
|
coreutils::MString &mailData) {
|
||||||
coreutils::MString fileName;
|
coreutils::MString fileName;
|
||||||
fileName << server.mailFileSystem.getMailPath() << "/.queue/" << generateMailFileName();
|
fileName << server.mailFileSystem.getMailPath() << "/.queue/" << generateMailFileName();
|
||||||
coreutils::File mailFile(fileName, O_CREAT | O_WRONLY, 0660);
|
coreutils::File mailFile(fileName, O_CREAT | O_WRONLY, 0660);
|
||||||
mailFile.write(mailData.str());
|
mailFile.write(mailData);
|
||||||
|
|
||||||
for(coreutils::MString recipient: recipientList) {
|
for(coreutils::MString recipient: recipientList) {
|
||||||
coreutils::MString newName(fileName.write(recipient));
|
coreutils::MString newName;
|
||||||
|
newName << fileName << "|" << recipient;
|
||||||
link(fileName.c_str(), newName.c_str());
|
link(fileName.c_str(), newName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ namespace mail {
|
|||||||
int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override;
|
int processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) override;
|
||||||
|
|
||||||
coreutils::MString generateMailFileName();
|
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);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ namespace mail {
|
|||||||
int __SMTP_EHLO::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
int __SMTP_EHLO::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
||||||
|
|
||||||
session.clientDomainName = request[1];
|
session.clientDomainName = request[1];
|
||||||
std::cout << "{" << session.clientDomainName << "}" << std::endl;
|
// std::cout << "{" << session.clientDomainName << "}" << std::endl;
|
||||||
session.out << "250-" << server.hostName << CRLF;
|
session.out << "250-" << server.hostName << CRLF;
|
||||||
// cout << "250-STARTTLS" << CRLF;
|
// cout << "250-STARTTLS" << CRLF;
|
||||||
// cout << "250-PIPELINING" << CRLF;
|
// cout << "250-PIPELINING" << CRLF;
|
||||||
|
@ -7,7 +7,7 @@ namespace mail {
|
|||||||
if(request[1].ifNext("FROM:")) {
|
if(request[1].ifNext("FROM:")) {
|
||||||
request[1].skipWhitespace();
|
request[1].skipWhitespace();
|
||||||
if(request[1].ifNext("<")) {
|
if(request[1].ifNext("<")) {
|
||||||
session.sender = request[1].getTokenExclude(">");
|
session.from = request[1].getTokenExclude(">");
|
||||||
if(session.authState = USER_KNOWN) {
|
if(session.authState = USER_KNOWN) {
|
||||||
session.out << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
session.recipientList.clear();
|
session.recipientList.clear();
|
||||||
@ -20,11 +20,11 @@ namespace mail {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string domainOnly(std::string email) {
|
// std::string domainOnly(std::string email) {
|
||||||
coreutils::ZString split(email);
|
// coreutils::ZString split(email);
|
||||||
split.split("@");
|
// split.split("@");
|
||||||
return split[1].str();
|
// return split[1].str();
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,23 +4,15 @@
|
|||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
int __SMTP_RCPT::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
int __SMTP_RCPT::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
||||||
std::cout << "001" << std::endl;
|
|
||||||
if((session.state == MAIL) || (session.state == RCPT)) {
|
if((session.state == MAIL) || (session.state == RCPT)) {
|
||||||
std::cout << "002" << std::endl;
|
|
||||||
if(request[1].ifNext("TO:")) {
|
if(request[1].ifNext("TO:")) {
|
||||||
std::cout << "003" << std::endl;
|
|
||||||
request[1].skipWhitespace();
|
request[1].skipWhitespace();
|
||||||
if(request[1].ifNext("<")) {
|
if(request[1].ifNext("<")) {
|
||||||
std::cout << "004" << std::endl;
|
|
||||||
coreutils::MString recipient(request[1].getTokenExclude(">"));
|
coreutils::MString recipient(request[1].getTokenExclude(">"));
|
||||||
if(server.mailFileSystem.ifMailBoxExists(recipient)) {
|
if(server.mailFileSystem.ifMailBoxExists(recipient)) {
|
||||||
std::cout << "005" << std::endl;
|
|
||||||
session.recipientList.push_back(recipient);
|
session.recipientList.push_back(recipient);
|
||||||
std::cout << "006" << std::endl;
|
|
||||||
session.out << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
std::cout << "007" << std::endl;
|
|
||||||
session.state = RCPT;
|
session.state = RCPT;
|
||||||
std::cout << "008" << std::endl;
|
|
||||||
} else if(session.relay) {
|
} else if(session.relay) {
|
||||||
session.recipientList.push_back(recipient);
|
session.recipientList.push_back(recipient);
|
||||||
session.out << "250 OK" << CRLF;
|
session.out << "250 OK" << CRLF;
|
||||||
@ -33,7 +25,6 @@ namespace mail {
|
|||||||
session.out << "550 Usage: RCPT TO:<email-address>" << CRLF;
|
session.out << "550 Usage: RCPT TO:<email-address>" << CRLF;
|
||||||
} else
|
} else
|
||||||
session.out << "503 Please use MAIL first" << CRLF;
|
session.out << "503 Please use MAIL first" << CRLF;
|
||||||
std::cout << "009" << std::endl;
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
compile
2
compile
@ -5,7 +5,7 @@ do
|
|||||||
filename="${file%.*}"
|
filename="${file%.*}"
|
||||||
list="$list $filename.o"
|
list="$list $filename.o"
|
||||||
echo -n "Compiling $filename..."
|
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' ]
|
if [ $? = '0' ]
|
||||||
then
|
then
|
||||||
echo "OK"
|
echo "OK"
|
||||||
|
5
main.cpp
5
main.cpp
@ -24,15 +24,16 @@ int main(int argc, char **argv) {
|
|||||||
mail::MailFileSystem mailFileSystem(mailPath);
|
mail::MailFileSystem mailFileSystem(mailPath);
|
||||||
|
|
||||||
core::EPoll ePoll;
|
core::EPoll ePoll;
|
||||||
|
ePoll.start(2, 1000);
|
||||||
mail::SMTPServer smtpServer(ePoll, hostName, mailFileSystem, core::IPAddress(ipAddress, 9025));
|
mail::SMTPServer smtpServer(ePoll, hostName, mailFileSystem, core::IPAddress(ipAddress, 9025));
|
||||||
// mail::POP3Server pop3Server(ePoll, hostName, mailFileSystem, core::IPAddress(ipAddress, 110));
|
// mail::POP3Server pop3Server(ePoll, hostName, mailFileSystem, core::IPAddress(ipAddress, 110));
|
||||||
// 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(2, 1000);
|
consoleServer.commands.add(smtpServer.commands, "smtp");
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
sleep(300);
|
sleep(3600);
|
||||||
|
|
||||||
ePoll.stop();
|
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/brad.arant/Inbox/*
|
||||||
rm -rf /var/mail/barant.com/barant/Inbox/*
|
rm -rf /var/mail/barant.com/barant/Inbox/*
|
||||||
|
|
||||||
|
for count in {1..256};
|
||||||
|
do
|
||||||
|
echo $count
|
||||||
./testsmtp &
|
./testsmtp &
|
||||||
./testsmtp &
|
sleep .005
|
||||||
./testsmtp &
|
done
|
||||||
./testsmtp &
|
|
||||||
./testsmtp &
|
|
||||||
./testsmtp &
|
|
||||||
./testsmtp &
|
|
||||||
./testsmtp &
|
|
||||||
./testsmtp &
|
|
||||||
./testsmtp &
|
|
||||||
wait
|
wait
|
||||||
|
@ -2,16 +2,15 @@
|
|||||||
nc localhost 9025 > /dev/null << EOL
|
nc localhost 9025 > /dev/null << EOL
|
||||||
EHLO barant.com
|
EHLO barant.com
|
||||||
MAIL FROM: <brad.arant@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
|
DATA
|
||||||
From: barant@barant.com
|
From: barant@barant.com
|
||||||
To: barant@barant.com
|
To: barant@barant.com
|
||||||
Subject: test email system
|
Subject: test email system
|
||||||
|
|
||||||
This is a test
|
This is a test
|
||||||
|
|
||||||
.
|
.
|
||||||
|
|
||||||
QUIT
|
QUIT
|
||||||
EOL
|
EOL
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user