1/*
2 * Copyright 2007-2015, Haiku, Inc. All rights reserved.
3 * Copyright 2001-2002 Dr. Zoidberg Enterprises. All rights reserved.
4 * Copyright 2011, Clemens Zeidler <haiku@clemens-zeidler.de>
5 * Distributed under the terms of the MIT License.
6 */
7#ifndef MAIL_DAEMON_APPLICATION_H
8#define MAIL_DAEMON_APPLICATION_H
9
10
11#include <map>
12
13#include <ObjectList.h>
14#include <Message.h>
15#include <MessageRunner.h>
16#include <Node.h>
17#include <Query.h>
18#include <Server.h>
19#include <String.h>
20
21#include <MailProtocol.h>
22
23#include "LEDAnimation.h"
24#include "DefaultNotifier.h"
25
26
27class BNotification;
28struct send_mails_info;
29
30
31struct account_protocols {
32	account_protocols();
33
34	image_id				inboundImage;
35	BInboundMailProtocol*	inboundProtocol;
36	image_id				outboundImage;
37	BOutboundMailProtocol*	outboundProtocol;
38};
39
40
41typedef std::map<int32, account_protocols> AccountMap;
42
43
44class MailDaemonApplication : public BServer {
45public:
46								MailDaemonApplication();
47	virtual						~MailDaemonApplication();
48
49	virtual void				ReadyToRun();
50	virtual	void				RefsReceived(BMessage* message);
51	virtual	void				MessageReceived(BMessage* message);
52
53	virtual void				Pulse();
54	virtual bool				QuitRequested();
55
56			void				InstallDeskbarIcon();
57			void				RemoveDeskbarIcon();
58
59			void				GetNewMessages(BMessage* message);
60			void				SendPendingMessages(BMessage* message);
61
62			void				MakeMimeTypes(bool remakeMIMETypes = false);
63
64private:
65			void				_InitAccounts();
66			void				_InitAccount(BMailAccountSettings& settings);
67			void				_ReloadAccounts(BMessage* message);
68			void				_RemoveAccount(
69									const account_protocols& account);
70
71			BInboundMailProtocol* _CreateInboundProtocol(
72									BMailAccountSettings& settings,
73									image_id& image);
74			BOutboundMailProtocol* _CreateOutboundProtocol(
75									BMailAccountSettings& settings,
76									image_id& image);
77
78			BInboundMailProtocol* _InboundProtocol(int32 account);
79			BOutboundMailProtocol* _OutboundProtocol(int32 account);
80
81			void				_InitNewMessagesCount();
82			void				_UpdateNewMessagesNotification();
83			void				_UpdateAutoCheckRunner();
84
85			void				_AddMessage(send_mails_info& info,
86									const BEntry& entry, const BNode& node);
87
88	static	bool				_IsPending(BNode& node);
89	static	bool				_IsEntryInTrash(BEntry& entry);
90
91private:
92			BMessageRunner*		fAutoCheckRunner;
93			BMailSettings		fSettingsFile;
94
95			int32				fNewMessages;
96			bool				fCentralBeep;
97				// TRUE to do a beep when the status window closes. This happens
98				// when all mail has been received, so you get one beep for
99				// everything rather than individual beeps for each mail
100				// account.
101				// Set to TRUE by the 'mcbp' message that the mail Notification
102				// filter sends us, cleared when the beep is done.
103			BObjectList<BMessage> fFetchDoneRespondents;
104			BObjectList<BQuery>	fQueries;
105
106			LEDAnimation*		fLEDAnimation;
107
108			BString				fAlertString;
109
110			AccountMap			fAccounts;
111
112			ErrorLogWindow*		fErrorLogWindow;
113			BNotification*		fNotification;
114};
115
116
117#endif // MAIL_DAEMON_APPLICATION_H
118