// Borland C++ Builder
// Copyright (c) 1995, 2002 by Borland Software Corporation
// All rights reserved

// (DO NOT EDIT: machine generated header) 'ahmtiemails.pas' rev: 6.00

#ifndef ahmtiemailsHPP
#define ahmtiemailsHPP

#pragma delphiheader begin
#pragma option push -w-
#pragma option push -Vx
#include <ahmtmailaccount.hpp>	// Pascal unit
#include <ahmmailclass.hpp>	// Pascal unit
#include <ahmmailconst.hpp>	// Pascal unit
#include <ScktComp.hpp>	// Pascal unit
#include <Classes.hpp>	// Pascal unit
#include <Windows.hpp>	// Pascal unit
#include <SysUtils.hpp>	// Pascal unit
#include <SysInit.hpp>	// Pascal unit
#include <System.hpp>	// Pascal unit

//-- user supplied -----------------------------------------------------------

namespace Ahmtiemails
{
//-- type declarations -------------------------------------------------------
typedef Shortint TAHMPStep;

#pragma option push -b-
enum TAHMMailSessionState { Authorization, Transaction };
#pragma option pop

typedef void __fastcall (__closure *TAHMOnHostMessage)(System::TObject* Sender, AnsiString Status, AnsiString Msg);

typedef void __fastcall (__closure *TAHMOnInfoMessage)(System::TObject* Sender, AnsiString Status, AnsiString MsgText, bool IsError);

typedef void __fastcall (__closure *TAHMOnConnectionState)(System::TObject* Sender, const AnsiString Server, int Port);

typedef void __fastcall (__closure *TAHMOnCodingStart)(System::TObject* Sender, AnsiString FileName, int BytesCount);

typedef void __fastcall (__closure *TAHMMailProgress)(System::TObject* Sender, Word Percent, int ItemIndex);

typedef void __fastcall (__closure *TAHMMailAction)(System::TObject* Sender, Word Index);

class DELPHICLASS TAHMMessage;
typedef void __fastcall (__closure *TAHMAfterMsgAction)(System::TObject* sender, TAHMMessage* MailMessage);

class DELPHICLASS TAHMAttachment;
class PASCALIMPLEMENTATION TAHMAttachment : public Classes::TCollectionItem 
{
	typedef Classes::TCollectionItem inherited;
	
private:
	AnsiString FFileName;
	Classes::TStringList* FBodyEncoded;
	Classes::TMemoryStream* FBodyBin;
	AnsiString FMimetype;
	TAHMMessage* FAHMMessage;
	AnsiString FPhysFile;
	
protected:
	virtual AnsiString __fastcall GetDisplayName();
	
public:
	__fastcall virtual TAHMAttachment(Classes::TCollection* Collection);
	__fastcall virtual ~TAHMAttachment(void);
	void __fastcall SaveToFile(AnsiString FileName);
	__property TAHMMessage* Owner = {read=FAHMMessage};
	__property AnsiString Mimetype = {read=FMimetype};
	
__published:
	__property AnsiString PhysFile = {read=FPhysFile, write=FPhysFile, stored=true};
	__property AnsiString FileName = {read=FFileName, write=FFileName};
};


class DELPHICLASS TAHMAttachments;
class PASCALIMPLEMENTATION TAHMAttachments : public Ahmmailclass::TAHMMailCollection 
{
	typedef Ahmmailclass::TAHMMailCollection inherited;
	
public:
	TAHMAttachment* operator[](int Index) { return Items[Index]; }
	
private:
	TAHMMessage* FAHMMessage;
	TAHMAttachment* __fastcall GeTAHMAttachment(int Index);
	void __fastcall SeTAHMAttachment(int Index, TAHMAttachment* Value);
	
protected:
	DYNAMIC Classes::TPersistent* __fastcall GetOwner(void);
	AnsiString __fastcall GetMimetype(const AnsiString FileName);
	
public:
	__fastcall TAHMAttachments(TAHMMessage* AOwner);
	HIDESBASE TAHMAttachment* __fastcall Add(AnsiString Filename);
	HIDESBASE bool __fastcall Delete(int Index);
	__property TAHMAttachment* Items[int Index] = {read=GeTAHMAttachment, write=SeTAHMAttachment/*, default*/};
public:
	#pragma option push -w-inl
	/* TCollection.Destroy */ inline __fastcall virtual ~TAHMAttachments(void) { }
	#pragma option pop
	
};


class DELPHICLASS TAHMMailHost;
class DELPHICLASS TAHMMessages;
class PASCALIMPLEMENTATION TAHMMessages : public Ahmmailclass::TAHMMailCollection 
{
	typedef Ahmmailclass::TAHMMailCollection inherited;
	
public:
	TAHMMessage* operator[](int Index) { return Items[Index]; }
	
private:
	TAHMMailHost* FAHMMailHost;
	TAHMMessage* __fastcall GetAHMMessage(int Index);
	void __fastcall SetAHMMessage(int Index, TAHMMessage* Value);
	
protected:
	DYNAMIC Classes::TPersistent* __fastcall GetOwner(void);
	
public:
	__fastcall TAHMMessages(TAHMMailHost* AOwner);
	HIDESBASE TAHMMessage* __fastcall Add(void);
	HIDESBASE bool __fastcall Delete(int Index);
	__property TAHMMessage* Items[int Index] = {read=GetAHMMessage, write=SetAHMMessage/*, default*/};
public:
	#pragma option push -w-inl
	/* TCollection.Destroy */ inline __fastcall virtual ~TAHMMessages(void) { }
	#pragma option pop
	
};


class PASCALIMPLEMENTATION TAHMMailHost : public Ahmmailclass::TAHMMailsComponent 
{
	typedef Ahmmailclass::TAHMMailsComponent inherited;
	
private:
	bool FConnected;
	TAHMOnConnectionState FOnConnect;
	bool FBusy;
	bool FCancel;
	Scktcomp::TWinSocketStream* FSocketStream;
	Scktcomp::TClientSocket* FSocket;
	Classes::TNotifyEvent FOnExecute;
	TAHMMessages* FAHMMessages;
	TAHMOnHostMessage FOnServerMessage;
	AnsiString FHostStatus;
	AnsiString FHostMsg;
	Ahmtmailaccount::TAHMAccountHolder* FAccountInfo;
	Ahmtmailaccount::TAHMMailAccount* FCurrentAccount;
	Classes::TNotifyEvent FAfterExecute;
	Classes::TNotifyEvent FBeforeExecute;
	TAHMOnInfoMessage FOnServerMsg;
	TAHMOnInfoMessage FOnError;
	TAHMOnConnectionState FOnDisconnect;
	void __fastcall SetAHMMessages(TAHMMessages* Value);
	void __fastcall SetAccountInfo(const Ahmtmailaccount::TAHMAccountHolder* Value);
	void __fastcall DoConnect(System::TObject* Sender, Scktcomp::TCustomWinSocket* Socket);
	void __fastcall DoDisconnect(System::TObject* Sender, Scktcomp::TCustomWinSocket* Socket);
	
protected:
	virtual void __fastcall Notification(Classes::TComponent* AComponent, Classes::TOperation Operation);
	void __fastcall HandleError(Scktcomp::TErrorEvent ErrorEvent);
	void __fastcall HandleErrorAndExit(System::TObject* Sender, Scktcomp::TCustomWinSocket* Socket, Scktcomp::TErrorEvent ErrorEvent, int &ErrorCode);
	virtual void __fastcall Connect(AnsiString Server, int Port, int TimeOut);
	virtual void __fastcall SendSocketText(const AnsiString SocketText);
	virtual AnsiString __fastcall GetSocketText(void) = 0 ;
	virtual void __fastcall Disconnect(void);
	void __fastcall HandleServerResponse(AnsiString Status, AnsiString MsgText, bool IsError);
	
public:
	__fastcall virtual TAHMMailHost(Classes::TComponent* AOwner);
	__fastcall virtual ~TAHMMailHost(void);
	virtual bool __fastcall Execute(void);
	__property Ahmtmailaccount::TAHMMailAccount* CurrentAccount = {read=FCurrentAccount};
	__property bool Connected = {read=FConnected, nodefault};
	__property bool Cancelled = {read=FCancel, nodefault};
	
__published:
	__property TAHMOnHostMessage OnServerMessage = {read=FOnServerMessage, write=FOnServerMessage};
	__property TAHMMessages* Messages = {read=FAHMMessages, write=SetAHMMessages};
	__property Classes::TNotifyEvent OnExecute = {read=FOnExecute, write=FOnExecute};
	__property Ahmtmailaccount::TAHMAccountHolder* AccountInfo = {read=FAccountInfo, write=SetAccountInfo};
	__property Classes::TNotifyEvent BeforeExecute = {read=FBeforeExecute, write=FBeforeExecute};
	__property Classes::TNotifyEvent AfterExecute = {read=FAfterExecute, write=FAfterExecute};
	__property TAHMOnInfoMessage OnServerResponse = {read=FOnServerMsg, write=FOnServerMsg};
	__property TAHMOnInfoMessage OnError = {read=FOnError, write=FOnError};
	__property TAHMOnConnectionState OnConnect = {read=FOnConnect, write=FOnConnect};
	__property TAHMOnConnectionState OnDisconnect = {read=FOnDisconnect, write=FOnDisconnect};
};


class PASCALIMPLEMENTATION TAHMMessage : public Classes::TCollectionItem 
{
	typedef Classes::TCollectionItem inherited;
	
private:
	AnsiString FFrommail;
	AnsiString FReplyTo;
	AnsiString FSendTo;
	AnsiString FSubject;
	AnsiString FFromname;
	AnsiString FMessageID;
	AnsiString FInReplyTo;
	AnsiString FDate;
	Classes::TStrings* FMessage;
	AnsiString FHeader;
	TAHMMailHost* FAHMMailHost;
	Classes::TStrings* FAtttypes;
	TAHMAttachments* FAHMAttachments;
	int FIndex;
	Ahmtmailaccount::TAHMMailAccount* FAccount;
	void __fastcall SetAHMAttachments(TAHMAttachments* Value);
	void __fastcall SetMessage(Classes::TStrings* Value);
	
protected:
	virtual AnsiString __fastcall GetDisplayName();
	
public:
	__fastcall virtual TAHMMessage(Classes::TCollection* Collection);
	__fastcall virtual ~TAHMMessage(void);
	__property TAHMMailHost* Owner = {read=FAHMMailHost};
	__property AnsiString Date = {read=FDate};
	__property AnsiString MessageID = {read=FMessageID};
	__property AnsiString InReplyTo = {read=FInReplyTo, write=FInReplyTo};
	__property Ahmtmailaccount::TAHMMailAccount* Account = {read=FAccount};
	__property int MessageIndex = {read=FIndex, nodefault};
	__property AnsiString Header = {read=FHeader};
	
__published:
	__property AnsiString FromMail = {read=FFrommail, write=FFrommail};
	__property AnsiString ReplyTo = {read=FReplyTo, write=FReplyTo};
	__property AnsiString SendTo = {read=FSendTo, write=FSendTo};
	__property AnsiString Subject = {read=FSubject, write=FSubject};
	__property AnsiString FromName = {read=FFromname, write=FFromname};
	__property Classes::TStrings* Message = {read=FMessage, write=SetMessage};
	__property TAHMAttachments* Attachments = {read=FAHMAttachments, write=SetAHMAttachments};
};


class DELPHICLASS TAHMSMTPMail;
class PASCALIMPLEMENTATION TAHMSMTPMail : public TAHMMailHost 
{
	typedef TAHMMailHost inherited;
	
private:
	int FCurrentMessage;
	Classes::TStrings* FSignature;
	bool FSMTPError;
	Word FSendProgress;
	Word FEncodeProgress;
	Classes::TNotifyEvent FOnBeforeSend;
	TAHMAfterMsgAction FOnAfterSend;
	Classes::TNotifyEvent FOnSuccessSend;
	TAHMMailProgress FOnSendProgress;
	TAHMOnCodingStart FOnEncodeStart;
	TAHMMailProgress FOnEncodeProgress;
	Classes::TNotifyEvent FOnEncodeend;
	void __fastcall SetSignature(Classes::TStrings* Value);
	void __fastcall DoEncodeStart(AnsiString FileName, int Size);
	void __fastcall DoEncodeProgress(Word Percent);
	void __fastcall DoEncodeend(void);
	void __fastcall DoSendProgress(Word Percent);
	void __fastcall DoOnBeforeSend(void);
	AnsiString __fastcall CreateUIN();
	Classes::TStringList* __fastcall InitializeMessage(TAHMMessage* &VMessage);
	AnsiString __fastcall CreateBounds();
	
protected:
	AnsiString __fastcall GetSMTPDate();
	void __fastcall base64encode(TAHMAttachment* &vattachment);
	virtual void __fastcall Connect(AnsiString Server, int Port, int TimeOut);
	virtual AnsiString __fastcall GetSocketText();
	
public:
	__fastcall virtual TAHMSMTPMail(Classes::TComponent* AOwner);
	__fastcall virtual ~TAHMSMTPMail(void);
	virtual bool __fastcall Execute(void);
	bool __fastcall SendMessage(TAHMMessage* VMessage);
	HIDESBASE bool __fastcall Connected(void);
	__property bool SMTPError = {read=FSMTPError, nodefault};
	
__published:
	__property Classes::TStrings* Signature = {read=FSignature, write=SetSignature};
	__property Classes::TNotifyEvent OnBeforeSend = {read=FOnBeforeSend, write=FOnBeforeSend};
	__property TAHMAfterMsgAction OnAfterSend = {read=FOnAfterSend, write=FOnAfterSend};
	__property Classes::TNotifyEvent OnSuccessSend = {read=FOnSuccessSend, write=FOnSuccessSend};
	__property TAHMOnCodingStart OnEncodeStart = {read=FOnEncodeStart, write=FOnEncodeStart};
	__property TAHMMailProgress OnEncodeProgress = {read=FOnEncodeProgress, write=FOnEncodeProgress};
	__property Classes::TNotifyEvent OnEncodeend = {read=FOnEncodeend, write=FOnEncodeend};
	__property TAHMMailProgress OnSendProgress = {read=FOnSendProgress, write=FOnSendProgress};
};


class DELPHICLASS TAHMPOPMail;
class PASCALIMPLEMENTATION TAHMPOPMail : public TAHMMailHost 
{
	typedef TAHMMailHost inherited;
	
private:
	int FCurrentMessage;
	TAHMMailSessionState FSessionState;
	Classes::TStrings* FExistingIDS;
	bool FPOPError;
	AnsiString FPOPErrorString;
	bool FReceivingVMessage;
	int FSize;
	Word FStep;
	Word FDecodeProgress;
	Word FRetrieveProgress;
	Classes::TStrings* FDeletedItems;
	Word FVMessagesCount;
	TAHMOnCodingStart FOnDecodeStart;
	TAHMMailProgress FOnDecodeProgress;
	Classes::TNotifyEvent FOnDecodeEnd;
	TAHMMailAction FOnBeforeRetrieve;
	TAHMAfterMsgAction FOnAfterRetrieve;
	TAHMMailProgress FOnRetrieveProgress;
	TAHMMailAction FOnDelete;
	bool __fastcall FindInHeaders(const AnsiString que, const Classes::TStringList* StrList, int &Line);
	bool __fastcall FindInStringList(const AnsiString que, const Classes::TStringList* StrList, int &Line, int &position);
	bool __fastcall FindInStringListCS(const AnsiString que, const Classes::TStringList* StrList, int &Line, int &position);
	bool __fastcall GetUUAttachments(const Classes::TStringList* StrList, int &Line, AnsiString &FileName);
	
protected:
	void __fastcall Base64Decode(TAHMAttachment* &VAttachment);
	void __fastcall UUDecode(TAHMAttachment* &VAttachment);
	virtual void __fastcall Connect(AnsiString Server, int Port, int TimeOut);
	virtual AnsiString __fastcall GetSocketText();
	bool __fastcall Login(void);
	Word __fastcall Init(void);
	void __fastcall DeleteMessage(Word Index);
	int __fastcall RetrieveMessages(void);
	void __fastcall RetrieveMessage(Word Index, bool GetHeaderOnly);
	
public:
	__fastcall virtual TAHMPOPMail(Classes::TComponent* AOwner);
	__fastcall virtual ~TAHMPOPMail(void);
	__property Classes::TStrings* DeletedItems = {read=FDeletedItems, write=FDeletedItems};
	bool __fastcall DownloadMessage(int Index);
	bool __fastcall EraseMessage(int Index);
	virtual bool __fastcall Execute(void);
	__property bool POPError = {read=FPOPError, nodefault};
	__property AnsiString ErrorString = {read=FPOPErrorString};
	__property Word VMessagesCount = {read=FVMessagesCount, nodefault};
	__property TAHMMailSessionState SessionState = {read=FSessionState, nodefault};
	__property Classes::TStrings* MessageIds = {read=FExistingIDS};
	
__published:
	__property Messages  = {stored=false};
	__property TAHMOnCodingStart OnDecodeStart = {read=FOnDecodeStart, write=FOnDecodeStart};
	__property TAHMMailProgress OnDecodeProgress = {read=FOnDecodeProgress, write=FOnDecodeProgress};
	__property Classes::TNotifyEvent OnDecodeEnd = {read=FOnDecodeEnd, write=FOnDecodeEnd};
	__property TAHMMailAction BeforeRetrieve = {read=FOnBeforeRetrieve, write=FOnBeforeRetrieve};
	__property TAHMAfterMsgAction AfterRetrieve = {read=FOnAfterRetrieve, write=FOnAfterRetrieve};
	__property TAHMMailProgress OnRetrieveProgress = {read=FOnRetrieveProgress, write=FOnRetrieveProgress};
	__property TAHMMailAction OnDelete = {read=FOnDelete, write=FOnDelete};
};


//-- var, const, procedure ---------------------------------------------------
#define crlf "\r\n"

}	/* namespace Ahmtiemails */
using namespace Ahmtiemails;
#pragma option pop	// -w-
#pragma option pop	// -Vx

#pragma delphiheader end.
//-- end unit ----------------------------------------------------------------
#endif	// ahmtiemails
