xref: /haiku/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPProtocol.h (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
1 /*
2  * Copyright 2013-2016, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef IMAP_PROTOCOL_H
6 #define IMAP_PROTOCOL_H
7 
8 
9 #include <map>
10 
11 #include <MailProtocol.h>
12 #include <ObjectList.h>
13 
14 #include <locks.h>
15 
16 #include "Commands.h"
17 #include "Settings.h"
18 
19 
20 class IMAPConnectionWorker;
21 class IMAPFolder;
22 namespace IMAP {
23 	class Protocol;
24 }
25 
26 
27 typedef std::map<BString, IMAPFolder*> FolderMap;
28 
29 
30 class IMAPProtocol : public BInboundMailProtocol {
31 public:
32 								IMAPProtocol(
33 									const BMailAccountSettings& settings);
34 	virtual						~IMAPProtocol();
35 
36 			status_t			CheckSubscribedFolders(
37 									IMAP::Protocol& protocol, bool idle);
38 			void				WorkerQuit(IMAPConnectionWorker* worker);
39 
40 			void				MessageStored(IMAPFolder& folder,
41 									entry_ref& ref, BFile& stream,
42 									uint32 fetchFlags, BMessage& attributes);
43 
44 			status_t			UpdateMessageFlags(IMAPFolder& folder,
45 									uint32 uid, uint32 flags);
46 
47 	virtual	status_t			SyncMessages();
48 	virtual	status_t			MarkMessageAsRead(const entry_ref& ref,
49 									read_flags flags = B_READ);
50 
51 	virtual void				MessageReceived(BMessage* message);
52 	const ::Settings*			Settings() const { return &fSettings; }
53 
54 protected:
55 	virtual status_t			HandleFetchBody(const entry_ref& ref,
56 									const BMessenger& replyTo);
57 
58 			void				ReadyToRun();
59 
60 private:
61 			IMAPFolder*			_CreateFolder(const BString& mailbox,
62 									const BString& separator);
63 			IMAPFolder*			_FolderFor(ino_t directory);
64 			status_t			_EnqueueCheckMailboxes();
65 
66 protected:
67 	typedef std::map<IMAPFolder*, IMAPConnectionWorker*> WorkerMap;
68 	typedef std::map<ino_t, IMAPFolder*> FolderNodeMap;
69 
70 			::Settings			fSettings;
71 			mutex				fWorkerLock;
72 			BObjectList<IMAPConnectionWorker> fWorkers;
73 			WorkerMap			fWorkerMap;
74 			FolderMap			fFolders;
75 			FolderNodeMap		fFolderNodeMap;
76 };
77 
78 
79 #endif	// IMAP_PROTOCOL_H