xref: /haiku/src/add-ons/mail_daemon/inbound_protocols/imap/IMAPFolder.h (revision 3302df142ef8f47c0c0a7d6020b38a63c7cb7403)
1 /*
2  * Copyright 2012, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef IMAP_FOLDER_H
6 #define IMAP_FOLDER_H
7 
8 
9 #include <hash_map>
10 #include <sys/stat.h>
11 
12 #include <Entry.h>
13 #include <Node.h>
14 #include <Handler.h>
15 #include <String.h>
16 
17 
18 struct MessageToken {
19 	BString	mailboxName;
20 	uint32	uidValidity;
21 	uint32	uid;
22 };
23 
24 
25 class FolderListener {
26 public:
27 	virtual	uint32				MessageAdded(const MessageToken& fromToken,
28 									const entry_ref& ref) = 0;
29 	virtual void				MessageDeleted(const MessageToken& token) = 0;
30 
31 	virtual void				MessageFlagsChanged(const MessageToken& token,
32 									const entry_ref& ref, uint32 oldFlags,
33 									uint32 newFlags) = 0;
34 };
35 
36 
37 class IMAPFolder : public BHandler {
38 public:
39 								IMAPFolder(const BString& mailboxName,
40 									const entry_ref& ref);
41 	virtual						~IMAPFolder();
42 
43 			const BString&		MailboxName() const { return fMailboxName; }
44 
45 			void				SetListener(FolderListener* listener);
46 			void				SetUIDValidity(uint32 uidValidity);
47 
48 			status_t			StoreTemporaryMessage(uint32 fetchFlags,
49 									BDataIO& stream, size_t length,
50 									entry_ref& ref);
51 			void				StoreMessage(uint32 fetchFlags, uint32 uid,
52 									uint32 flags, entry_ref& ref);
53 			status_t			StoreMessage(uint32 fetchFlags, uint32 uid,
54 									BDataIO& stream, size_t length);
55 			void				DeleteMessage(uint32 uid);
56 			void				SetMessageFlags(uint32 uid, uint32 flags);
57 
58 	virtual void				MessageReceived(BMessage* message);
59 
60 private:
61 			void				_InitializeFolderState();
62 			const MessageToken	_Token(uint32 uid) const;
63 			uint32				_ReadUniqueID(BNode& node);
64 			uint32				_ReadFlags(BNode& node);
65 
66 private:
67 	typedef std::hash_map<uint32, uint32> UIDToFlagsMap;
68 	typedef std::hash_map<uint32, entry_ref> UIDToRefMap;
69 
70 			const entry_ref		fRef;
71 			BString				fMailboxName;
72 			uint32				fUIDValidity;
73 			FolderListener*		fListener;
74 			UIDToRefMap			fRefMap;
75 			UIDToFlagsMap		fUIDMap;
76 };
77 
78 
79 #endif	// IMAP_FOLDER_H
80