1 /* 2 * Copyright 2013-2015, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef IMAP_MAILBOX_H 6 #define IMAP_MAILBOX_H 7 8 9 #include "Commands.h" 10 #include "IMAPFolder.h" 11 12 13 namespace IMAP { 14 class Protocol; 15 }; 16 17 18 class IMAPMailbox : public FolderListener { 19 public: 20 IMAPMailbox(IMAP::Protocol& protocol, 21 const BString& mailboxName); 22 virtual ~IMAPMailbox(); 23 24 const BString& MailboxName() const { return fMailboxName; } 25 26 void AddMessageEntry(uint32 index, uint32 uid, 27 uint32 flags, uint32 size); 28 void RemoveMessageEntry(uint32 index); 29 30 uint32 UIDForIndex(uint32 index) const; 31 uint32 MessageFlags(uint32 uid) const; 32 uint32 MessageSize(uint32 uid) const; 33 uint32 CountMessages() const { return fUIDs.size(); } 34 35 // FolderListener interface 36 virtual uint32 MessageAdded(const MessageToken& fromToken, 37 const entry_ref& ref); 38 virtual void MessageDeleted(const MessageToken& token); 39 40 virtual void MessageFlagsChanged(const MessageToken& token, 41 const entry_ref& ref, uint32 oldFlags, 42 uint32 newFlags); 43 44 protected: 45 struct MessageFlagsAndSize { 46 MessageFlagsAndSize(uint32 _flags, uint32 _size) 47 : 48 flags(_flags), 49 size(_size) 50 { 51 } 52 53 uint32 flags; 54 uint32 size; 55 }; 56 #if __GNUC__ >= 4 57 typedef __gnu_cxx::hash_map<uint32, MessageFlagsAndSize> MessageEntryMap; 58 #else 59 typedef std::hash_map<uint32, MessageFlagsAndSize> MessageEntryMap; 60 #endif 61 62 IMAP::Protocol& fProtocol; 63 BString fMailboxName; 64 MessageEntryMap fMessageEntries; 65 IMAP::MessageUIDList fUIDs; 66 }; 67 68 69 #endif // IMAP_MAILBOX_H 70