# include "__SMTP_RCPT.h"
# include "SMTPServer.h"

namespace mail {

   int __SMTP_RCPT::processCommand(coreutils::ZString &request, SMTPSession &session, SMTPServer &server) {
      if((session.state == MAIL) || (session.state == RCPT)) {
	 		if(request[1].ifNext("TO:")) {
	    		request[1].skipWhitespace();
	    		if(request[1].ifNext("<")) {
			 		coreutils::MString recipient(request[1].getTokenExclude(">"));
	       		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;
      } else
		  session.out << "503 Please use MAIL first" << CRLF;
      return 1;
   }

}
