Esempio n. 1
0
        Stream ISupportMime.GetMimeStream(MessageRec message, out PropValueData[] extraPropValues)
        {
            extraPropValues = null;
            Properties properties = this.FetchMessageItem(message);

            if (properties == null || properties.Body == null || string.IsNullOrEmpty(properties.Body.Data))
            {
                throw new UnableToFetchMimeStreamException(EasMailbox.GetStringId(message.EntryId));
            }
            if (properties.Flag != null)
            {
                extraPropValues = new PropValueData[]
                {
                    new PropValueData((PropTag)277872643U, properties.Flag.Status)
                };
            }
            string       data         = properties.Body.Data;
            MemoryStream memoryStream = new MemoryStream(data.Length);
            Stream       result;

            using (DisposeGuard disposeGuard = memoryStream.Guard())
            {
                using (StreamWriter streamWriter = new StreamWriter(memoryStream, Encoding.UTF8, 1024, true))
                {
                    streamWriter.Write(data);
                }
                memoryStream.Seek(0L, SeekOrigin.Begin);
                disposeGuard.Success();
                result = memoryStream;
            }
            return(result);
        }
Esempio n. 2
0
 protected override void InternalDispose(bool disposing)
 {
     if (disposing)
     {
         this.Mailbox = null;
     }
 }
Esempio n. 3
0
        private Properties ReadCalendarItem(MessageRec messageRec)
        {
            Add    add      = base.EasFolderCache[messageRec.FolderId];
            string stringId = EasMailbox.GetStringId(messageRec.EntryId);

            return(base.EasConnectionWrapper.FetchCalendarItem(stringId, add.ServerId));
        }
Esempio n. 4
0
        ISourceFolder ISourceMailbox.GetFolder(byte[] entryId)
        {
            MrsTracer.Provider.Function("EasSourceMailbox.GetFolder({0})", new object[]
            {
                TraceUtils.DumpEntryId(entryId)
            });
            Add           add;
            EasFolderBase easFolderBase;

            if (base.EasFolderCache.TryGetValue(entryId, out add))
            {
                easFolderBase = new EasSourceFolder(add, base.EasConnectionWrapper.UserSmtpAddress);
            }
            else if (EasMailbox.GetStringId(entryId) == EasSyntheticFolder.RootFolder.ServerId)
            {
                easFolderBase = EasSyntheticFolder.RootFolder;
            }
            else
            {
                if (!(EasMailbox.GetStringId(entryId) == EasSyntheticFolder.IpmSubtreeFolder.ServerId))
                {
                    MrsTracer.Provider.Debug("Folder with folderId '{0}' does not exist.", new object[]
                    {
                        entryId
                    });
                    return(null);
                }
                easFolderBase = EasSyntheticFolder.IpmSubtreeFolder;
            }
            return((ISourceFolder)easFolderBase.Configure(this));
        }
Esempio n. 5
0
 protected IEnumerable <MessageRec> CreateMessageRecsForDeletions(List <DeleteCommand> deletions)
 {
     foreach (DeleteCommand delete in deletions)
     {
         yield return(new MessageRec(EasMailbox.GetEntryId(delete.ServerId), base.EntryId, DateTime.MinValue, 0, MsgRecFlags.Deleted, this.GetAdditionalProps(delete)));
     }
     yield break;
 }
Esempio n. 6
0
        private Properties FetchMessageItem(MessageRec messageRec)
        {
            base.CheckDisposed();
            Add    add      = base.EasFolderCache[messageRec.FolderId];
            string stringId = EasMailbox.GetStringId(messageRec.EntryId);

            return(base.EasConnectionWrapper.FetchMessageItem(stringId, add.ServerId));
        }
