diff --git a/BMAMail b/BMAMail index 9045895..1153a68 100755 Binary files a/BMAMail and b/BMAMail differ diff --git a/MailFileSystem.cpp b/MailFileSystem.cpp index 104f18d..2991fea 100644 --- a/MailFileSystem.cpp +++ b/MailFileSystem.cpp @@ -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; } diff --git a/SMTPServer.h b/SMTPServer.h index 01958de..4f88293 100644 --- a/SMTPServer.h +++ b/SMTPServer.h @@ -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 << "."; diff --git a/__SMTP_AUTH.cpp b/__SMTP_AUTH.cpp index f49f052..540ef63 100644 --- a/__SMTP_AUTH.cpp +++ b/__SMTP_AUTH.cpp @@ -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(); diff --git a/__SMTP_DATA.cpp b/__SMTP_DATA.cpp index 93071a4..cd0d41a 100644 --- a/__SMTP_DATA.cpp +++ b/__SMTP_DATA.cpp @@ -71,7 +71,8 @@ namespace mail { } coreutils::MString __SMTP_DATA::queueMail(SMTPServer &server, coreutils::MString &sender, std::vector &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()); diff --git a/__SMTP_HELO.cpp b/__SMTP_HELO.cpp index b5daf21..ca324f6 100644 --- a/__SMTP_HELO.cpp +++ b/__SMTP_HELO.cpp @@ -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; diff --git a/__SMTP_RCPT.cpp b/__SMTP_RCPT.cpp index 94c76b6..dee9282 100644 --- a/__SMTP_RCPT.cpp +++ b/__SMTP_RCPT.cpp @@ -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:" << CRLF; - } else - session.out << "550 Usage: RCPT TO:" << 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:" << CRLF; + } else + session.out << "550 Usage: RCPT TO:" << 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; } diff --git a/main.cpp b/main.cpp index 23b6719..cc59fb6 100644 --- a/main.cpp +++ b/main.cpp @@ -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); diff --git a/tests/testsmtp b/tests/testsmtp index 6879ab5..7c90566 100755 --- a/tests/testsmtp +++ b/tests/testsmtp @@ -3,15 +3,6 @@ nc localhost 25 > /dev/null << EOL EHLO barant.com MAIL FROM: RCPT TO: -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