예제 #1
0
        public PersistablePropertyBag CreateAttachment(ICollection <PropertyDefinition> propertiesToLoad, CoreAttachment attachmentToClone, IItem itemToAttach, out int attachmentNumber)
        {
            this.CheckDisposed(null);
            InMemoryPersistablePropertyBag inMemoryPersistablePropertyBag = new InMemoryPersistablePropertyBag(propertiesToLoad);

            inMemoryPersistablePropertyBag.ExTimeZone = this.ExTimeZone;
            if (attachmentToClone != null)
            {
                throw new NotSupportedException("CreateAttachment for copied attachments is not supported");
            }
            attachmentNumber = this.attachmentCounter++;
            inMemoryPersistablePropertyBag[InternalSchema.AttachNum] = attachmentNumber;
            this.newAttachmentList.Add(attachmentNumber, inMemoryPersistablePropertyBag);
            if (itemToAttach != null)
            {
                string text   = itemToAttach.TryGetProperty(InternalSchema.ItemClass) as string;
                Schema schema = (text != null) ? ObjectClass.GetSchema(text) : ItemSchema.Instance;
                propertiesToLoad = InternalSchema.Combine <PropertyDefinition>(schema.AutoloadProperties, propertiesToLoad);
                using (DisposeGuard disposeGuard = default(DisposeGuard))
                {
                    PersistablePropertyBag persistablePropertyBag = new InMemoryPersistablePropertyBag(propertiesToLoad);
                    disposeGuard.Add <PersistablePropertyBag>(persistablePropertyBag);
                    persistablePropertyBag.ExTimeZone = this.ExTimeZone;
                    CoreItem coreItem = new CoreItem(null, persistablePropertyBag, null, null, Origin.New, ItemLevel.Attached, propertiesToLoad, ItemBindOption.LoadRequiredPropertiesOnly);
                    disposeGuard.Add <CoreItem>(coreItem);
                    CoreItem.CopyItemContent(itemToAttach.CoreItem, coreItem);
                    this.attachedItems.Add(attachmentNumber, coreItem);
                    disposeGuard.Success();
                }
            }
            return(inMemoryPersistablePropertyBag);
        }
예제 #2
0
        public ICoreItem OpenAttachedItem(ICollection <PropertyDefinition> propertiesToLoad, AttachmentPropertyBag attachmentBag, bool isNew)
        {
            this.CheckDisposed(null);
            CoreItem coreItem         = null;
            int      attachmentNumber = attachmentBag.AttachmentNumber;

            if (this.attachedItems.TryGetValue(attachmentNumber, out coreItem))
            {
                string text   = coreItem.PropertyBag.TryGetProperty(InternalSchema.ItemClass) as string;
                Schema schema = (text != null) ? ObjectClass.GetSchema(text) : MessageItemSchema.Instance;
                propertiesToLoad = InternalSchema.Combine <PropertyDefinition>(schema.AutoloadProperties, propertiesToLoad);
                coreItem.PropertyBag.Load(propertiesToLoad);
            }
            else
            {
                if (!isNew)
                {
                    throw new ObjectNotFoundException(ServerStrings.MapiCannotOpenEmbeddedMessage);
                }
                string text2   = attachmentBag.TryGetProperty(InternalSchema.ItemClass) as string;
                Schema schema2 = (text2 != null) ? ObjectClass.GetSchema(text2) : MessageItemSchema.Instance;
                propertiesToLoad = InternalSchema.Combine <PropertyDefinition>(schema2.AutoloadProperties, propertiesToLoad);
                coreItem         = new CoreItem(null, new InMemoryPersistablePropertyBag(propertiesToLoad)
                {
                    ExTimeZone = this.ExTimeZone
                }, StoreObjectId.DummyId, null, Origin.New, ItemLevel.Attached, propertiesToLoad, ItemBindOption.LoadRequiredPropertiesOnly);
                if (text2 != null)
                {
                    coreItem.PropertyBag[InternalSchema.ItemClass] = text2;
                }
                this.attachedItems.Add(attachmentNumber, coreItem);
            }
            return(new CoreItemWrapper(coreItem));
        }