Esempio n. 7
0
 private IEnumerable <MessageRec> CreateMessageRecsForAdditions(List <AddCommand> additions)
 {
     foreach (AddCommand addition in additions)
     {
         yield return(new MessageRec(EasMailbox.GetEntryId(addition.ServerId), base.EntryId, EasFolder.GetCreationTimestamp(addition.ApplicationData.DateReceived), (int)((addition.ApplicationData.Body == null) ? 0U : addition.ApplicationData.Body.EstimatedDataSize), MsgRecFlags.None, this.GetAdditionalProps(addition)));
     }
     yield break;
 }
Esempio n. 8
0
 protected EasFolderBase(string serverId, string parentId, string displayName, EasFolderType folderType)
 {
     this.serverId    = serverId;
     this.parentId    = parentId;
     this.displayName = displayName;
     this.folderType  = folderType;
     this.EntryId     = EasMailbox.GetEntryId(serverId);
 }
Esempio n. 9
0
 private byte[] GetParentId(Add add)
 {
     if (add.GetEasFolderType() != EasFolderType.UserCalendar)
     {
         return(EasMailbox.GetEntryId(add.ParentId));
     }
     return(this.defaultCalendarId);
 }
        internal byte[] CreateCalendarEvent(string clientId, string syncKey, out string newSyncKey, string folderId, Event theEvent, IList <Event> exceptionalEvents, IList <string> deletedOccurrences, UserSmtpAddress userSmtpAddress)
        {
            SyncRequest  syncRequest  = EasRequestGenerator.CreateSyncRequestForCreateCalendarEvent(syncKey, clientId, folderId, theEvent, exceptionalEvents, deletedOccurrences, userSmtpAddress);
            SyncResponse syncResponse = this.SyncCreation(clientId, syncRequest);

            newSyncKey = syncResponse.Collections[0].SyncKey;
            return(EasMailbox.GetEntryId(syncResponse.AddResponses[0].ServerId));
        }
Esempio n. 11
0
 private IEnumerable <MessageRec> CreateMessageRecsForChanges(List <ChangeCommand> changes)
 {
     foreach (ChangeCommand change in changes)
     {
         int estimatedDataSize = (int)((change.ApplicationData.Body == null) ? 0U : change.ApplicationData.Body.EstimatedDataSize);
         yield return(new MessageRec(EasMailbox.GetEntryId(change.ServerId), base.EntryId, DateTime.MinValue, estimatedDataSize, MsgRecFlags.None, this.GetAdditionalProps(change)));
     }
     yield break;
 }
Esempio n. 12
0
        private List <MessageRec> CreateMessageRecsForFetches(IReadOnlyCollection <Fetch> fetches)
        {
            List <MessageRec> list = new List <MessageRec>(fetches.Count);

            foreach (Fetch fetch in fetches)
            {
                if (fetch.Status == 1)
                {
                    list.Add(new MessageRec(EasMailbox.GetEntryId(fetch.ServerId), base.EntryId, EasFolder.GetCreationTimestamp(fetch.Properties.DateReceived), (int)fetch.Properties.Body.EstimatedDataSize, MsgRecFlags.None, this.GetAdditionalProps(fetch)));
                }
            }
            return(list);
        }
