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 53 protected: 54 virtual status_t HandleFetchBody(const entry_ref& ref, 55 const BMessenger& replyTo); 56 57 void ReadyToRun(); 58 59 private: 60 IMAPFolder* _CreateFolder(const BString& mailbox, 61 const BString& separator); 62 IMAPFolder* _FolderFor(ino_t directory); 63 status_t _EnqueueCheckMailboxes(); 64 65 protected: 66 typedef std::map<IMAPFolder*, IMAPConnectionWorker*> WorkerMap; 67 typedef std::map<ino_t, IMAPFolder*> FolderNodeMap; 68 69 Settings fSettings; 70 mutex fWorkerLock; 71 BObjectList<IMAPConnectionWorker> fWorkers; 72 WorkerMap fWorkerMap; 73 FolderMap fFolders; 74 FolderNodeMap fFolderNodeMap; 75 }; 76 77 78 #endif // IMAP_PROTOCOL_H 79