예제 #3
0
        private LoadedItemPart CreateLoadedItemPart(IItem item, IStorePropertyBag propertyBagFromTree, HtmlStreamOptionCallback htmlCallback, PropertyDefinition[] additionalPropertyDefinitions, ItemPartIrmInfo itemPartIrmInfo, bool isIrmEnabled, long bytesLoadedForConversation, bool isSmimeSupported, string domainName)
        {
            ConversationBodyScanner bodyScanner = null;
            long bytesLoaded = 0L;

            PropertyDefinition[] loadedProperties = InternalSchema.Combine <PropertyDefinition>(this.queriedPropertyDefinitions, additionalPropertyDefinitions).ToArray <PropertyDefinition>();
            IStorePropertyBag    propertyBag      = this.CalculatePropertyBag(propertyBagFromTree, item, additionalPropertyDefinitions);
            BodyFragmentInfo     bodyFragmentInfo = null;
            bool didLoadSucceed = false;

            if (this.TryLoadBodyScanner(item, htmlCallback, bytesLoadedForConversation, isIrmEnabled, out bodyScanner, out bytesLoaded))
            {
                bodyFragmentInfo = new BodyFragmentInfo(bodyScanner);
                didLoadSucceed   = true;
            }
            AttachmentCollection attachmentCollection = item.AttachmentCollection;

            if (isIrmEnabled)
            {
                this.InitializeIrmInfo(item, itemPartIrmInfo, out attachmentCollection);
            }
            string itemClass = item.TryGetProperty(StoreObjectSchema.ItemClass) as string;

            if (isSmimeSupported && ObjectClass.IsSmimeClearSigned(itemClass))
            {
                this.InitializeSmimeInfo(item, domainName, out attachmentCollection);
            }
            return(new LoadedItemPart(item, propertyBag, bodyFragmentInfo, loadedProperties, itemPartIrmInfo, didLoadSucceed, bytesLoaded, attachmentCollection));
        }
예제 #4
0
        public static IStorePropertyBag[] FindItemsFromInternetId(MailboxSession session, string internetMessageId, params PropertyDefinition[] propertyDefinitions)
        {
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullOrEmptyArgument(internetMessageId, "internetMessageId");
            Util.ThrowOnNullOrEmptyArgument(propertyDefinitions, "propertyDefinitions");
            DumpsterFolderHelper.CheckAndCreateFolder(session);
            ICollection <PropertyDefinition> dataColumns = InternalSchema.Combine <PropertyDefinition>(propertyDefinitions, new PropertyDefinition[]
            {
                ItemSchema.InternetMessageId
            });

            IStorePropertyBag[] result;
            using (Folder folder = Folder.Bind(session, DefaultFolderType.RecoverableItemsDeletions))
            {
                using (QueryResult queryResult = folder.ItemQuery(ItemQueryType.None, null, DumpsterFolderHelper.searchSortBy, dataColumns))
                {
                    if (queryResult.SeekToCondition(SeekReference.OriginBeginning, new ComparisonFilter(ComparisonOperator.Equal, DumpsterFolderHelper.searchSortBy[0].ColumnDefinition, internetMessageId)))
                    {
                        result = DumpsterFolderHelper.ProcessQueryResult(queryResult, internetMessageId);
                    }
                    else
                    {
                        result = Array <IStorePropertyBag> .Empty;
                    }
                }
            }
            return(result);
        }
예제 #5
0
        public HashSet <PropertyDefinition> CalculatePropertyDefinitionsToBeLoaded(ICollection <PropertyDefinition> requestedProperties)
        {
            ICollection <PropertyDefinition> collection = InternalSchema.Combine <PropertyDefinition>(ConversationTreeFactory.RequiredBuildTreeProperties, requestedProperties);
            HashSet <PropertyDefinition>     hashSet    = new HashSet <PropertyDefinition>(collection);

            hashSet.ExceptWith(ConversationDataExtractor.BodyPropertiesCanBeExtracted);
            return(hashSet);
        }
        public static IStorePropertyBag[] FindItemsFromInternetId(MailboxSession session, string internetMessageId, ItemQueryType itemQueryType, params PropertyDefinition[] propertyDefinitions)
        {
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullOrEmptyArgument(internetMessageId, "internetMessageId");
            Util.ThrowOnNullOrEmptyArgument(propertyDefinitions, "propertyDefinitions");
            ICollection <PropertyDefinition> properties = InternalSchema.Combine <PropertyDefinition>(propertyDefinitions, new PropertyDefinition[]
            {
                ItemSchema.InternetMessageId,
                ItemSchema.InternetMessageIdHash
            });
            int internetMessageIdHash = (int)AllItemsFolderHelper.GetHashValue(internetMessageId);

            IStorePropertyBag[] array = AllItemsFolderHelper.RunQueryOnAllItemsFolder <IStorePropertyBag[]>(session, AllItemsFolderHelper.SupportedSortBy.InternetMessageIdHash, internetMessageIdHash, null, (QueryResult queryResult) => AllItemsFolderHelper.ProcessQueryResult(queryResult, internetMessageId, internetMessageIdHash), properties, itemQueryType);
            return(array ?? Array <IStorePropertyBag> .Empty);
        }
