Compiles but lotsa problems.

This commit is contained in:
Brad Arant 2022-07-30 17:46:35 -07:00
parent 09c6163a74
commit bb1c2cf944
9 changed files with 50 additions and 49 deletions

BIN
BMAMail

Binary file not shown.

View File

@ -7,7 +7,6 @@ namespace mail {
MailFileSystem::MailFileSystem(coreutils::ZString &mailPath) : mailPath(mailPath) {}
bool MailFileSystem::ifMailBoxExists(coreutils::ZString &mailbox) {
std::cout << "{" << mailbox << "}" << std::endl;
if(stat(getMailBoxPath(mailbox).c_str(), &statbuf) != -1)
if(S_ISDIR(statbuf.st_mode))
return true;
@ -23,9 +22,8 @@ namespace mail {
coreutils::MString MailFileSystem::getMailBoxPath(coreutils::ZString &mailbox) {
mailbox.split("@", 1);
std::cout << mailbox[0] << "-" << mailbox[1] << std::endl;
coreutils::MString path(mailPath + "/" + mailbox[1] + "/" + mailbox[0]);
std::cout << "{" << path << "}" << std::endl;
coreutils::MString path;
path << mailPath << "/" << mailbox[1] << "/" << mailbox[0];
return path;
}

View File

@ -56,10 +56,12 @@ namespace mail {
void inCreate(std::string name) {
int pos = name.find(".") + 10;
std::string mail = name.substr(0, pos);
std::string recipient = name.substr(pos);
coreutils::ZString recipient = name.substr(pos);
if(recipient != "") {
std::string fileName = mailPath + "/.queue/" + name;
std::string path = mailFileSystem.getMailBoxPath(recipient) + "/Inbox/" + mail;
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 << ".";

View File

@ -9,16 +9,16 @@ namespace mail {
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];
@ -47,7 +47,8 @@ namespace mail {
}
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);
secret.read();
return password == secret.asString();

View File

@ -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 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);
mailFile.write(mailData.str());

View File

@ -4,7 +4,7 @@
namespace mail {
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.state = READY;
return 1;

View File

@ -4,28 +4,36 @@
namespace mail {
int __SMTP_RCPT::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
std::cout << "001" << std::endl;
if((session.state == MAIL) || (session.state == RCPT)) {
std::string recipient;
if(request[1].ifNext("TO:")) {
request[1].skipWhitespace();
if(request[1].ifNext("<")) {
recipient = request[1].getTokenExclude(">").str();
if(server.mailFileSystem.ifMailBoxExists(recipient)) {
session.recipientList.push_back(recipient);
session.out << "250 OK" << 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;
std::cout << "002" << std::endl;
if(request[1].ifNext("TO:")) {
std::cout << "003" << std::endl;
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) {
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 << "503 Please use MAIL first" << CRLF;
session.out << "503 Please use MAIL first" << CRLF;
std::cout << "009" << std::endl;
return 1;
}

View File

@ -19,7 +19,7 @@ int main(int argc, char **argv) {
std::string hostName = "localhost";
std::string ipAddress = "0.0.0.0";
std::string mailPath = "/var/mail";
coreutils::ZString mailPath("/var/mail");
mail::MailFileSystem mailFileSystem(mailPath);

View File

@ -3,15 +3,6 @@ nc localhost 25 > /dev/null << EOL
EHLO barant.com
MAIL FROM: <brad.arant@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
EOL