Compiles but lotsa problems.
This commit is contained in:
parent
09c6163a74
commit
bb1c2cf944
@ -7,7 +7,6 @@ namespace mail {
|
|||||||
MailFileSystem::MailFileSystem(coreutils::ZString &mailPath) : mailPath(mailPath) {}
|
MailFileSystem::MailFileSystem(coreutils::ZString &mailPath) : mailPath(mailPath) {}
|
||||||
|
|
||||||
bool MailFileSystem::ifMailBoxExists(coreutils::ZString &mailbox) {
|
bool MailFileSystem::ifMailBoxExists(coreutils::ZString &mailbox) {
|
||||||
std::cout << "{" << mailbox << "}" << std::endl;
|
|
||||||
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;
|
||||||
@ -23,9 +22,8 @@ namespace mail {
|
|||||||
|
|
||||||
coreutils::MString MailFileSystem::getMailBoxPath(coreutils::ZString &mailbox) {
|
coreutils::MString MailFileSystem::getMailBoxPath(coreutils::ZString &mailbox) {
|
||||||
mailbox.split("@", 1);
|
mailbox.split("@", 1);
|
||||||
std::cout << mailbox[0] << "-" << mailbox[1] << std::endl;
|
coreutils::MString path;
|
||||||
coreutils::MString path(mailPath + "/" + mailbox[1] + "/" + mailbox[0]);
|
path << mailPath << "/" << mailbox[1] << "/" << mailbox[0];
|
||||||
std::cout << "{" << path << "}" << std::endl;
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,10 +56,12 @@ namespace mail {
|
|||||||
void inCreate(std::string name) {
|
void inCreate(std::string name) {
|
||||||
int pos = name.find(".") + 10;
|
int pos = name.find(".") + 10;
|
||||||
std::string mail = name.substr(0, pos);
|
std::string mail = name.substr(0, pos);
|
||||||
std::string recipient = name.substr(pos);
|
coreutils::ZString recipient = name.substr(pos);
|
||||||
if(recipient != "") {
|
if(recipient != "") {
|
||||||
std::string fileName = mailPath + "/.queue/" + name;
|
coreutils::MString fileName;
|
||||||
std::string path = mailFileSystem.getMailBoxPath(recipient) + "/Inbox/" + mail;
|
fileName << mailPath << "/.queue/" << name;
|
||||||
|
coreutils::MString path;
|
||||||
|
path << mailFileSystem.getMailBoxPath(recipient) << "/Inbox/" << mail;
|
||||||
int rc = link(fileName.c_str(), path.c_str());
|
int rc = link(fileName.c_str(), path.c_str());
|
||||||
rc = unlink(fileName.c_str());
|
rc = unlink(fileName.c_str());
|
||||||
coreutils::Log(coreutils::LOG_INFO) << "Message " << mail << " delivered to " << recipient << ".";
|
coreutils::Log(coreutils::LOG_INFO) << "Message " << mail << " delivered to " << recipient << ".";
|
||||||
|
@ -9,16 +9,16 @@ namespace mail {
|
|||||||
switch(session.authState) {
|
switch(session.authState) {
|
||||||
|
|
||||||
case USER_UNKNOWN:
|
case USER_UNKNOWN:
|
||||||
if(request[1].equals("LOGIN")) {
|
if(request[1].equals("LOGIN")) {
|
||||||
session.out << "334 VXNlcm5hbWU6" << CRLF;
|
session.out << "334 VXNlcm5hbWU6" << CRLF;
|
||||||
// setTimer(10.0f);
|
// setTimer(10.0f);
|
||||||
session.authState = USER_QUERY;
|
session.authState = USER_QUERY;
|
||||||
grabInput(session);
|
grabInput(session);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
session.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:
|
||||||
session.userName = request[0];
|
session.userName = request[0];
|
||||||
@ -47,7 +47,8 @@ namespace mail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool __SMTP_AUTH::authLogin(coreutils::ZString &userName, coreutils::ZString &password, SMTPServer &server) {
|
bool __SMTP_AUTH::authLogin(coreutils::ZString &userName, coreutils::ZString &password, SMTPServer &server) {
|
||||||
std::string secretPath = server.mailFileSystem.getMailBoxPath(userName) + "/.password";
|
coreutils::MString secretPath;
|
||||||
|
secretPath << server.mailFileSystem.getMailBoxPath(userName) << "/.password";
|
||||||
coreutils::File secret(secretPath);
|
coreutils::File secret(secretPath);
|
||||||
secret.read();
|
secret.read();
|
||||||
return password == secret.asString();
|
return password == secret.asString();
|
||||||
|
@ -71,7 +71,8 @@ namespace mail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
coreutils::MString __SMTP_DATA::queueMail(SMTPServer &server, coreutils::MString &sender, std::vector<coreutils::MString> &recipientList, std::stringstream &mailData) {
|
coreutils::MString __SMTP_DATA::queueMail(SMTPServer &server, coreutils::MString &sender, std::vector<coreutils::MString> &recipientList, std::stringstream &mailData) {
|
||||||
coreutils::MString fileName(server.mailFileSystem.getMailPath() + "/.queue/" + generateMailFileName().str());
|
coreutils::MString fileName;
|
||||||
|
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.str());
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
namespace mail {
|
namespace mail {
|
||||||
|
|
||||||
int __SMTP_HELO::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
int __SMTP_HELO::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
|
||||||
session.clientDomainName = request[1].str();
|
session.clientDomainName = request[1];
|
||||||
session.out << "250 " << server.hostName << CRLF;
|
session.out << "250 " << server.hostName << CRLF;
|
||||||
session.state = READY;
|
session.state = READY;
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -4,28 +4,36 @@
|
|||||||
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::string recipient;
|
std::cout << "002" << std::endl;
|
||||||
if(request[1].ifNext("TO:")) {
|
if(request[1].ifNext("TO:")) {
|
||||||
request[1].skipWhitespace();
|
std::cout << "003" << std::endl;
|
||||||
if(request[1].ifNext("<")) {
|
request[1].skipWhitespace();
|
||||||
recipient = request[1].getTokenExclude(">").str();
|
if(request[1].ifNext("<")) {
|
||||||
if(server.mailFileSystem.ifMailBoxExists(recipient)) {
|
std::cout << "004" << std::endl;
|
||||||
session.recipientList.push_back(recipient);
|
coreutils::MString recipient(request[1].getTokenExclude(">"));
|
||||||
session.out << "250 OK" << CRLF;
|
if(server.mailFileSystem.ifMailBoxExists(recipient)) {
|
||||||
session.state = RCPT;
|
std::cout << "005" << std::endl;
|
||||||
} else if(session.relay) {
|
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;
|
||||||
session.state = RCPT;
|
std::cout << "007" << std::endl;
|
||||||
} else
|
session.state = RCPT;
|
||||||
session.out << "550 Mailbox does not exist" << CRLF;
|
std::cout << "008" << std::endl;
|
||||||
} else
|
} else if(session.relay) {
|
||||||
session.out << "550 Usage: RCPT TO:<email-address>" << CRLF;
|
session.recipientList.push_back(recipient);
|
||||||
} else
|
session.out << "250 OK" << CRLF;
|
||||||
session.out << "550 Usage: RCPT TO:<email-address>" << 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
|
} 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
main.cpp
2
main.cpp
@ -19,7 +19,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
std::string hostName = "localhost";
|
std::string hostName = "localhost";
|
||||||
std::string ipAddress = "0.0.0.0";
|
std::string ipAddress = "0.0.0.0";
|
||||||
std::string mailPath = "/var/mail";
|
coreutils::ZString mailPath("/var/mail");
|
||||||
|
|
||||||
mail::MailFileSystem mailFileSystem(mailPath);
|
mail::MailFileSystem mailFileSystem(mailPath);
|
||||||
|
|
||||||
|
@ -3,15 +3,6 @@ nc localhost 25 > /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: <barant@barant.com>
|
||||||
DATA
|
|
||||||
From: brad.arant@barant.com
|
|
||||||
To: barant@barant.com
|
|
||||||
Subject: This is a test
|
|
||||||
|
|
||||||
This is a test message.
|
|
||||||
This is just here for testing and not of much use.
|
|
||||||
Can it be that additional data helps the situation?
|
|
||||||
.
|
|
||||||
QUIT
|
QUIT
|
||||||
EOL
|
EOL
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user