예제 #7
0
 private void OnOpenConnection(ICollection <PropertyDefinition> propertiesToLoad)
 {
     if (this.persistablePropertyBag == null)
     {
         Schema attachmentSchema = AttachmentPropertyBag.GetAttachmentSchema(this.AttachMethod);
         propertiesToLoad            = InternalSchema.Combine <PropertyDefinition>(attachmentSchema.AutoloadProperties, propertiesToLoad);
         this.persistablePropertyBag = this.attachmentProvider.OpenAttachment(propertiesToLoad, this);
         this.persistablePropertyBag.Context.Session   = this.attachmentTablePropertyBag.Context.Session;
         this.persistablePropertyBag.Context.CoreState = this.attachmentTablePropertyBag.Context.CoreState;
         this.UpdateAttachmentTableCache();
     }
     else if (propertiesToLoad != null)
     {
         this.persistablePropertyBag.Load(propertiesToLoad);
     }
     this.attachmentProvider.OnAttachmentLoad(this);
 }
        private AttachmentPropertyBag InternalCreateAttachmentPropertyBag(AttachmentType?type, CoreAttachment attachmentToClone, IItem itemToAttach)
        {
            this.InitCollection("InternalCreateAttachmentPropertyBag", true);
            bool flag             = false;
            int  attachmentNumber = -1;
            PersistablePropertyBag persistablePropertyBag = null;
            AttachmentPropertyBag  attachmentPropertyBag  = null;

            try
            {
                Schema attachmentSchema = CoreAttachmentCollection.GetAttachmentSchema(type);
                ICollection <PropertyDefinition> prefetchProperties = InternalSchema.Combine <PropertyDefinition>(attachmentSchema.AutoloadProperties, (ICollection <PropertyDefinition>) this.fetchProperties);
                persistablePropertyBag           = this.attachmentProvider.CreateAttachment(prefetchProperties, attachmentToClone, itemToAttach, out attachmentNumber);
                attachmentPropertyBag            = new AttachmentPropertyBag(this.attachmentProvider, attachmentNumber, persistablePropertyBag, true);
                attachmentPropertyBag.ExTimeZone = this.ExTimeZone;
                if (type != null)
                {
                    int num = CoreAttachment.AttachmentTypeToAttachMethod(type.Value);
                    ((IDirectPropertyBag)attachmentPropertyBag).SetValue(InternalSchema.AttachMethod, num);
                }
                this.isDirty = true;
                this.IsClonedFromAnExistingAttachmentCollection = false;
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    if (attachmentPropertyBag != null)
                    {
                        attachmentPropertyBag.Dispose();
                        attachmentPropertyBag = null;
                    }
                    if (persistablePropertyBag != null)
                    {
                        persistablePropertyBag.Dispose();
                        persistablePropertyBag = null;
                    }
                }
            }
            return(attachmentPropertyBag);
        }
