1 /* 2 * Copyright 2013-2016, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 /*! This class offers a high level look at an IMAP mailbox. 8 */ 9 10 11 #include "IMAPMailbox.h" 12 13 14 IMAPMailbox::IMAPMailbox(IMAP::Protocol& protocol, const BString& mailboxName) 15 : 16 fProtocol(protocol), 17 fMailboxName(mailboxName) 18 { 19 } 20 21 22 IMAPMailbox::~IMAPMailbox() 23 { 24 } 25 26 27 void 28 IMAPMailbox::AddMessageEntry(uint32 index, uint32 uid, uint32 flags, 29 uint32 size) 30 { 31 fMessageEntries.insert( 32 std::make_pair(uid, MessageFlagsAndSize(flags, size))); 33 34 fUIDs.reserve(index + 1); 35 fUIDs[index] = uid; 36 } 37 38 39 void 40 IMAPMailbox::RemoveMessageEntry(uint32 index) 41 { 42 if (index >= fUIDs.size()) 43 return; 44 45 uint32 uid = fUIDs[index]; 46 fMessageEntries.erase(uid); 47 48 fUIDs.erase(fUIDs.begin() + index); 49 } 50 51 52 uint32 53 IMAPMailbox::UIDForIndex(uint32 index) const 54 { 55 if (index >= fUIDs.size()) 56 return 0; 57 58 return fUIDs[index]; 59 } 60 61 62 uint32 63 IMAPMailbox::MessageFlags(uint32 uid) const 64 { 65 MessageEntryMap::const_iterator found = fMessageEntries.find(uid); 66 if (found == fMessageEntries.end()) 67 return 0; 68 69 return found->second.flags; 70 } 71 72 73 uint32 74 IMAPMailbox::MessageSize(uint32 uid) const 75 { 76 MessageEntryMap::const_iterator found = fMessageEntries.find(uid); 77 if (found == fMessageEntries.end()) 78 return 0; 79 80 return found->second.size; 81 } 82 83 84 uint32 85 IMAPMailbox::MessageAdded(const MessageToken& fromToken, const entry_ref& ref) 86 { 87 printf("IMAP: message added %s, uid %" B_PRIu32 "\n", ref.name, 88 fromToken.uid); 89 return fromToken.uid; 90 } 91 92 93 void 94 IMAPMailbox::MessageDeleted(const MessageToken& token) 95 { 96 printf("IMAP: message deleted, uid %" B_PRIu32 "\n", token.uid); 97 } 98 99 100 void 101 IMAPMailbox::MessageFlagsChanged(const MessageToken& token, 102 const entry_ref& ref, uint32 oldFlags, uint32 newFlags) 103 { 104 printf("IMAP: flags changed %s, uid %" B_PRIu32 ", from %" B_PRIx32 " to %" 105 B_PRIx32 "\n", ref.name, token.uid, oldFlags, newFlags); 106 } 107