Esempio n. 13
0
        List <MessageRec> ISourceFolder.EnumerateMessagesPaged(int maxPageSize)
        {
            SyncContentsManifestState syncContentsManifestState = base.Mailbox.SyncState[base.EntryId];
            EasFolderSyncState        persistedSyncState        = base.Mailbox.GetPersistedSyncState(syncContentsManifestState);

            if (string.IsNullOrEmpty(this.nextEnumerateKey))
            {
                this.nextEnumerateKey = persistedSyncState.CrawlerSyncKey;
            }
            else
            {
                persistedSyncState.CrawlerSyncKey = this.nextEnumerateKey;
                persistedSyncState.CrawlerDeletions.AddRange(this.pendingDeletes);
                syncContentsManifestState.Data = persistedSyncState.Serialize();
            }
            EasSyncOptions options = new EasSyncOptions
            {
                SyncKey            = this.nextEnumerateKey,
                RecentOnly         = false,
                MaxNumberOfMessage = maxPageSize
            };
            EasSyncResult easSyncResult = base.SyncMessages(base.Mailbox.CrawlerConnectionWrapper, options);

            if (this.estimatedItemCount == 0)
            {
                options.SyncKey         = easSyncResult.SyncKeyRequested;
                this.estimatedItemCount = base.GetItemEstimate(base.Mailbox.CrawlerConnectionWrapper, options);
            }
            if (easSyncResult.MessageRecs.Count == 0)
            {
                return(null);
            }
            this.nextEnumerateKey = easSyncResult.NewSyncKey;
            List <MessageRec> list = new List <MessageRec>(easSyncResult.MessageRecs.Count);

            foreach (MessageRec messageRec in easSyncResult.MessageRecs)
            {
                if (persistedSyncState.ChangesSynced == null || !(messageRec.CreationTimestamp < persistedSyncState.ChangesSynced.Value) || !(messageRec.CreationTimestamp > persistedSyncState.ChangesSynced.Value - EasRequestGenerator.RecentSyncTimeSpan))
                {
                    if (EasSourceFolder.FindMessageCategory(messageRec) == EasMessageCategory.Delete)
                    {
                        this.pendingDeletes.Add(EasMailbox.GetStringId(messageRec.EntryId));
                    }
                    else
                    {
                        list.Add(messageRec);
                    }
                }
            }
            return(list);
        }
Esempio n. 14
0
        protected override MailboxChangesManifest RunManualHierarchySync(bool catchup, SyncHierarchyManifestState hierState)
        {
            MrsTracer.Provider.Function("EasSourceMailbox.RunManualHierarchySync", new object[0]);
            base.VerifyMailboxConnection(VerifyMailboxConnectionFlags.None);
            EasHierarchySyncState easHierarchySyncState = EasHierarchySyncState.Deserialize(hierState.ProviderSyncState);

            hierState.ProviderSyncState = null;
            EasHierarchySyncState easHierarchySyncState2 = base.RefreshFolderCache();
            EntryIdMap <EasHierarchySyncState.EasFolderData> entryIdMap = new EntryIdMap <EasHierarchySyncState.EasFolderData>();

            foreach (EasHierarchySyncState.EasFolderData easFolderData in easHierarchySyncState.FolderData)
            {
                entryIdMap[EasMailbox.GetEntryId(easFolderData.ServerId)] = easFolderData;
            }
            EntryIdMap <EasHierarchySyncState.EasFolderData> entryIdMap2 = new EntryIdMap <EasHierarchySyncState.EasFolderData>();

            foreach (EasHierarchySyncState.EasFolderData easFolderData2 in easHierarchySyncState2.FolderData)
            {
                entryIdMap2[EasMailbox.GetEntryId(easFolderData2.ServerId)] = easFolderData2;
            }
            MailboxChangesManifest mailboxChangesManifest = new MailboxChangesManifest();

            mailboxChangesManifest.DeletedFolders = new List <byte[]>();
            foreach (byte[] array in entryIdMap.Keys)
            {
                if (!entryIdMap2.ContainsKey(array))
                {
                    mailboxChangesManifest.DeletedFolders.Add(array);
                }
            }
            mailboxChangesManifest.ChangedFolders = new List <byte[]>();
            foreach (KeyValuePair <byte[], EasHierarchySyncState.EasFolderData> keyValuePair in entryIdMap2)
            {
                byte[] key = keyValuePair.Key;
                EasHierarchySyncState.EasFolderData value = keyValuePair.Value;
                EasHierarchySyncState.EasFolderData easFolderData3;
                if (entryIdMap.TryGetValue(key, out easFolderData3))
                {
                    if (easFolderData3.ParentId != value.ParentId || easFolderData3.DisplayName != value.DisplayName)
                    {
                        mailboxChangesManifest.ChangedFolders.Add(key);
                    }
                }
                else
                {
                    mailboxChangesManifest.ChangedFolders.Add(key);
                }
            }
            return(mailboxChangesManifest);
        }
