#ifndef ____SMTP_RCPT_h__ #define ____SMTP_RCPT_h__ #include "Command.h" namespace mail { class __SMTP_RCPT : public core::Command { int processCommand(std::string request, Session *session, std::stringstream &data); if((state == "MAIL") || (state == "RCPT")) { bool done = false; //-------------------------------------- // Obtain the recipient's email address. //-------------------------------------- string recipient = input.substr(5); //----------------------------------------------- // Fetch the recipient list for the alias. //----------------------------------------------- string aliasRecipients; if(getAliasList(cleanEMail(recipient), aliasRecipients)) { //----------------------------------------------- // If the list is not blank then add the list // to the recipient list and accept the request. //----------------------------------------------- recipientList += aliasRecipients; data << "250 OK" << CRLF; state = "RCPT"; done = true; } //------------------------------------------------- // No alias entry for the mailbox so check if it // is a hard mailbox. //------------------------------------------------- if(!done) { //-------------------------------------- // Check to see if the user is a local // address to deliver to. //-------------------------------------- if(localUser(cleanEMail(recipient))) { //------------------------------------------ // They're local so lets queue it for them. //------------------------------------------ recipientList += cleanEMail(recipient) + " "; data << "250 OK" << CRLF; state = "RCPT"; done = true; } } //-------------------------------------------------- // There is no mailbox either so do domain check. //-------------------------------------------------- if(!done) { //--------------------------------------------------- // Check to see if the domain is good at least and // if there is a default mailbox address.. //--------------------------------------------------- string defaultMailbox; if(localDomain(domainOnly(cleanEMail(recipient)), defaultMailbox)) { //-------------------------------------------------- // The domain is local so if there is a default // mailbox then let's send it to the queue with the // default address attached instead. //-------------------------------------------------- if(defaultMailbox != "*NONE") { //--------------------------------------------------------- // If the default mailbox is *DISCARD then we do not want // to add the mailbox to the recipient list but we still // want to say we have a mailbox. //--------------------------------------------------------- if(defaultMailbox != "*DISCARD") recipientList += defaultMailbox + " "; cout << "250 OK" << CRLF; log.message("Response: 250 OK."); state = "RCPT"; done = true; } //-------------------------------------------------- // If there is no default address then we will tell // the client that the mailbox does not exist. //-------------------------------------------------- else { cout << "553 Mailbox does not exist" << CRLF; log.message("Response: 553 Mailbox does not exist."); done = true; } } } //-------------------------------------------------------------- // If we are not done then this is a relay request. //-------------------------------------------------------------- if (!done) { //--------------------------------------------------------- // If relaying is enabled for this conversation then // queue the mail. //--------------------------------------------------------- if(relay) { recipientList += cleanEMail(recipient) + " "; cout << "250 OK" << CRLF; log.message("Response: 250 OK."); state = "RCPT"; } //---------------------------------------- // Otherwise send an error. //---------------------------------------- else { cout << "553 Server requires authentication to relay" << CRLF; log.message("Response: 553 Server requires authentication to relay."); } } } else { cout << "503 Please use MAIL first" << CRLF; log.message("Response: 503 Please use MAIL first."); } return 0; } }; } #endif