#ifndef OverbyteIcsSslMailRcv1H
#define OverbyteIcsSslMailRcv1H

#include <System.Classes.hpp>
#include <Vcl.Controls.hpp>
#include <Vcl.StdCtrls.hpp>
#include <Vcl.ExtCtrls.hpp>
#include <Vcl.Forms.hpp>
#include "OverbyteIcsOAuthFormVclE.hpp"
#include "OverbyteIcsPop3Prot.hpp"
#include "OverbyteIcsSslBase.hpp"
#include "OverbyteIcsSslHttpOAuth.hpp"
#include "OverbyteIcsTypes.hpp"
#include "OverbyteIcsWndControl.hpp"

#pragma push_macro("GetUserName")
#undef GetUserName
#include "OverbyteIcsPop3Prot.hpp"
#pragma pop_macro("GetUserName")
#include "OverbyteIcsWndControl.hpp"
#include "OverbyteIcsSslHttpOAuth.hpp"
#include "OverbyteIcsOAuthFormVclE.hpp"
#include "OverbyteIcsSslBase.hpp"
#include "OverbyteIcsTypes.hpp"

#include <functional>
#include <memory>

class TPOP3ExcercizerForm : public TForm
{
__published:
    TMemo *DisplayMemo;
    TPanel *Panel1;
    TLabel *InfoLabel;
    TLabel *Label1;
    TLabel *Label2;
    TLabel *Label3;
    TLabel *Label4;
    TLabel *Label5;
    TLabel *Label6;
    TLabel *Label7;
    TLabel *Label8;
    TLabel *Label9;
    TLabel *Label11;
    TLabel *Label10;
    TLabel *Label12;
    TLabel *Label13;
    TLabel *Label14;
    TButton *ConnectButton;
    TButton *QuittButton;
    TButton *UserButton;
    TEdit *HostEdit;
    TEdit *UserNameEdit;
    TEdit *PassWordEdit;
    TButton *PassButton;
    TEdit *MsgNumEdit;
    TButton *RetrButton;
    TButton *StatButton;
    TButton *ListAllButton;
    TButton *ListButton;
    TButton *DeleteButton;
    TButton *NoopButton;
    TButton *LastButton;
    TButton *ResetButton;
    TButton *TopButton;
    TEdit *MsgLinesEdit;
    TButton *RpopButton;
    TButton *UidlButton;
    TButton *ApopButton;
    TButton *NextButton;
    TButton *GetAllButton;
    TEdit *PortEdit;
    TButton *OpenButton;
    TButton *AbortButton;
    TEdit *SubjectEdit;
    TEdit *FromEdit;
    TEdit *ToEdit;
    TComboBox *AuthComboBox;
    TButton *AuthButton;
    TComboBox *SslTypeComboBox;
    TButton *STlsButton;
    TCheckBox *VerifyCheckBox;
    TEdit *CAFileEdit;
    TEdit *CAPathEdit;
    TCheckBox *OAuth2ExtBrow;
    TComboBox *OAuth2UserAuth;
    TSslPop3Cli *SslPop3Client;
    TSslContext *SslContext1;
    TIcsRestEmail *IcsRestEmail1;
    TOAuthBrowser *OAuthBrowser1;
    void __fastcall ConnectButtonClick(TObject *Sender);
    void __fastcall FormCreate(TObject *Sender);
    void __fastcall QuittButtonClick(TObject *Sender);
    void __fastcall UserButtonClick(TObject *Sender);
    void __fastcall PassButtonClick(TObject *Sender);
    void __fastcall SslPop3ClientMessageBegin(TObject *Sender);
    void __fastcall SslPop3ClientMessageEnd(TObject *Sender);
    void __fastcall SslPop3ClientMessageLine(TObject *Sender);
    void __fastcall RetrButtonClick(TObject *Sender);
    void __fastcall StatButtonClick(TObject *Sender);
    void __fastcall ListAllButtonClick(TObject *Sender);
    void __fastcall ListButtonClick(TObject *Sender);
    void __fastcall SslPop3ClientListBegin(TObject *Sender);
    void __fastcall SslPop3ClientListEnd(TObject *Sender);
    void __fastcall SslPop3ClientListLine(TObject *Sender);
    void __fastcall DeleteButtonClick(TObject *Sender);
    void __fastcall NoopButtonClick(TObject *Sender);
    void __fastcall LastButtonClick(TObject *Sender);
    void __fastcall ResetButtonClick(TObject *Sender);
    void __fastcall TopButtonClick(TObject *Sender);
    void __fastcall RpopButtonClick(TObject *Sender);
    void __fastcall SslPop3ClientDisplay(TObject *Sender, const String Msg);
    void __fastcall UidlButtonClick(TObject *Sender);
    void __fastcall SslPop3ClientUidlBegin(TObject *Sender);
    void __fastcall SslPop3ClientUidlEnd(TObject *Sender);
    void __fastcall SslPop3ClientUidlLine(TObject *Sender);
    void __fastcall ApopButtonClick(TObject *Sender);
    void __fastcall NextButtonClick(TObject *Sender);
    void __fastcall GetAllButtonClick(TObject *Sender);
    void __fastcall SslPop3ClientRequestDone(TObject *Sender, TPop3Request RqType, System::Word ErrCode);
    void __fastcall OpenButtonClick(TObject *Sender);
    void __fastcall AbortButtonClick(TObject *Sender);
    void __fastcall SslPop3ClientHeaderEnd(TObject *Sender);
    void __fastcall AuthButtonClick(TObject *Sender);
    void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
    void __fastcall FormShow(TObject *Sender);
    void __fastcall STlsButtonClick(TObject *Sender);
    void __fastcall IcsRestEmail1EmailNewToken(TObject *Sender);
    void __fastcall IcsRestEmail1EmailProg(TObject *Sender, TLogOption LogOption, const String Msg);
    void __fastcall SslPop3ClientGetNewToken(TObject *Sender);
    void __fastcall IcsRestEmail1OAEmbed(TObject *Sender, const String URL, bool &Success);

private:
    String FIniFileName;
    bool FInitialized;
    std::unique_ptr<TFileStream> FFile;
    String FFileName;
    int FGetAllState;
    String FMsgPath;
    void __fastcall SetSslVerifyProps();
    void __fastcall Exec(const std::function<void()> &Method, const String &MethodName);
    void __fastcall CloseGetAllFile(bool DeletePartial);
    void __fastcall MessageBegin(TObject *Sender);
    void __fastcall MessageLine(TObject *Sender);
    void __fastcall GetAllMessageLine(TObject *Sender);
    void __fastcall GetAllRequestDone(TObject *Sender, TPop3Request RqType, System::Word ErrCode);
    void __fastcall NextMessageRequestDone(TObject *Sender, TPop3Request RqType, System::Word ErrCode);
    void __fastcall SetupOAuth2();

public:
    __fastcall TPOP3ExcercizerForm(TComponent *Owner);
};

extern PACKAGE TPOP3ExcercizerForm *POP3ExcercizerForm;

#endif