Esempio n. 15
0
        protected void RefreshFolderCache(EasHierarchySyncState state)
        {
            IReadOnlyCollection <Add> folders    = state.Folders;
            EntryIdMap <Add>          entryIdMap = new EntryIdMap <Add>(folders.Count);

            this.defaultCalendarId = null;
            foreach (Add add in folders)
            {
                EasFolderType easFolderType = add.GetEasFolderType();
                if (easFolderType == EasFolderType.Calendar)
                {
                    this.defaultCalendarId = EasMailbox.GetEntryId(add.ServerId);
                }
                EasFolderType easFolderType2 = easFolderType;
                if (easFolderType2 == EasFolderType.UserGeneric)
                {
                    goto IL_8B;
                }
                bool flag;
                switch (easFolderType2)
                {
                case EasFolderType.Contacts:
                case EasFolderType.UserContacts:
                    flag = !ConfigBase <MRSConfigSchema> .GetConfig <bool>("DisableContactSync");

                    goto IL_9D;

                case EasFolderType.UserMail:
                case EasFolderType.UserCalendar:
                    goto IL_8B;
                }
                flag = EasMailbox.folderTypeMap.ContainsKey(easFolderType);
IL_9D:
                if (flag)
                {
                    entryIdMap.Add(EasMailbox.GetEntryId(add.ServerId), add);
                    continue;
                }
                MrsTracer.Provider.Debug("EasMailbox.RefreshFolderCache: ignore {0} folder '{1}' since it is not supported yet", new object[]
                {
                    easFolderType,
                    add.DisplayName
                });
                continue;
IL_8B:
                flag = true;
                goto IL_9D;
            }
            this.EasFolderCache = entryIdMap;
        }
Esempio n. 16
0
        List <WellKnownFolder> IMailbox.DiscoverWellKnownFolders(int flags)
        {
            List <WellKnownFolder> list = new List <WellKnownFolder>(this.EasFolderCache.Count + 1);

            foreach (Add add in this.EasFolderCache.Values)
            {
                WellKnownFolderType wkfType;
                if (EasMailbox.folderTypeMap.TryGetValue(add.GetEasFolderType(), out wkfType))
                {
                    list.Add(new WellKnownFolder((int)wkfType, EasMailbox.GetEntryId(add.ServerId)));
                }
            }
            list.Add(new WellKnownFolder(3, EasSyntheticFolder.IpmSubtreeFolder.EntryId));
            return(list);
        }
Esempio n. 17
0
        protected override MailboxChangesManifest DoManifestSync(EnumerateHierarchyChangesFlags flags, int maxChanges, SyncHierarchyManifestState hierState, MapiStore mapiStore)
        {
            MrsTracer.Provider.Function("EasSourceMailbox.DoManifestSync", new object[0]);
            base.VerifyMailboxConnection(VerifyMailboxConnectionFlags.None);
            flags.HasFlag(EnumerateHierarchyChangesFlags.Catchup);
            EasHierarchySyncState easHierarchySyncState = EasHierarchySyncState.Deserialize(hierState.ProviderSyncState);
            string syncKey = easHierarchySyncState.SyncKey;
            string syncKey2;
            IReadOnlyCollection <Add> readOnlyCollection;
            MailboxChangesManifest    folderChangesOnServer = this.GetFolderChangesOnServer(syncKey, out syncKey2, out readOnlyCollection);
            bool flag = false;

            easHierarchySyncState.SyncKey = syncKey2;
            if (folderChangesOnServer.DeletedFolders != null)
            {
                List <Add> list = new List <Add>(folderChangesOnServer.DeletedFolders.Count);
                foreach (Add add in easHierarchySyncState.Folders)
                {
                    foreach (byte[] entryId in folderChangesOnServer.DeletedFolders)
                    {
                        if (StringComparer.Ordinal.Equals(add.ServerId, EasMailbox.GetStringId(entryId)))
                        {
                            list.Add(add);
                            break;
                        }
                    }
                }
                foreach (Add item in list)
                {
                    easHierarchySyncState.Folders.Remove(item);
                    flag = true;
                }
            }
            if (readOnlyCollection != null)
            {
                foreach (Add item2 in readOnlyCollection)
                {
                    easHierarchySyncState.Folders.Add(item2);
                    flag = true;
                }
            }
            hierState.ProviderSyncState = easHierarchySyncState.Serialize(false);
            if (flag)
            {
                base.RefreshFolderCache(easHierarchySyncState);
            }
            return(folderChangesOnServer);
        }