예제 #9
0
        private static Item InternalOpenEmbeddedMessageAndAttachment(AttachmentCollection attachments, ExTimeZone organizerTimeZone, ExDateTime userStartTime, ExDateTime userEndTime, out ItemAttachment itemAttachment, bool detectDuplicatedAttachment, out AttachmentId[] duplicatedAttachmentIds, ICollection <PropertyDefinition> properties)
        {
            itemAttachment          = null;
            duplicatedAttachmentIds = null;
            Item           item            = null;
            ItemAttachment itemAttachment2 = null;
            List <KeyValuePair <long, AttachmentHandle> > list = new List <KeyValuePair <long, AttachmentHandle> >();
            List <AttachmentId> list2       = null;
            ExDateTime          exDateTime  = ExTimeZone.UtcTimeZone.ConvertDateTime(userStartTime);
            ExDateTime          exDateTime2 = ExTimeZone.UtcTimeZone.ConvertDateTime(userEndTime);
            ExDateTime          exDateTime3 = organizerTimeZone.ConvertDateTime(exDateTime);
            ExDateTime          exDateTime4 = organizerTimeZone.ConvertDateTime(exDateTime2);

            exDateTime3 = new ExDateTime(ExTimeZone.UtcTimeZone, (DateTime)exDateTime3);
            exDateTime4 = new ExDateTime(ExTimeZone.UtcTimeZone, (DateTime)exDateTime4);
            if (properties == null)
            {
                properties = new PropertyDefinition[]
                {
                    InternalSchema.StartTime,
                    InternalSchema.EndTime
                };
            }
            else
            {
                properties = InternalSchema.Combine <PropertyDefinition>(properties, new PropertyDefinition[]
                {
                    InternalSchema.StartTime,
                    InternalSchema.EndTime
                });
            }
            CalendarItem calendarItem = attachments.ContainerItem as CalendarItem;
            List <RecurrenceManager.ExceptionSummary> list3;

            if (calendarItem != null)
            {
                if (calendarItem.ExceptionSummaryList == null)
                {
                    ExTraceGlobals.RecurrenceTracer.TraceDebug((long)calendarItem.GetHashCode(), "For calendar item, retrieve exception summary information by walking through all hidden attachements");
                    calendarItem.ExceptionSummaryList = RecurrenceManager.GetExceptionSumaryList(attachments);
                }
                list3 = calendarItem.ExceptionSummaryList;
            }
            else
            {
                ExTraceGlobals.RecurrenceTracer.TraceDebug((long)attachments.GetHashCode(), "No calendar item exists, retrieve exception summary information by walking through all hidden attachements");
                list3 = RecurrenceManager.GetExceptionSumaryList(attachments);
            }
            foreach (RecurrenceManager.ExceptionSummary exceptionSummary in list3)
            {
                ExDateTime utcStartTime = exceptionSummary.UtcStartTime;
                ExDateTime utcEndTime   = exceptionSummary.UtcEndTime;
                TimeSpan   timeSpan     = utcStartTime - exDateTime;
                utcEndTime - exDateTime2;
                if (Math.Abs((exDateTime3 - exDateTime4 - (utcStartTime - utcEndTime)).Ticks) < 1200000000L && Math.Abs(timeSpan.Ticks) <= 504000000000L)
                {
                    list.Add(new KeyValuePair <long, AttachmentHandle>(Math.Abs((utcStartTime - exDateTime3).Ticks), exceptionSummary.Handle));
                }
            }
            list.Sort(delegate(KeyValuePair <long, AttachmentHandle> left, KeyValuePair <long, AttachmentHandle> right)
            {
                if (left.Key == right.Key)
                {
                    return(0);
                }
                if (left.Key <= right.Key)
                {
                    return(-1);
                }
                return(1);
            });
            bool flag = false;

            try
            {
                foreach (KeyValuePair <long, AttachmentHandle> keyValuePair in list)
                {
                    ItemAttachment itemAttachment3 = (ItemAttachment)attachments.Open(keyValuePair.Value, new AttachmentType?(AttachmentType.EmbeddedMessage), null);
                    ExTraceGlobals.RecurrenceTracer.TraceDebug <ExDateTime, int>((long)keyValuePair.Value.GetHashCode(), "Open embedded message for StartTime: {0}, Probables queue length: {1}", userStartTime, list.Count);
                    if (itemAttachment3 != null)
                    {
                        Item item2 = null;
                        bool flag2 = true;
                        try
                        {
                            if (itemAttachment3.IsItemOpen)
                            {
                                ExTraceGlobals.RecurrenceTracer.TraceError((long)keyValuePair.Value.GetHashCode(), "Embedded message is in erroneous open state, which should be guaranteed by master");
                            }
                            else
                            {
                                item2 = itemAttachment3.GetItem(InternalSchema.Combine <PropertyDefinition>(MessageItemSchema.Instance.AutoloadProperties, properties));
                                TimeSpan timeSpan2 = item2.GetValueOrDefault <ExDateTime>(InternalSchema.MapiStartTime, ExDateTime.MinValue) - userStartTime;
                                TimeSpan timeSpan3 = item2.GetValueOrDefault <ExDateTime>(InternalSchema.MapiEndTime, ExDateTime.MinValue) - userEndTime;
                                if (timeSpan2.TotalMinutes < 1.0 && timeSpan2.TotalMinutes > -1.0 && timeSpan3.TotalMinutes < 1.0 && timeSpan3.TotalMinutes > -1.0)
                                {
                                    if (item == null)
                                    {
                                        flag2           = false;
                                        itemAttachment2 = itemAttachment3;
                                        item            = item2;
                                        if (!detectDuplicatedAttachment)
                                        {
                                            break;
                                        }
                                        list2 = new List <AttachmentId>();
                                    }
                                    else
                                    {
                                        ExTraceGlobals.RecurrenceTracer.TraceDebug <AttachmentId, ExDateTime>((long)keyValuePair.Value.GetHashCode(), "Detected duplicated attachment {0} for StartTime: {1}", itemAttachment3.Id, userStartTime);
                                        list2.Add(itemAttachment3.Id);
                                    }
                                }
                            }
                        }
                        finally
                        {
                            if (flag2)
                            {
                                Util.DisposeIfPresent(item2);
                                Util.DisposeIfPresent(itemAttachment3);
                            }
                        }
                    }
                }
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    Util.DisposeIfPresent(item);
                    Util.DisposeIfPresent(itemAttachment2);
                }
            }
            itemAttachment          = itemAttachment2;
            duplicatedAttachmentIds = ((list2 == null) ? null : list2.ToArray());
            return(item);
        }
        private HashSet <PropertyDefinition> SanitizePropertiesRequested(PropertyDefinition[] requestedItemProperties, ICollection <PropertyDefinition> requestedThreadProperties)
        {
            ICollection <PropertyDefinition> requestedProperties = InternalSchema.Combine <PropertyDefinition>(requestedItemProperties, requestedThreadProperties);

            return(this.conversationThreadTreeFactory.CalculatePropertyDefinitionsToBeLoaded(requestedProperties));
        }
