
/*---------------------------------------------------------------------------*/
/* smtp.h                                                                    */
/* copyright (c) innovaphone 2016                                            */
/*                                                                           */
/*---------------------------------------------------------------------------*/

/*#define TEXT_PLAIN      "text/plain"  //[RFC1521]
#define TEXT_HTML       "text/html"   //[RFC1866]
#define IMG_JPG         "image/jpeg"  //[RFC1521]
#define IMG_GIF         "image/gif"   //[RFC1521]
#define VIDEO_MPEG      "video/mpeg"  //[RFC1521]
#define APPLICATION_GZIP    "application/gzip"
#define APPLICATION_PDF    "application/pdf"
*/


class ISmtpProvider* CreateSmtpProvider();

class ISmtpProvider {
public:
    virtual ~ISmtpProvider() {}
    virtual class ISmtp* CreateSmtp(class IIoMux* iomux, class ISocketProvider* tcpSocketProvider, class ISocketProvider* tlsSocketProvider, class IInstanceLog* const log, class IDns* const dns = nullptr) = 0;
};

#define smtp_ROOT 1

class ISmtp {

public:
    enum ContentTypes {
        ContentTextHtml,
        ContentTextPlain,
        ContentUnknown
    };

    virtual ~ISmtp() {}
    virtual class ISmtpSend* CreateSend(const char* from, const char* fromName, const char* subject, const char* host, const char* server, const char* userSmtp, const char* password) = 0;
    virtual void SendChunk(const char* attachmentChunk, int sChunk, bool lastChunk, dword fileIndex) = 0;
    virtual class ISmtpListen * CreateListen(class USmtpListen * USmtpListen, class ISocketContext * tlsSocketContext = 0) = 0;
};

class ISmtpSend : public ITask {
public:
    virtual void AddAttachment(const char* attachmentUrl, const char* mimeType = nullptr) = 0;
    virtual void AddTo(const char* rcpt) = 0;
    virtual void AddCc(const char* rcpt) = 0;
    virtual void AddBcc(const char* rcpt) = 0;
    virtual void AddBody(const char* data, const char* format, const char* charset) = 0;
};

class ISmtpListen {
public:
    virtual ~ISmtpListen() {};
    virtual class ISmtpReceive * CreateReceive(const char * user, const char * password, const char * domain) = 0;
    virtual void Shutdown() = 0;
};

class USmtpListen {
public:
    virtual ~USmtpListen() {};
    virtual void SmtpListenResult(class ISmtpReceive * smtpRecv) = 0;
    virtual void SmtpListenShutdownComplete() = 0;
    virtual class ISmtpReceive * CreateSmtpReceive() = 0;
};

class USmtpReceive {
public:
    virtual ~USmtpReceive() {};
    virtual void SmtpReceiveCancelComplete() = 0;
    virtual void CallRecvBody() = 0;
    virtual void SmtpHeader() = 0;
    virtual void SmtpBody(char * buffer, int length, bool complete) = 0;
};

class ISmtpReceive {
public:
    virtual ~ISmtpReceive() {}
    virtual void Cancel() = 0;
    virtual void Receive() = 0;
    virtual void Accept(USmtpReceive * receive) = 0;
    virtual char * GetTo() = 0;
    virtual char * GetFrom() = 0;
    virtual char * GetSubject() = 0;
    virtual char * GetDate() = 0;
    virtual char * GetFileName() = 0;
    virtual enum ISmtp::ContentTypes GetContentType(const char ** type = 0) = 0;
    virtual const char * GetXForwardedFor() = 0;
    virtual void RecvBody(char * mBuffer, int len) = 0;
    virtual void RecvAttachment(char * mBuffer, int len) = 0;
};