Esempio n. 18
0
        private byte[] CreateItem(byte[] itemEntryId, byte[] folderEntryId, Func <string, string, string, byte[]> executeSync)
        {
            base.CheckDisposed();
            Add add;

            if (!base.EasFolderCache.TryGetValue(folderEntryId, out add))
            {
                MrsTracer.Provider.Warning("Source folder {0} doesn't exist", new object[]
                {
                    TraceUtils.DumpBytes(folderEntryId)
                });
                throw new EasObjectNotFoundException(EasMailbox.GetStringId(folderEntryId));
            }
            string arg     = EasSourceMailbox.ClientIdFromItemId(itemEntryId);
            string syncKey = base.GetPersistedSyncState(folderEntryId).SyncKey;

            return(executeSync(arg, syncKey, add.ServerId));
        }
Esempio n. 19
0
        private void UpdateItem(byte[] itemEntryId, byte[] folderEntryId, Action <string, string, string> executeSync)
        {
            base.CheckDisposed();
            Add add;

            if (!base.EasFolderCache.TryGetValue(folderEntryId, out add))
            {
                MrsTracer.Provider.Warning("Source folder {0} doesn't exist", new object[]
                {
                    TraceUtils.DumpBytes(folderEntryId)
                });
                throw new EasObjectNotFoundException(EasMailbox.GetStringId(folderEntryId));
            }
            string stringId = EasMailbox.GetStringId(itemEntryId);
            string syncKey  = base.GetPersistedSyncState(folderEntryId).SyncKey;

            executeSync(stringId, syncKey, add.ServerId);
        }
Esempio n. 20
0
        protected override List <MessageRec> InternalLookupMessages(PropTag ptagToLookup, List <byte[]> keysToLookup, PropTag[] additionalPtagsToLoad)
        {
            ArgumentValidator.ThrowIfInvalidValue <PropTag>("ptagToLookup", ptagToLookup, (PropTag ptag) => ptag == PropTag.EntryId);
            List <string> list = new List <string>(keysToLookup.Count);

            foreach (byte[] entryId in keysToLookup)
            {
                list.Add(EasMailbox.GetStringId(entryId));
            }
            List <Fetch> fetchList = new List <Fetch>(keysToLookup.Count);

            CommonUtils.ProcessInBatches <string>(list.ToArray(), 10, delegate(string[] messageBatch)
            {
                ItemOperationsResponse itemOperationsResponse = this.Mailbox.EasConnectionWrapper.LookupItems(messageBatch, this.ServerId);
                fetchList.AddRange(itemOperationsResponse.Response.Fetches);
            });
            return(this.CreateMessageRecsForFetches(fetchList));
        }