예제 #11
0
        private static bool SearchByTopic(IXSOFactory xsoFactory, IMailboxSession session, ICorePropertyBag persistPropertyBag, ConversationIndexTrackingEx indexTrackingEx, out IStorePropertyBag foundPropertyBag, out bool didConversationIdMatch, out bool didReferencesMatch, params PropertyDefinition[] propsToReturn)
        {
            foundPropertyBag       = null;
            didConversationIdMatch = false;
            didReferencesMatch     = false;
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullArgument(persistPropertyBag, "persistPropertyBag");
            Util.ThrowOnNullArgument(propsToReturn, "propsToReturn");
            ICollection <PropertyDefinition> properties = InternalSchema.Combine <PropertyDefinition>(propsToReturn, new PropertyDefinition[]
            {
                ItemSchema.ConversationTopicHash
            });
            string            incomingConversationTopic = persistPropertyBag.GetValueOrDefault <string>(ItemSchema.ConversationTopic);
            ConversationIndex conversationIndex;
            bool           isValidIncomingIndex   = ConversationIndex.TryCreate(persistPropertyBag.TryGetProperty(ItemSchema.ConversationIndex) as byte[], out conversationIndex);
            ConversationId incomingConversationId = isValidIncomingIndex ? ConversationId.Create(conversationIndex.Guid) : null;

            if (incomingConversationTopic == null)
            {
                return(false);
            }
            bool              didConversationIdMatchLocal   = false;
            bool              didReferencesMatchLocal       = false;
            int               incomingConversationTopicHash = (int)AllItemsFolderHelper.GetHashValue(incomingConversationTopic);
            Stopwatch         stopwatch        = Stopwatch.StartNew();
            IStorePropertyBag storePropertyBag = xsoFactory.RunQueryOnAllItemsFolder <IStorePropertyBag>(session, AllItemsFolderHelper.SupportedSortBy.ConversationTopicHash, incomingConversationTopicHash, null, delegate(QueryResult queryResult)
            {
                bool flag = queryResult.SeekToCondition(SeekReference.OriginBeginning, new ComparisonFilter(ComparisonOperator.Equal, ItemSchema.ConversationTopicHash, incomingConversationTopicHash));
                if (flag)
                {
                    IStorePropertyBag storePropertyBag2 = null;
                    for (int i = 0; i < 5; i++)
                    {
                        IStorePropertyBag[] propertyBags = queryResult.GetPropertyBags(1);
                        if (propertyBags.Length != 1)
                        {
                            break;
                        }
                        int?num = propertyBags[0].TryGetProperty(ItemSchema.ConversationTopicHash) as int?;
                        if (num == null || num.Value != incomingConversationTopicHash)
                        {
                            break;
                        }
                        string foundTopic = propertyBags[0].TryGetProperty(ItemSchema.ConversationTopic) as string;
                        if (ConversationIndex.CompareTopics(incomingConversationTopic, foundTopic))
                        {
                            if (storePropertyBag2 == null)
                            {
                                storePropertyBag2 = propertyBags[0];
                            }
                            ConversationIndex conversationIndex2;
                            bool flag2 = ConversationIndex.TryCreate(propertyBags[0].TryGetProperty(ItemSchema.ConversationIndex) as byte[], out conversationIndex2);
                            if (flag2)
                            {
                                if (isValidIncomingIndex)
                                {
                                    ConversationId conversationId = ConversationId.Create(conversationIndex2.Guid);
                                    if (conversationId.Equals(incomingConversationId))
                                    {
                                        didConversationIdMatchLocal = true;
                                        return(propertyBags[0]);
                                    }
                                }
                                else if (AggregationByItemClassReferencesSubjectProcessor.MatchMessageIdWithReferences(persistPropertyBag, propertyBags[0]))
                                {
                                    didReferencesMatchLocal = true;
                                    return(propertyBags[0]);
                                }
                            }
                        }
                        if (!queryResult.SeekToCondition(SeekReference.OriginCurrent, new ComparisonFilter(ComparisonOperator.Equal, ItemSchema.ConversationTopicHash, incomingConversationTopicHash)))
                        {
                            break;
                        }
                    }
                    if (storePropertyBag2 != null)
                    {
                        return(storePropertyBag2);
                    }
                }
                return(null);
            }, properties);

            stopwatch.Stop();
            if (indexTrackingEx != null)
            {
                indexTrackingEx.Trace("SBT", stopwatch.ElapsedMilliseconds.ToString());
            }
            if (storePropertyBag != null)
            {
                foundPropertyBag       = storePropertyBag;
                didConversationIdMatch = didConversationIdMatchLocal;
                didReferencesMatch     = didReferencesMatchLocal;
                return(true);
            }
            return(false);
        }
