Exemplo n.º 1
0
        private void CalculateBasedOnMessageWithSameInternetMessageId(ICorePropertyBag message, IStorePropertyBag referenceItem, out ConversationIndex.FixupStage stage, out ConversationIndex newIndex)
        {
            string text = message.TryGetProperty(ItemSchema.NormalizedSubject) as string;

            newIndex = ConversationIndex.Empty;
            stage    = ConversationIndex.FixupStage.Unknown;
            ConversationIndex conversationIndex;
            bool flag           = ConversationIndex.TryCreate(referenceItem.TryGetProperty(ItemSchema.ConversationIndex) as byte[], out conversationIndex);
            bool valueOrDefault = referenceItem.GetValueOrDefault <bool>(InternalSchema.IsDraft, false);

            if (flag && !valueOrDefault)
            {
                string value = referenceItem.TryGetProperty(ItemSchema.ConversationTopic) as string;
                if (string.IsNullOrEmpty(value) || (!string.IsNullOrEmpty(text) && text.Equals(value, StringComparison.OrdinalIgnoreCase)))
                {
                    bool?flag2 = referenceItem.TryGetProperty(ItemSchema.ConversationIndexTracking) as bool?;
                    stage    = ((flag2 == null || !flag2.Value) ? ConversationIndex.FixupStage.L1 : ConversationIndex.FixupStage.H13);
                    newIndex = conversationIndex;
                }
            }
        }
Exemplo n.º 2
0
        internal static IDictionary <string, string> ExtractDeliveryDetails(StoreSession session, Item item)
        {
            IDictionary <string, string> customProperties = null;

            ActivityLogHelper.CatchNonFatalExceptions(delegate
            {
                MessageItem messageItem = item as MessageItem;
                if (messageItem == null)
                {
                    return;
                }
                bool flag    = false;
                bool flag2   = false;
                string value = null;
                ConversationId conversationId = null;
                string value2 = null;
                bool?flag3    = null;
                if (((IDirectPropertyBag)messageItem.PropertyBag).IsLoaded(InternalSchema.InferenceClassificationResult))
                {
                    InferenceClassificationResult?valueAsNullable = messageItem.GetValueAsNullable <InferenceClassificationResult>(InternalSchema.InferenceClassificationResult);
                    flag3 = new bool?(valueAsNullable != null && valueAsNullable.Value.HasFlag(InferenceClassificationResult.IsClutterFinal));
                }
                string value3 = string.Empty;
                if (flag3 != null)
                {
                    value3 = (flag3.Value ? bool.TrueString : bool.FalseString);
                }
                bool?flag4    = new bool?(messageItem.IsGroupEscalationMessage);
                string value4 = string.Empty;
                if (flag4 != null)
                {
                    value4 = (flag4.Value ? bool.TrueString : bool.FalseString);
                }
                StoreObjectId parentId = messageItem.ParentId;
                DefaultFolderType defaultFolderType = DefaultFolderType.None;
                bool flag5 = false;
                if (parentId != null)
                {
                    StoreObjectId defaultFolderId = session.GetDefaultFolderId(DefaultFolderType.Inbox);
                    flag = parentId.Equals(defaultFolderId);
                    StoreObjectId defaultFolderId2 = session.GetDefaultFolderId(DefaultFolderType.Clutter);
                    flag2 = (defaultFolderId2 != null && parentId.Equals(defaultFolderId2));
                    MailboxSession mailboxSession = session as MailboxSession;
                    if (mailboxSession != null)
                    {
                        defaultFolderType = mailboxSession.IsDefaultFolderType(parentId);
                        flag5             = true;
                    }
                }
                value = messageItem.InternetMessageId;
                ConversationIndex index;
                if (ConversationIndex.TryCreate(messageItem.ConversationIndex, out index))
                {
                    conversationId = ConversationId.Create(index);
                }
                string value5 = string.Empty;
                if (((IDirectPropertyBag)messageItem.PropertyBag).IsLoaded(InternalSchema.InferenceMessageIdentifier))
                {
                    value5 = messageItem.GetValueAsNullable <Guid>(InternalSchema.InferenceMessageIdentifier).ToString();
                }
                if (messageItem.Sender != null)
                {
                    value2 = messageItem.Sender.SmtpEmailAddress;
                }
                List <string> list  = null;
                List <string> list2 = null;
                foreach (Recipient recipient in messageItem.Recipients)
                {
                    if (recipient.Participant != null)
                    {
                        if (recipient.IsDistributionList() == true)
                        {
                            if (list == null)
                            {
                                list = new List <string>(2);
                            }
                            list.Add(recipient.SmtpAddress());
                        }
                        else if (recipient.IsGroupMailbox() == true)
                        {
                            if (list2 == null)
                            {
                                list2 = new List <string>(2);
                            }
                            list2.Add(recipient.SmtpAddress());
                        }
                    }
                }
                Dictionary <string, string> dictionary = new Dictionary <string, string>
                {
                    {
                        "IsClutter",
                        value3
                    },
                    {
                        "DeliveredToInbox",
                        flag ? bool.TrueString : bool.FalseString
                    },
                    {
                        "DeliveredToClutter",
                        flag2 ? bool.TrueString : bool.FalseString
                    },
                    {
                        "IsGroupEscalationMessage",
                        value4
                    },
                    {
                        "InternetMessageId",
                        value
                    },
                    {
                        "ConversationId",
                        (conversationId == null) ? string.Empty : conversationId.ToString()
                    },
                    {
                        "MessageGuid",
                        value5
                    },
                    {
                        "SenderSmtpAddress",
                        value2
                    }
                };
                if (list != null && list.Count > 0)
                {
                    dictionary.Add("DLRecipients", string.Join(";", list));
                }
                if (list2 != null)
                {
                    dictionary.Add("GMRecipients", string.Join(";", list2));
                }
                if (flag5)
                {
                    Dictionary <string, string> dictionary2 = dictionary;
                    string key = "DeliveredFolderType";
                    int num    = (int)defaultFolderType;
                    dictionary2.Add(key, num.ToString());
                    if (defaultFolderType == DefaultFolderType.None && parentId != null)
                    {
                        dictionary.Add("DeliveredFolderId", parentId.ToString());
                    }
                }
                customProperties = dictionary;
            }, null);
            return(customProperties);
        }
