#include "__SMTP_MAIL.h"
#include "SMTPServer.h"

namespace mail {
   
   int __SMTP_MAIL::processCommand(coreutils::PString request, SMTPSession &session, SMTPServer &server, std::stringstream &data) {
      
      if(request.ifNext("MAIL FROM:")) { 
	 request.skipWhitespace();
	 if(request.ifNext("<")) {
	    session.sender = request.getTokenExclude(">");	    
	    if(session.authState = USER_KNOWN) {
	       data << "250 OK" << CRLF;
	       session.recipientList.clear();
	       session.state = MAIL;
	    }
	 } else 
	   data << "550 Usage: MAIL FROM:<email-address>" << CRLF;	 
      } else 
	data << "550 Usage: MAIL FROM:<email-address>" << CRLF;
      
      return 1;
   }
   
   std::string domainOnly(std::string email) {
      coreutils::PString split(email);
      split.split("@");
      return split[1].str();
   }      
   
}

