FolderChangesManifest ISourceFolder.EnumerateChanges(EnumerateContentChangesFlags flags, int maxChanges) { FolderChangesManifest folderChangesManifest = new FolderChangesManifest(base.FolderId); folderChangesManifest.ChangedMessages = new List <MessageRec>(); folderChangesManifest.ReadMessages = new List <byte[]>(); folderChangesManifest.UnreadMessages = new List <byte[]>(); SyncContentsManifestState syncContentsManifestState = base.Mailbox.SyncState[base.FolderId]; PopFolderState lastSyncedState; if (syncContentsManifestState.Data != null) { lastSyncedState = PopFolderState.Deserialize(syncContentsManifestState.Data); } else { lastSyncedState = PopFolderState.CreateNew(); } List <MessageRec> messages = base.EnumerateMessagesOnPopConnection(maxChanges); PopFolderState popFolderState = PopFolderState.Create(messages); this.EnumerateIncrementalChanges(popFolderState, lastSyncedState, folderChangesManifest, messages); syncContentsManifestState.Data = popFolderState.Serialize(); return(folderChangesManifest); }
internal static PopFolderState Create(List <MessageRec> messages) { PopFolderState popFolderState = new PopFolderState(); foreach (MessageRec messageRec in messages) { popFolderState.MessageList.Add(Encoding.UTF8.GetString(messageRec.EntryId)); } return(popFolderState); }
private void EnumerateMessageDeletes(PopFolderState currentState, PopFolderState lastSyncedState, FolderChangesManifest changes, Dictionary <string, MessageRec> lookup) { foreach (string text in lastSyncedState.MessageList.Values) { if (!currentState.MessageList.Contains(text)) { MessageRec messageRec = base.CreateMessageRec(text, 0L); messageRec.Flags |= MsgRecFlags.Deleted; changes.ChangedMessages.Add(messageRec); } } }
private void EnumerateIncrementalChanges(PopFolderState currentState, PopFolderState lastSyncedState, FolderChangesManifest changes, IEnumerable <MessageRec> messages) { Dictionary <string, MessageRec> dictionary = new Dictionary <string, MessageRec>(); foreach (MessageRec messageRec in messages) { string key = PopEntryId.ParseUid(messageRec.EntryId); dictionary.Add(key, messageRec); } this.EnumerateNewMessages(currentState, lastSyncedState, changes, dictionary); this.EnumerateMessageDeletes(currentState, lastSyncedState, changes, dictionary); }
public static PopFolderState Deserialize(byte[] compressedXml) { byte[] bytes = CommonUtils.DecompressData(compressedXml); string @string = Encoding.UTF7.GetString(bytes); if (string.IsNullOrEmpty(@string)) { throw new CorruptSyncStateException(new ArgumentNullException("data", "Cannot deserialize null or empty data")); } PopFolderState popFolderState = XMLSerializableBase.Deserialize <PopFolderState>(@string, true); popFolderState.MessageList = PopBookmark.Parse(popFolderState.MessageListString); return(popFolderState); }
private void EnumerateNewMessages(PopFolderState currentState, PopFolderState lastSyncedState, FolderChangesManifest changes, Dictionary <string, MessageRec> lookup) { foreach (string text in currentState.MessageList.Values) { if (!lastSyncedState.MessageList.Contains(text)) { MessageRec messageRec = null; if (lookup.TryGetValue(text, out messageRec)) { messageRec.Flags |= MsgRecFlags.New; changes.ChangedMessages.Add(messageRec); } } } }
List <MessageRec> ISourceFolder.EnumerateMessagesPaged(int maxPageSize) { SyncContentsManifestState syncContentsManifestState = base.Mailbox.SyncState[base.FolderId]; PopFolderState popFolderState = (syncContentsManifestState.Data != null) ? PopFolderState.Deserialize(syncContentsManifestState.Data) : PopFolderState.CreateNew(); foreach (string item in this.crawlerCopiedMessages.Values) { popFolderState.MessageList.Add(item); this.crawlerCopiedMessages.Remove(item); } syncContentsManifestState.Data = popFolderState.Serialize(); List <MessageRec> list = base.EnumerateMessagesOnPopConnection(0); List <MessageRec> list2 = new List <MessageRec>(); foreach (MessageRec messageRec in list) { string item2 = PopEntryId.ParseUid(messageRec.EntryId); if (!popFolderState.MessageList.Contains(item2)) { list2.Add(messageRec); if (list2.Count == maxPageSize) { break; } } } if (list2.Count == 0) { return(null); } foreach (MessageRec messageRec2 in list2) { string item3 = PopEntryId.ParseUid(messageRec2.EntryId); this.crawlerCopiedMessages.Add(item3); } return(list2); }