Exemplo n.º 3
0
        public bool FirstTimeSync(Dictionary <ISyncItemId, FolderSync.ClientStateInformation> clientManifest, FirstTimeSyncWatermark minWatermark, QueryFilter filter, int numOperations, Dictionary <ISyncItemId, ServerManifestEntry> newServerManifest)
        {
            ExDateTime receivedDateUtc = minWatermark.ReceivedDateUtc;

            if (numOperations < 0 && numOperations != -1)
            {
                throw new ArgumentException("numOperations is not valid, value = " + numOperations);
            }
            AirSyncDiagnostics.TraceInfo <int, QueryFilter>(ExTraceGlobals.SyncProcessTracer, this, "FirstTimeSyncProvider.FirstTimeSync. numOperations = {0} filter = {1}", numOperations, filter);
            ExDateTime?            filterTypeBoundary     = this.GetFilterTypeBoundary(filter);
            MailboxSyncPropertyBag mailboxSyncPropertyBag = new MailboxSyncPropertyBag(FirstTimeSyncProvider.newQueryProps);

            if (filter != null)
            {
                mailboxSyncPropertyBag.AddColumnsFromFilter(filter);
            }
            int num;

            using (QueryResult positionedQueryResult = this.GetPositionedQueryResult(minWatermark, filterTypeBoundary, mailboxSyncPropertyBag.Columns, out num))
            {
                bool flag = false;
                while (!flag)
                {
                    if (newServerManifest.Count >= numOperations && numOperations > 0)
                    {
                        return(!flag);
                    }
                    int num2;
                    if (numOperations == -1)
                    {
                        num2 = 10000;
                    }
                    else
                    {
                        int num3 = numOperations - newServerManifest.Count;
                        num2 = num3 + 1;
                    }
                    if (num2 < 0)
                    {
                        throw new InvalidOperationException(ServerStrings.ExNumberOfRowsToFetchInvalid(num2.ToString()));
                    }
                    bool flag2 = false;
                    if (num >= 0 && num < num2)
                    {
                        AirSyncDiagnostics.TraceDebug <int, int>(ExTraceGlobals.SyncProcessTracer, this, "[FirstTimeSyncProvier.FirstTimeSync] Limiting rows to fetch based on end filter. Original value: {0}, Filter Based Value: {1}", num2, num + 1);
                        num2  = num;
                        flag2 = true;
                    }
                    if (num2 <= 0)
                    {
                        AirSyncDiagnostics.TraceDebug(ExTraceGlobals.SyncProcessTracer, this, "[FirstTimeSyncProvider.FirstTimeSync] No more rows to fetch. Bailing out.");
                        flag = true;
                        return(false);
                    }
                    AirSyncDiagnostics.TraceInfo <int>(ExTraceGlobals.SyncProcessTracer, this, "FirstTimeSyncProvider.FirstTimeSync. Asking queryResult for {0} rows", num2);
                    IStorePropertyBag[] propertyBags = positionedQueryResult.GetPropertyBags(num2);
                    AirSyncDiagnostics.TraceInfo <int>(ExTraceGlobals.SyncProcessTracer, this, "FirstTimeSyncProvider.FirstTimeSync. Retrieved {0} rows", propertyBags.Length);
                    if (num > -1)
                    {
                        num -= propertyBags.Length;
                    }
                    flag = (propertyBags.Length == 0 || (flag2 && num == 0));
                    if (propertyBags.Length < num2)
                    {
                        flag |= (positionedQueryResult.CurrentRow == positionedQueryResult.EstimatedRowCount);
                    }
                    for (int i = 0; i < propertyBags.Length; i++)
                    {
                        VersionedId       versionedId      = null;
                        IStorePropertyBag storePropertyBag = propertyBags[i];
                        try
                        {
                            if (numOperations != -1 && newServerManifest.Count >= numOperations)
                            {
                                return(true);
                            }
                            if (!this.TryGetPropertyFromBag <VersionedId>(storePropertyBag, ItemSchema.Id, out versionedId))
                            {
                                AirSyncDiagnostics.TraceError(ExTraceGlobals.SyncProcessTracer, this, "[FirstTimeSyncProvider.FirstTimeSync] Could not get versioned Id from property bag.  Skipping item.");
                            }
                            else
                            {
                                ExDateTime exDateTime;
                                bool       flag3 = this.TryGetPropertyFromBag <ExDateTime>(storePropertyBag, ItemSchema.ReceivedTime, out exDateTime);
                                if (!flag3 && filterTypeBoundary != null)
                                {
                                    AirSyncDiagnostics.TraceDebug <string, string>(ExTraceGlobals.SyncProcessTracer, this, "FirstTimeSyncProvider.FirstTimeSync. Found item with missing/corrupt DateTimeReceived. Bailing out of FirstTimeSync mode. Mailbox: {0} ItemId: {1}", this.folder.Session.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString(), versionedId.ObjectId.ToBase64String());
                                    flag = true;
                                    return(false);
                                }
                                ExDateTime value = exDateTime;
                                if (!flag3 && !this.TryGetPropertyFromBag <ExDateTime>(storePropertyBag, StoreObjectSchema.CreationTime, out value))
                                {
                                    AirSyncDiagnostics.TraceDebug <string, string>(ExTraceGlobals.SyncProcessTracer, this, "FirstTimeSyncProvider.FirstTimeSync. Found item with missing/corrupt CreationDate. Will use DateTime.MinValue instead.  Mailbox: {0}, ItemId: {1}", this.folder.Session.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString(), versionedId.ObjectId.ToBase64String());
                                }
                                if (filterTypeBoundary != null && exDateTime < filterTypeBoundary)
                                {
                                    AirSyncDiagnostics.TraceDebug <ExDateTime>(ExTraceGlobals.SyncProcessTracer, this, "[FirstTimeSyncProvider.FirstTimeSync]  Passed our sync cutoff date of {0}. All rows fetched.", filterTypeBoundary.Value);
                                    flag = true;
                                    return(false);
                                }
                                int num4;
                                if (!this.TryGetPropertyFromBag <int>(storePropertyBag, ItemSchema.ArticleId, out num4))
                                {
                                    AirSyncDiagnostics.TraceDebug <VersionedId>(ExTraceGlobals.SyncProcessTracer, this, "[FirstTimeSyncProvider.FirstTimeSync] Unable to get articleId from property bag item. Id: {0}", versionedId);
                                }
                                else
                                {
                                    ISyncItemId syncItemId = MailboxSyncItemId.CreateForNewItem(versionedId.ObjectId);
                                    FolderSync.ClientStateInformation clientStateInformation;
                                    if (clientManifest != null && clientManifest.TryGetValue(syncItemId, out clientStateInformation) && clientStateInformation.ClientHasItem)
                                    {
                                        AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.SyncProcessTracer, this, "[FirstTimeSyncProvider.FirstTimeSync] Skipping item {0} because it is already in client manifest.", syncItemId.NativeId.ToString());
                                        minWatermark.ChangeNumber    = num4;
                                        minWatermark.ReceivedDateUtc = exDateTime;
                                    }
                                    else if (filter != null && !EvaluatableFilter.Evaluate(filter, storePropertyBag))
                                    {
                                        AirSyncDiagnostics.TraceInfo <StoreObjectId, ExDateTime, int>(ExTraceGlobals.SyncTracer, this, "[FirstTimeSyncProvider.FirstTimeSync] Dropping item '{0}' because it failed to match our filter. ReceivedDateUtc: {1}, ChangeNumber: {2}", versionedId.ObjectId, exDateTime, num4);
                                        minWatermark.ChangeNumber    = num4;
                                        minWatermark.ReceivedDateUtc = exDateTime;
                                    }
                                    else
                                    {
                                        bool read;
                                        if (!this.TryGetPropertyFromBag <bool>(storePropertyBag, MessageItemSchema.IsRead, out read))
                                        {
                                            AirSyncDiagnostics.TraceDebug(ExTraceGlobals.SyncProcessTracer, this, "[FirstTimeSyncProvider.FirstTimeSync] Unabled to get read flag from property bag. Default to false.");
                                            read = false;
                                        }
                                        MailboxSyncWatermark mailboxSyncWatermark = MailboxSyncWatermark.Create();
                                        mailboxSyncWatermark.UpdateWithChangeNumber(num4, read);
                                        AirSyncDiagnostics.TraceInfo(ExTraceGlobals.SyncTracer, this, "FirstTimeSyncProvider.FirstTimeSync. Adding Sync'd item {0} to manifest", new object[]
                                        {
                                            syncItemId.NativeId
                                        });
                                        ServerManifestEntry serverManifestEntry = base.CreateItemChangeManifestEntry(syncItemId, mailboxSyncWatermark);
                                        ConversationId      conversationId      = null;
                                        if (this.TryGetPropertyFromBag <ConversationId>(storePropertyBag, ItemSchema.ConversationId, out conversationId))
                                        {
                                            serverManifestEntry.ConversationId = conversationId;
                                        }
                                        byte[]            bytes;
                                        ConversationIndex index;
                                        if (this.TryGetPropertyFromBag <byte[]>(storePropertyBag, ItemSchema.ConversationIndex, out bytes) && ConversationIndex.TryCreate(bytes, out index) && index != ConversationIndex.Empty && index.Components != null && index.Components.Count == 1)
                                        {
                                            AirSyncDiagnostics.TraceInfo(ExTraceGlobals.SyncTracer, this, "FirstTimeSyncProvider.FirstTimeSync. First message in conversation.", new object[]
                                            {
                                                syncItemId.NativeId
                                            });
                                            serverManifestEntry.FirstMessageInConversation = true;
                                        }
                                        serverManifestEntry.FilterDate = new ExDateTime?(value);
                                        string text;
                                        if (this.TryGetPropertyFromBag <string>(storePropertyBag, StoreObjectSchema.ItemClass, out text))
                                        {
                                            serverManifestEntry.MessageClass = (storePropertyBag[StoreObjectSchema.ItemClass] as string);
                                        }
                                        newServerManifest[serverManifestEntry.Id] = serverManifestEntry;
                                        minWatermark.ChangeNumber    = num4;
                                        minWatermark.ReceivedDateUtc = exDateTime;
                                    }
                                }
                            }
                        }
                        catch (Exception arg)
                        {
                            AirSyncDiagnostics.TraceError <string, Exception>(ExTraceGlobals.SyncTracer, this, "FirstTimeSyncProvider.FirstTimeSync. Caught exception processing item: {0}. Exception: {1}", (versionedId == null) ? "<NULL>" : versionedId.ToBase64String(), arg);
                            throw;
                        }
                    }
                }
            }
            return(false);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public void Aggregate(ICorePropertyBag item, bool shouldSearchForDuplicatedMessage, out IStorePropertyBag parentItem, out ConversationIndex newIndex, out ConversationIndex.FixupStage stage)
        {
            newIndex = ConversationIndex.Empty;
            stage    = ConversationIndex.FixupStage.Unknown;
            string valueOrDefault = item.GetValueOrDefault <string>(InternalSchema.ItemClass, string.Empty);

            parentItem = null;
            if (!string.IsNullOrEmpty(valueOrDefault))
            {
                if (ObjectClass.IsMeetingMessage(valueOrDefault))
                {
                    if (AggregationByItemClassReferencesSubjectProcessor.FixupMeetingMessage(this.xsoFactory, this.session, new AggregationByItemClassReferencesSubjectProcessor.PropertyDefinitionListConstructorDelegate(this.GetSearchPropertyDefinitions), item, ref newIndex, ref stage, out parentItem))
                    {
                        return;
                    }
                }
                else if (ObjectClass.IsSmsMessage(valueOrDefault))
                {
                    AggregationBySmsItemClassProcessor aggregationBySmsItemClassProcessor = new AggregationBySmsItemClassProcessor(this.xsoFactory, this.session, this.indexTrackingEx);
                    aggregationBySmsItemClassProcessor.Aggregate(item, out newIndex, out stage);
                    return;
                }
            }
            ConversationIndex conversationIndex;
            bool flag = ConversationIndex.TryCreate(item.TryGetProperty(ItemSchema.ConversationIndex) as byte[], out conversationIndex);

            if (this.indexTrackingEx != null)
            {
                if (flag)
                {
                    this.indexTrackingEx.Trace(conversationIndex);
                }
                else
                {
                    this.indexTrackingEx.Trace("II", "<invalid>");
                }
            }
            if (AggregationByItemClassReferencesSubjectProcessor.SearchByReferences(this.xsoFactory, this.session, item, this.indexTrackingEx, shouldSearchForDuplicatedMessage, out parentItem, this.GetSearchPropertyDefinitions(null)))
            {
                bool flag2 = false;
                if (shouldSearchForDuplicatedMessage)
                {
                    string a    = item.TryGetProperty(ItemSchema.InternetMessageId) as string;
                    string text = parentItem.TryGetProperty(ItemSchema.InternetMessageId) as string;
                    flag2 = (!string.IsNullOrEmpty(text) && string.Equals(a, text, StringComparison.OrdinalIgnoreCase));
                }
                if (flag2)
                {
                    this.CalculateBasedOnMessageWithSameInternetMessageId(item, parentItem, out stage, out newIndex);
                }
                else
                {
                    this.CalculateBasedOnReferenceMessage(item, parentItem, out stage, out newIndex);
                }
            }
            string text2 = item.TryGetProperty(ItemSchema.NormalizedSubject) as string;

            if (stage == ConversationIndex.FixupStage.Unknown)
            {
                if (string.IsNullOrEmpty(item.GetValueOrDefault <string>(ItemSchema.SubjectPrefix)) && flag)
                {
                    if (conversationIndex.Components.Count > 1)
                    {
                        byte[]    incomingConversationIdBytes = ConversationId.Create(conversationIndex.Guid).GetBytes();
                        int       conversationIdHash          = (int)AllItemsFolderHelper.GetHashValue(incomingConversationIdBytes);
                        Stopwatch stopwatch = Stopwatch.StartNew();
                        parentItem = this.xsoFactory.RunQueryOnAllItemsFolder <IStorePropertyBag>(this.session, AllItemsFolderHelper.SupportedSortBy.ConversationIdHash, conversationIdHash, null, delegate(QueryResult queryResult)
                        {
                            IStorePropertyBag[] propertyBags;
                            byte[] array;
                            do
                            {
                                propertyBags = queryResult.GetPropertyBags(1);
                                if (propertyBags == null || propertyBags.Length != 1)
                                {
                                    goto IL_69;
                                }
                                int?num = propertyBags[0].TryGetProperty(ItemSchema.ConversationIdHash) as int?;
                                if (num == null || num.Value != conversationIdHash)
                                {
                                    goto IL_69;
                                }
                                array = (propertyBags[0].TryGetProperty(InternalSchema.MapiConversationId) as byte[]);
                            }while (array == null || !Util.CompareByteArray(incomingConversationIdBytes, array));
                            return(propertyBags[0]);

                            IL_69:
                            return(null);
                        }, this.GetSearchPropertyDefinitions(new StorePropertyDefinition[]
                        {
                            InternalSchema.MapiConversationId,
                            ItemSchema.ConversationIdHash
                        }));
                        stopwatch.Stop();
                        if (this.indexTrackingEx != null)
                        {
                            this.indexTrackingEx.Trace("SBCID", stopwatch.ElapsedMilliseconds.ToString());
                        }
                        if (parentItem != null && !ConversationIndex.CompareTopics(parentItem.TryGetProperty(ItemSchema.ConversationTopic) as string, text2))
                        {
                            newIndex = ConversationIndex.CreateNew();
                            stage    = ConversationIndex.FixupStage.H11;
                            if (this.indexTrackingEx != null)
                            {
                                string text3 = parentItem.TryGetProperty(ItemSchema.InternetMessageId) as string;
                                if (text3 != null)
                                {
                                    this.indexTrackingEx.Trace("S3", text3);
                                }
                            }
                        }
                    }
                    if (stage == ConversationIndex.FixupStage.Unknown)
                    {
                        newIndex = conversationIndex;
                        bool flag3 = parentItem != null;
                        if (flag3)
                        {
                            bool?flag4 = parentItem.TryGetProperty(ItemSchema.ConversationIndexTracking) as bool?;
                            stage = ((flag4 == null || !flag4.Value) ? ConversationIndex.FixupStage.L1 : ConversationIndex.FixupStage.H14);
                        }
                        else
                        {
                            stage = ConversationIndex.FixupStage.H4;
                        }
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(item.GetValueOrDefault <string>(ItemSchema.InReplyTo, string.Empty)) && string.IsNullOrEmpty(item.GetValueOrDefault <string>(ItemSchema.InternetReferences, string.Empty)) && string.IsNullOrEmpty(item.GetValueOrDefault <string>(ItemSchema.SubjectPrefix)) && !flag)
                    {
                        TopicHashCache topicHashCache = TopicHashCache.Load(this.xsoFactory, this.session, 50);
                        if (string.IsNullOrEmpty(text2) || !topicHashCache.Contains(AllItemsFolderHelper.GetHashValue(text2)))
                        {
                            newIndex = ConversationIndex.CreateNew();
                            stage    = ConversationIndex.FixupStage.H12;
                        }
                    }
                    bool flag5;
                    bool flag6;
                    if (stage == ConversationIndex.FixupStage.Unknown && AggregationByItemClassReferencesSubjectProcessor.SearchByTopic(this.xsoFactory, this.session, item, this.indexTrackingEx, out parentItem, out flag5, out flag6, this.GetSearchPropertyDefinitions(new StorePropertyDefinition[]
                    {
                        ItemSchema.ReceivedTime,
                        ItemSchema.InReplyTo,
                        ItemSchema.InternetReferences
                    })))
                    {
                        if (this.indexTrackingEx != null)
                        {
                            string text4 = parentItem.TryGetProperty(ItemSchema.InternetMessageId) as string;
                            if (text4 != null)
                            {
                                this.indexTrackingEx.Trace("S2", text4);
                            }
                        }
                        bool?flag7 = parentItem.TryGetProperty(ItemSchema.ConversationIndexTracking) as bool?;
                        bool flag8 = flag7 == null || !flag7.Value;
                        if (flag5)
                        {
                            newIndex = conversationIndex;
                            stage    = (flag8 ? ConversationIndex.FixupStage.L1 : ConversationIndex.FixupStage.H5);
                        }
                        else
                        {
                            ConversationIndex conversationIndex2;
                            bool flag9 = ConversationIndex.TryCreate(parentItem.TryGetProperty(ItemSchema.ConversationIndex) as byte[], out conversationIndex2);
                            if (flag6)
                            {
                                ExDateTime?valueAsNullable = item.GetValueAsNullable <ExDateTime>(ItemSchema.SentTime);
                                newIndex = ((valueAsNullable != null) ? ConversationIndex.Create(conversationIndex2.Guid, valueAsNullable.Value) : ConversationIndex.Create(conversationIndex2.Guid));
                                stage    = (flag8 ? ConversationIndex.FixupStage.L1 : ConversationIndex.FixupStage.H6);
                            }
                            else
                            {
                                object obj             = parentItem.TryGetProperty(ItemSchema.ReceivedTime);
                                string valueOrDefault2 = item.GetValueOrDefault <string>(ItemSchema.SubjectPrefix);
                                if (obj != null && obj is ExDateTime)
                                {
                                    ExDateTime dt       = (ExDateTime)obj;
                                    TimeSpan   timeSpan = ExDateTime.Now - dt;
                                    if (timeSpan.TotalHours >= -72.0 && timeSpan.TotalHours <= 72.0 && flag9)
                                    {
                                        if (flag)
                                        {
                                            newIndex = conversationIndex.UpdateGuid(conversationIndex2.Guid);
                                            stage    = (flag8 ? ConversationIndex.FixupStage.L1 : ConversationIndex.FixupStage.H9);
                                        }
                                        else if (!string.IsNullOrEmpty(valueOrDefault2))
                                        {
                                            ExDateTime?valueAsNullable2 = item.GetValueAsNullable <ExDateTime>(ItemSchema.SentTime);
                                            if (valueAsNullable2 != null)
                                            {
                                                newIndex = ConversationIndex.Create(conversationIndex2.Guid, valueAsNullable2.Value);
                                            }
                                            else
                                            {
                                                newIndex = ConversationIndex.Create(conversationIndex2.Guid);
                                            }
                                            stage = (flag8 ? ConversationIndex.FixupStage.L1 : ConversationIndex.FixupStage.H6);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (stage == ConversationIndex.FixupStage.Unknown)
            {
                if (!string.IsNullOrEmpty(item.GetValueOrDefault <string>(ItemSchema.SubjectPrefix)))
                {
                    TopicHashCache topicHashCache2 = TopicHashCache.Load(this.xsoFactory, this.session, 50);
                    uint           hashValue       = AllItemsFolderHelper.GetHashValue(text2);
                    topicHashCache2.Add(hashValue);
                    TopicHashCache.Save(topicHashCache2, this.xsoFactory, this.session);
                    if (this.indexTrackingEx != null)
                    {
                        this.indexTrackingEx.Trace("THA", hashValue.ToString());
                    }
                }
                if (flag)
                {
                    newIndex = conversationIndex;
                    stage    = ConversationIndex.FixupStage.H7;
                    return;
                }
                newIndex = ConversationIndex.CreateNew();
                stage    = ConversationIndex.FixupStage.H8;
            }
        }
Exemplo n.º 6
0
        private static bool FixupMeetingMessage(IXSOFactory xsoFactory, IMailboxSession session, AggregationByItemClassReferencesSubjectProcessor.PropertyDefinitionListConstructorDelegate propertyDefinitionListConstructorDelegate, ICorePropertyBag corePropertyBag, ref ConversationIndex newIndex, ref ConversationIndex.FixupStage stage, out IStorePropertyBag parentItemPropertyBag)
        {
            corePropertyBag.Load(propertyDefinitionListConstructorDelegate(new PropertyDefinition[]
            {
                CalendarItemBaseSchema.GlobalObjectId,
                CalendarItemBaseSchema.CleanGlobalObjectId,
                CalendarItemBaseSchema.OwnerCriticalChangeTime,
                InternalSchema.AppointmentSequenceNumber
            }));
            byte[] array = corePropertyBag.TryGetProperty(CalendarItemBaseSchema.GlobalObjectId) as byte[];
            if (array == null)
            {
                parentItemPropertyBag = null;
                return(false);
            }
            GlobalObjectId globalObjectId;
            GlobalObjectId globalObjectId3;

            try
            {
                globalObjectId  = new GlobalObjectId(array);
                globalObjectId3 = new GlobalObjectId(array);
            }
            catch (CorruptDataException)
            {
                parentItemPropertyBag = null;
                return(false);
            }
            globalObjectId3.Date = ExDateTime.MinValue;
            string     valueOrDefault          = corePropertyBag.GetValueOrDefault <string>(InternalSchema.ItemClass, string.Empty);
            bool       isRequest               = ObjectClass.IsMeetingRequest(valueOrDefault);
            object     fixupStage              = null;
            ExDateTime ownerCriticalChangeTime = corePropertyBag.GetValueOrDefault <ExDateTime>(CalendarItemBaseSchema.OwnerCriticalChangeTime, ExDateTime.MaxValue);
            int        sequenceNumber          = corePropertyBag.GetValueOrDefault <int>(InternalSchema.AppointmentSequenceNumber, -1);

            if (sequenceNumber == -1)
            {
                parentItemPropertyBag = null;
                return(false);
            }
            parentItemPropertyBag = xsoFactory.RunQueryOnAllItemsFolder <IStorePropertyBag>(session, AllItemsFolderHelper.SupportedSortBy.CleanGlobalObjectId, globalObjectId3.Bytes, null, delegate(QueryResult queryResult)
            {
                IStorePropertyBag result = null;
                bool flag2 = false;
                while (!flag2)
                {
                    IStorePropertyBag[] propertyBags = queryResult.GetPropertyBags(50);
                    flag2 = (propertyBags.Length == 0);
                    IStorePropertyBag[] array2 = propertyBags;
                    int i = 0;
                    while (i < array2.Length)
                    {
                        IStorePropertyBag storePropertyBag = array2[i];
                        VersionedId versionedId            = (VersionedId)storePropertyBag.TryGetProperty(ItemSchema.Id);
                        byte[] array3 = (storePropertyBag.TryGetProperty(CalendarItemBaseSchema.GlobalObjectId) as byte[]) ?? (storePropertyBag.TryGetProperty(CalendarItemBaseSchema.CleanGlobalObjectId) as byte[]);
                        if (array3 != null && GlobalObjectId.CompareCleanGlobalObjectIds(array3, globalObjectId.Bytes))
                        {
                            GlobalObjectId globalObjectId2 = new GlobalObjectId(array3);
                            if (versionedId.ObjectId.ObjectType == StoreObjectType.MeetingRequest)
                            {
                                ConversationId conversationId = storePropertyBag.TryGetProperty(ConversationItemSchema.ConversationId) as ConversationId;
                                if (conversationId != null)
                                {
                                    if (isRequest)
                                    {
                                        fixupStage = ConversationIndex.FixupStage.M1;
                                        return(storePropertyBag);
                                    }
                                    if (AggregationByItemClassReferencesSubjectProcessor.IsMatchForMeetingResponse(globalObjectId, ownerCriticalChangeTime, sequenceNumber, storePropertyBag))
                                    {
                                        if (globalObjectId.Date != ExDateTime.MinValue && globalObjectId.Date == globalObjectId2.Date)
                                        {
                                            fixupStage = ConversationIndex.FixupStage.M3;
                                            return(storePropertyBag);
                                        }
                                        if (globalObjectId.Date == ExDateTime.MinValue)
                                        {
                                            fixupStage = ConversationIndex.FixupStage.M2;
                                            return(storePropertyBag);
                                        }
                                        fixupStage = ConversationIndex.FixupStage.M4;
                                        result     = storePropertyBag;
                                    }
                                }
                            }
                            i++;
                            continue;
                        }
                        return(result);
                    }
                }
                return(result);
            }, propertyDefinitionListConstructorDelegate(new PropertyDefinition[]
            {
                CalendarItemBaseSchema.GlobalObjectId,
                CalendarItemBaseSchema.CleanGlobalObjectId,
                InternalSchema.AppointmentSequenceNumber,
                CalendarItemBaseSchema.OwnerCriticalChangeTime,
                ConversationItemSchema.ConversationId
            }));
            if (parentItemPropertyBag == null)
            {
                return(false);
            }
            ConversationIndex conversationIndex;

            if (!ConversationIndex.TryCreate(parentItemPropertyBag.TryGetProperty(ItemSchema.ConversationIndex) as byte[], out conversationIndex))
            {
                return(false);
            }
            bool?flag = parentItemPropertyBag.TryGetProperty(ItemSchema.ConversationIndexTracking) as bool?;

            stage = ((flag == null || !flag.Value) ? ConversationIndex.FixupStage.L1 : ((ConversationIndex.FixupStage)fixupStage));
            if (isRequest)
            {
                byte[]            valueOrDefault2 = corePropertyBag.GetValueOrDefault <byte[]>(ItemSchema.ConversationIndex);
                ConversationIndex conversationIndex2;
                if (valueOrDefault2 != null && ConversationIndex.TryCreate(valueOrDefault2, out conversationIndex2))
                {
                    newIndex = conversationIndex.UpdateHeader(conversationIndex2.Components[0]);
                }
                else
                {
                    newIndex = ConversationIndex.Create(conversationIndex.Guid);
                }
            }
            else
            {
                newIndex = ConversationIndex.CreateFromParent(conversationIndex.Bytes);
            }
            return(true);
        }
Exemplo n.º 7
0
        private bool CalculateBasedOnReferenceMessage(ICorePropertyBag message, IStorePropertyBag referenceItem, out ConversationIndex.FixupStage stage, out ConversationIndex newIndex)
        {
            bool result = true;

            newIndex = ConversationIndex.Empty;
            stage    = ConversationIndex.FixupStage.Unknown;
            if (this.indexTrackingEx != null)
            {
                string text = referenceItem.TryGetProperty(ItemSchema.InternetMessageId) as string;
                if (text != null)
                {
                    this.indexTrackingEx.Trace("S1", text);
                }
            }
            string            text2 = message.TryGetProperty(ItemSchema.NormalizedSubject) as string;
            ConversationIndex conversationIndex;
            bool flag = ConversationIndex.TryCreate(referenceItem.TryGetProperty(ItemSchema.ConversationIndex) as byte[], out conversationIndex);
            ConversationIndex conversationIndex2;
            bool flag2 = ConversationIndex.TryCreate(message.TryGetProperty(ItemSchema.ConversationIndex) as byte[], out conversationIndex2);
            bool?flag3 = referenceItem.TryGetProperty(ItemSchema.ConversationIndexTracking) as bool?;
            bool flag4 = flag3 == null || !flag3.Value;

            if (flag)
            {
                string value = referenceItem.TryGetProperty(ItemSchema.ConversationTopic) as string;
                if (string.IsNullOrEmpty(value) || (!string.IsNullOrEmpty(text2) && text2.EndsWith(value, StringComparison.OrdinalIgnoreCase)))
                {
                    string text3 = message.TryGetProperty(ItemSchema.InReplyTo) as string;
                    string text4 = referenceItem.TryGetProperty(ItemSchema.InternetMessageId) as string;
                    if (!string.IsNullOrEmpty(text3) && !string.IsNullOrEmpty(text4) && string.Compare(text3, text4, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        if (conversationIndex.IsParentOf(conversationIndex2))
                        {
                            newIndex = conversationIndex2;
                            stage    = (flag4 ? ConversationIndex.FixupStage.L1 : ConversationIndex.FixupStage.H1);
                            result   = false;
                        }
                        else
                        {
                            ExDateTime?valueAsNullable = message.GetValueAsNullable <ExDateTime>(ItemSchema.SentTime);
                            if (valueAsNullable != null)
                            {
                                newIndex = ConversationIndex.CreateFromParent(conversationIndex.Bytes, valueAsNullable.Value);
                            }
                            else
                            {
                                newIndex = ConversationIndex.CreateFromParent(conversationIndex.Bytes);
                            }
                            stage = (flag4 ? ConversationIndex.FixupStage.L1 : ConversationIndex.FixupStage.H2);
                        }
                    }
                    else if (flag2)
                    {
                        if (conversationIndex.IsAncestorOf(conversationIndex2))
                        {
                            newIndex = conversationIndex2;
                            stage    = (flag4 ? ConversationIndex.FixupStage.L1 : ConversationIndex.FixupStage.H1);
                            result   = false;
                        }
                        else
                        {
                            newIndex = conversationIndex2.UpdateGuid(conversationIndex.Guid);
                            newIndex = newIndex.UpdateHeader(conversationIndex.Header);
                            stage    = (flag4 ? ConversationIndex.FixupStage.L1 : ConversationIndex.FixupStage.H10);
                        }
                    }
                    else
                    {
                        newIndex = ConversationIndex.CreateFromParent(conversationIndex.Bytes);
                        stage    = (flag4 ? ConversationIndex.FixupStage.L1 : ConversationIndex.FixupStage.H2);
                    }
                }
                else
                {
                    newIndex = ConversationIndex.CreateNew();
                    stage    = ConversationIndex.FixupStage.H3;
                }
            }
            return(result);
        }