/*
	SendMailProxy.h
*/
#ifndef _SENDMAIL_PROXY_H
#define _SENDMAIL_PROXY_H
#include "IMAP.h"
#include "SMTP.h"

namespace Wagner {
// Forward Declarations
class SendMessageContainer;

class SendMailProxy {
	public:
		static SendMailProxy	&Newman();
								~SendMailProxy();

		status_t				SendMessage(SendMessageContainer *container);
		status_t				OpenImapSmtpConnections(IMAP &imap, SmtpDaemon &smtp, SendMessageContainer *container);
		BDataIO	*				CreateAdapterChain(SendMessageContainer *container);

	private:
								// There is only one send mail proxy
								SendMailProxy();
								
		static	status_t		DeliveryManEntry(void *arg);
		status_t				DeliveryMan();
		status_t				DeliverTheMessage(SendMessageContainer *container);
		
		bool fKeepDelivering;
		sem_id fSignalSem;
		sem_id fQueueSem;
		thread_id fQueueThread;
		BList fQueuedMessages;
};
}
#endif
