/home/bradarant/barant/BMAMail/__SMTP_DATA.h
Go to the documentation of this file.
#ifndef ____SMTP_DATA_h__
# define ____SMTP_DATA_h__
# include "SMTPCommand.h"
namespace mail {
class __SMTP_DATA : public SMTPCommand {
int processCommand(coreutils::PString request, SMTPSession &session, std::stringstream &data) {
switch(session.mode) {
case WAIT_FOR_DATA:
switch(session.state) {
case RCPT:
data << "354 Enter the mail message terminated by <CRLF>.<CRLF>" << CRLF;
session.mailData.str("");
session.mode = RECEIVE_DATA;
session.server.commands.grabInput(*this);
// setTimer(120.0f);
break;
case MAIL:
data << "503 Please use RCPT first" << CRLF;
break;
default:
data << "503 Please use MAIL first" << CRLF;
break;
}
break;
case RECEIVE_DATA:
session.mailData << request.str();
if(request.str().rfind("\r\n.\r\n") != std::string::npos) {
session.mode = WAIT_FOR_DATA;
session.state = READY;
session.server.commands.clearGrab();
// if(filterMessage(session.mailData)) {
if(session.recipientList.size() > 0) {
if(session.mailData.str().size() > 0) {
std::string ID = queueMail(session.sender, session.recipientList, session.mailData);
if(ID != "")
data << "250 OK Queued message " << ID << CRLF;
else
data << "550 Mail message too big" << CRLF;
} else
data << "550 Mail message was empty" << CRLF;
} else
data << "250 OK Queued message " << CRLF;
// } else
// data << "550 Message is probably spam" << CRLF;
}
break;
}
}
std::string generateMailFileName() {
char name[256];
strftime(name, 256, "%Y%M%D%H%M%S", gmtime(time()));
return std::string(name);
}
std::string queueMail(std::string sender, std::vector<std::string> recipientList, std::stringstream &mailData) {
std::string fileName = generateMailFileName();
coreutils::File mailFile(fileName, O_CREAT | O_WRONLY, 0660);
mailFile.write(mailData.str());
for(std::string recipient: recipientList) {
std::string newName = fileName + recipient;
link(fileName, newName);
}
unlink(fileName);
return fileName;
}
};
}
#endif
mail::RECEIVE_DATA
Definition: SMTPSession.h:13
mail::SMTPSession::state
State state
Definition: SMTPSession.h:25
mail::MAIL
Definition: SMTPSession.h:11
mail::WAIT_FOR_DATA
Definition: SMTPSession.h:13
mail::READY
Definition: SMTPSession.h:11
mail::SMTPSession::recipientList
std::vector< std::string > recipientList
Definition: SMTPSession.h:30
mail::SMTPSession::mode
Mode mode
Definition: SMTPSession.h:27
mail
Definition: __IMAP_APPEND.h:7
SMTPCommand.h
mail::SMTPSession::sender
std::string sender
Definition: SMTPSession.h:29
mail::SMTPCommand
Definition: SMTPCommand.h:9
CRLF
#define CRLF
Definition: SMTPSession.h:7
mail::SMTPSession
Definition: SMTPSession.h:15
mail::SMTPSession::mailData
std::stringstream mailData
Definition: SMTPSession.h:24
mail::__SMTP_DATA
Definition: __SMTP_DATA.h:8
mail::RCPT
Definition: SMTPSession.h:11