#ifndef __SendMail_h__
#define __SendMail_h__

#include "EPoll.h"
#include "SMTPSession.h"
#include "TCPSession2.h"
#include "MString.h"
#include "Timer.h"

#define CRLF "\r\n"

namespace mail {

   class SendMail : public core::TCPSession2, private core::Timer {

    public:
      SendMail(core::EPoll &ePoll, std::string from, std::string recipient, std::string mailFileName);
      ~SendMail();
      coreutils::MString& send();

      void protocol(coreutils::ZString &data) override;

    private:
      std::vector<coreutils::MString>& extractRecipientList();
      void onTimeout() override;

      core::EPoll &ePoll;

      coreutils::File mailData;
      coreutils::MString from;
      coreutils::MString recipient;
      coreutils::MString mailFileName;
      coreutils::MString buffer;
      std::vector<coreutils::MString> recipientList;

      State state = CONNECT;
      State stateOnTimeout = CONNECT;

   };

}

#endif