Esempio n. 21
0
        private MailboxChangesManifest GetFolderChangesOnServer(string syncKey, out string newSyncKey, out IReadOnlyCollection <Add> newFolders)
        {
            newFolders = null;
            FolderSyncResponse folderSyncResponse = base.EasConnectionWrapper.FolderSync(syncKey);

            newSyncKey = folderSyncResponse.SyncKey;
            MailboxChangesManifest mailboxChangesManifest = new MailboxChangesManifest();

            mailboxChangesManifest.ChangedFolders = new List <byte[]>(0);
            mailboxChangesManifest.DeletedFolders = new List <byte[]>(0);
            if (folderSyncResponse.Changes != null)
            {
                List <Add> additions = folderSyncResponse.Changes.Additions;
                if (additions != null && additions.Count > 0)
                {
                    mailboxChangesManifest.ChangedFolders.Capacity += additions.Count;
                    foreach (Add add in additions)
                    {
                        mailboxChangesManifest.ChangedFolders.Add(EasMailbox.GetEntryId(add.ServerId));
                    }
                    newFolders = additions;
                }
                List <Update> updates = folderSyncResponse.Changes.Updates;
                if (updates != null && updates.Count > 0)
                {
                    mailboxChangesManifest.ChangedFolders.Capacity += updates.Count;
                    foreach (Update update in updates)
                    {
                        mailboxChangesManifest.ChangedFolders.Add(EasMailbox.GetEntryId(update.ServerId));
                    }
                }
                List <Delete> deletions = folderSyncResponse.Changes.Deletions;
                if (deletions != null && deletions.Count > 0)
                {
                    mailboxChangesManifest.DeletedFolders.Capacity = deletions.Count;
                    foreach (Delete delete in deletions)
                    {
                        mailboxChangesManifest.DeletedFolders.Add(EasMailbox.GetEntryId(delete.ServerId));
                    }
                }
            }
            return(mailboxChangesManifest);
        }
Esempio n. 22
0
        private byte[] MoveItem(byte[] messageEntryId, byte[] sourceFolderEntryId, byte[] destFolderEntryId, out bool isPermanentDeletionMove)
        {
            isPermanentDeletionMove = false;
            base.CheckDisposed();
            Add add;

            if (!base.EasFolderCache.TryGetValue(sourceFolderEntryId, out add))
            {
                MrsTracer.Provider.Warning("Source folder {0} doesn't exist", new object[]
                {
                    TraceUtils.DumpBytes(sourceFolderEntryId)
                });
                throw new EasObjectNotFoundException(EasMailbox.GetStringId(sourceFolderEntryId));
            }
            Add add2;

            if (!base.EasFolderCache.TryGetValue(destFolderEntryId, out add2))
            {
                MrsTracer.Provider.Warning("Destination folder {0} doesn't exist", new object[]
                {
                    TraceUtils.DumpBytes(destFolderEntryId)
                });
                throw new EasObjectNotFoundException(EasMailbox.GetStringId(destFolderEntryId));
            }
            string stringId = EasMailbox.GetStringId(messageEntryId);

            if (add2.Type == 4 && EasFolder.IsCalendarFolder((EasFolderType)add.Type))
            {
                this.DeleteItem(messageEntryId, sourceFolderEntryId);
                isPermanentDeletionMove = true;
                return(null);
            }
            string stringId2 = base.EasConnectionWrapper.MoveItem(stringId, add.ServerId, add2.ServerId);

            return(EasMailbox.GetEntryId(stringId2));
        }
Esempio n. 23
0
 private FolderRec CreateGenericFolderRec(Add add)
 {
     return(new FolderRec(EasMailbox.GetEntryId(add.ServerId), this.GetParentId(add), FolderType.Generic, EasMailbox.GetFolderClass(add), add.DisplayName, DateTime.MinValue, null));
 }
Esempio n. 24
0
 protected static FolderRec CreateGenericFolderRec(EasFolderBase folder)
 {
     return(new FolderRec(folder.EntryId, EasMailbox.GetEntryId(folder.ParentId), FolderType.Generic, folder.DisplayName, DateTime.MinValue, null));
 }
Esempio n. 25
0
 internal EasFolderBase Configure(EasMailbox mailbox)
 {
     this.Mailbox = mailbox;
     return(this);
 }