예제 #12
0
        private static bool SearchByReferences(IXSOFactory xsoFactory, IMailboxSession session, ICorePropertyBag persistPropertyBag, ConversationIndexTrackingEx indexTrackingEx, bool searchByDupedMessage, out IStorePropertyBag foundPropertyBag, params PropertyDefinition[] propsToReturn)
        {
            foundPropertyBag = null;
            Util.ThrowOnNullArgument(propsToReturn, "propsToReturn");
            Util.ThrowOnNullArgument(session, "session");
            Util.ThrowOnNullArgument(persistPropertyBag, "persistPropertyBag");
            List <string> internetIds = new List <string>();

            if (searchByDupedMessage)
            {
                string valueOrDefault = persistPropertyBag.GetValueOrDefault <string>(ItemSchema.InternetMessageId, string.Empty);
                if (!string.IsNullOrEmpty(valueOrDefault))
                {
                    internetIds.Add(valueOrDefault);
                }
            }
            string valueOrDefault2 = persistPropertyBag.GetValueOrDefault <string>(ItemSchema.InReplyTo, string.Empty);

            if (!string.IsNullOrEmpty(valueOrDefault2))
            {
                internetIds.Add(valueOrDefault2);
            }
            string valueOrDefault3 = persistPropertyBag.GetValueOrDefault <string>(ItemSchema.InternetReferences, string.Empty);

            if (!string.IsNullOrEmpty(valueOrDefault3))
            {
                string[] array = valueOrDefault3.Split(AggregationByItemClassReferencesSubjectProcessor.ReferencesSeparators, StringSplitOptions.RemoveEmptyEntries);
                if (array != null && array.Length > 0)
                {
                    int num = array.Length - 1;
                    for (int i = num; i >= 0; i--)
                    {
                        if (!string.IsNullOrEmpty(array[i]) && !internetIds.Contains(array[i]))
                        {
                            internetIds.Add(array[i]);
                            if (internetIds.Count >= 50)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            if (internetIds.Count > 0)
            {
                ICollection <PropertyDefinition> properties = InternalSchema.Combine <PropertyDefinition>(propsToReturn, new PropertyDefinition[]
                {
                    ItemSchema.InternetMessageIdHash
                });
                Stopwatch         stopwatch        = Stopwatch.StartNew();
                IStorePropertyBag storePropertyBag = xsoFactory.RunQueryOnAllItemsFolder <IStorePropertyBag>(session, AllItemsFolderHelper.SupportedSortBy.InternetMessageIdHash, delegate(QueryResult queryResult)
                {
                    using (List <string> .Enumerator enumerator = internetIds.GetEnumerator())
                    {
                        IL_A6:
                        while (enumerator.MoveNext())
                        {
                            string text   = enumerator.Current;
                            int hashValue = (int)AllItemsFolderHelper.GetHashValue(text);
                            if (queryResult.SeekToCondition(SeekReference.OriginBeginning, new ComparisonFilter(ComparisonOperator.Equal, ItemSchema.InternetMessageIdHash, hashValue)))
                            {
                                IStorePropertyBag[] propertyBags;
                                string text2;
                                do
                                {
                                    propertyBags = queryResult.GetPropertyBags(1);
                                    if (propertyBags == null || propertyBags.Length != 1)
                                    {
                                        goto IL_A6;
                                    }
                                    int?num2 = propertyBags[0].TryGetProperty(ItemSchema.InternetMessageIdHash) as int?;
                                    if (num2 == null || num2.Value != hashValue)
                                    {
                                        goto IL_A6;
                                    }
                                    text2 = (propertyBags[0].TryGetProperty(ItemSchema.InternetMessageId) as string);
                                }while (string.IsNullOrEmpty(text2) || !string.Equals(text, text2, StringComparison.OrdinalIgnoreCase));
                                return(propertyBags[0]);
                            }
                        }
                    }
                    return(null);
                }, properties);
                stopwatch.Stop();
                if (indexTrackingEx != null)
                {
                    indexTrackingEx.Trace("SBMID", stopwatch.ElapsedMilliseconds.ToString());
                }
                if (storePropertyBag != null)
                {
                    foundPropertyBag = storePropertyBag;
                    return(true);
                }
            }
            return(false);
        }
 internal ICollection <PropertyDefinition> GetAttachmentLoadList(ICollection <PropertyDefinition> prefetchProperties, Schema attachmentSchema)
 {
     this.CheckDisposed(null);
     prefetchProperties = InternalSchema.Combine <PropertyDefinition>((ICollection <PropertyDefinition>) this.fetchProperties, prefetchProperties);
     return(InternalSchema.Combine <PropertyDefinition>(attachmentSchema.AutoloadProperties, prefetchProperties));
 }
예제 #14
0
        public ICoreItem OpenAttachedItem(ICollection <PropertyDefinition> propertiesToLoad, AttachmentPropertyBag attachmentBag, bool isNew)
        {
            MapiMessage            mapiMessage            = null;
            PersistablePropertyBag persistablePropertyBag = null;
            CoreItem      coreItem      = null;
            bool          flag          = false;
            StoreObjectId storeObjectId = null;

            byte[]    array = null;
            ICoreItem result;

            try
            {
                StoreObjectPropertyBag storeObjectPropertyBag = (StoreObjectPropertyBag)attachmentBag.PersistablePropertyBag;
                MapiAttach             mapiAttach             = (MapiAttach)storeObjectPropertyBag.MapiProp;
                StoreSession           session           = this.AttachmentCollection.ContainerItem.Session;
                OpenPropertyFlags      openPropertyFlags = isNew ? OpenPropertyFlags.Create : (this.AttachmentCollection.IsReadOnly ? OpenPropertyFlags.BestAccess : OpenPropertyFlags.BestAccess);
                openPropertyFlags |= OpenPropertyFlags.DeferredErrors;
                string text   = storeObjectPropertyBag.TryGetProperty(InternalSchema.ItemClass) as string;
                Schema schema = (text != null) ? ObjectClass.GetSchema(text) : MessageItemSchema.Instance;
                propertiesToLoad = InternalSchema.Combine <PropertyDefinition>(schema.AutoloadProperties, propertiesToLoad);
                StoreSession session2 = this.AttachmentCollection.ContainerItem.Session;
                bool         flag2    = false;
                try
                {
                    if (session2 != null)
                    {
                        session2.BeginMapiCall();
                        session2.BeginServerHealthCall();
                        flag2 = true;
                    }
                    if (StorageGlobals.MapiTestHookBeforeCall != null)
                    {
                        StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                    }
                    mapiMessage = mapiAttach.OpenEmbeddedMessage(openPropertyFlags);
                }
                catch (MapiPermanentException ex)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenEmbeddedMessage, ex, session2, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("MapiAttachmentProvider::OpenAttachedItem", new object[0]),
                        ex
                    });
                }
                catch (MapiRetryableException ex2)
                {
                    throw StorageGlobals.TranslateMapiException(ServerStrings.MapiCannotOpenEmbeddedMessage, ex2, session2, this, "{0}. MapiException = {1}.", new object[]
                    {
                        string.Format("MapiAttachmentProvider::OpenAttachedItem", new object[0]),
                        ex2
                    });
                }
                finally
                {
                    try
                    {
                        if (session2 != null)
                        {
                            session2.EndMapiCall();
                            if (flag2)
                            {
                                session2.EndServerHealthCall();
                            }
                        }
                    }
                    finally
                    {
                        if (StorageGlobals.MapiTestHookAfterCall != null)
                        {
                            StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                        }
                    }
                }
                persistablePropertyBag = new StoreObjectPropertyBag(session, mapiMessage, propertiesToLoad);
                if (!isNew)
                {
                    StoreObjectType storeObjectType = ItemBuilder.ReadStoreObjectTypeFromPropertyBag(persistablePropertyBag);
                    ItemCreateInfo  itemCreateInfo  = ItemCreateInfo.GetItemCreateInfo(storeObjectType);
                    propertiesToLoad = InternalSchema.Combine <PropertyDefinition>(itemCreateInfo.Schema.AutoloadProperties, propertiesToLoad);
                    if (this.AttachmentCollection.IsReadOnly)
                    {
                        StoreId.SplitStoreObjectIdAndChangeKey(StoreObjectId.DummyId, out storeObjectId, out array);
                    }
                    persistablePropertyBag = new AcrPropertyBag(persistablePropertyBag, itemCreateInfo.AcrProfile, storeObjectId, new RetryBagFactory(session), array);
                }
                coreItem = new CoreItem(session, persistablePropertyBag, storeObjectId, array, isNew ? Origin.New : Origin.Existing, ItemLevel.Attached, propertiesToLoad, ItemBindOption.None);
                if (text != null && isNew)
                {
                    coreItem.PropertyBag[InternalSchema.ItemClass] = text;
                }
                flag   = true;
                result = coreItem;
            }
            finally
            {
                if (!flag)
                {
                    if (coreItem != null)
                    {
                        coreItem.Dispose();
                        coreItem = null;
                    }
                    if (persistablePropertyBag != null)
                    {
                        persistablePropertyBag.Dispose();
                        persistablePropertyBag = null;
                    }
                    if (mapiMessage != null)
                    {
                        mapiMessage.Dispose();
                        mapiMessage = null;
                    }
                }
            }
            return(result);
        }
예제 #15
0
 public new static ContactsFolder Bind(StoreSession session, StoreId folderId, ICollection <PropertyDefinition> prefetchProperties)
 {
     prefetchProperties = InternalSchema.Combine <PropertyDefinition>(FolderSchema.Instance.AutoloadProperties, prefetchProperties);
     return(Folder.InternalBind <ContactsFolder>(session, folderId, prefetchProperties));
 }
예제 #16
0
        internal static MailboxStoreObject Bind(StoreSession session, MapiStore mapiStore, ICollection <PropertyDefinition> requestedProperties, bool getMappingSignature, bool overridePropertyList)
        {
            ICollection <PropertyDefinition> collection = InternalSchema.Combine <PropertyDefinition>(overridePropertyList ? new PropertyTagPropertyDefinition[]
            {
                MailboxSchema.MailboxType,
                MailboxSchema.MailboxTypeDetail
            } : MailboxSchema.Instance.AutoloadProperties, requestedProperties);
            PersistablePropertyBag persistablePropertyBag = null;
            CoreMailboxObject      coreMailboxObject      = null;
            MailboxStoreObject     mailboxStoreObject     = null;
            bool flag = false;
            MailboxStoreObject result;

            try
            {
                byte[] array = null;
                if (getMappingSignature)
                {
                    object thisObject = null;
                    bool   flag2      = false;
                    try
                    {
                        if (session != null)
                        {
                            session.BeginMapiCall();
                            session.BeginServerHealthCall();
                            flag2 = true;
                        }
                        if (StorageGlobals.MapiTestHookBeforeCall != null)
                        {
                            StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod());
                        }
                        using (MapiFolder rootFolder = mapiStore.GetRootFolder())
                        {
                            array = (rootFolder.GetProp(PropTag.MappingSignature).Value as byte[]);
                        }
                    }
                    catch (MapiPermanentException ex)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.StoreOperationFailed, ex, session, thisObject, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("Failed to get mapping signature.", new object[0]),
                            ex
                        });
                    }
                    catch (MapiRetryableException ex2)
                    {
                        throw StorageGlobals.TranslateMapiException(ServerStrings.StoreOperationFailed, ex2, session, thisObject, "{0}. MapiException = {1}.", new object[]
                        {
                            string.Format("Failed to get mapping signature.", new object[0]),
                            ex2
                        });
                    }
                    finally
                    {
                        try
                        {
                            if (session != null)
                            {
                                session.EndMapiCall();
                                if (flag2)
                                {
                                    session.EndServerHealthCall();
                                }
                            }
                        }
                        finally
                        {
                            if (StorageGlobals.MapiTestHookAfterCall != null)
                            {
                                StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod());
                            }
                        }
                    }
                }
                if (array != null)
                {
                    session.MappingSignature = Convert.ToBase64String(array);
                }
                persistablePropertyBag = new StoreObjectPropertyBag(session, mapiStore, collection);
                coreMailboxObject      = new CoreMailboxObject(session, persistablePropertyBag, null, null, collection);
                mailboxStoreObject     = new MailboxStoreObject(coreMailboxObject);
                flag   = true;
                result = mailboxStoreObject;
            }
            finally
            {
                if (!flag)
                {
                    if (mailboxStoreObject != null)
                    {
                        mailboxStoreObject.Dispose();
                        mailboxStoreObject = null;
                    }
                    if (coreMailboxObject != null)
                    {
                        coreMailboxObject.Dispose();
                        coreMailboxObject = null;
                    }
                    if (persistablePropertyBag != null)
                    {
                        persistablePropertyBag.Dispose();
                        persistablePropertyBag = null;
                    }
                }
            }
            return(result);
        }
예제 #17
0
 public new static SearchFolder Bind(StoreSession session, StoreId folderId, ICollection <PropertyDefinition> propsToReturn)
 {
     propsToReturn = InternalSchema.Combine <PropertyDefinition>(FolderSchema.Instance.AutoloadProperties, propsToReturn);
     return(Folder.InternalBind <SearchFolder>(session, folderId, propsToReturn));
 }
예제 #18
0
        internal static ICollection <PropertyDefinition> GetPropertiesToLoad(ItemBindOption itemBindOption, Schema schema, ICollection <PropertyDefinition> requestedProperties)
        {
            ICollection <PropertyDefinition> first = ((itemBindOption & ItemBindOption.LoadRequiredPropertiesOnly) == ItemBindOption.LoadRequiredPropertiesOnly) ? schema.RequiredAutoloadProperties : schema.AutoloadProperties;

            return(InternalSchema.Combine <PropertyDefinition>(first, requestedProperties));
        }