// Token: 0x06000113 RID: 275 RVA: 0x00006C64 File Offset: 0x00004E64
        internal static void HandleEventInternal(MapiEvent mapiEvent, MailboxSession session, StoreObject storeItem, MailboxData mailboxData)
        {
            SentItemsProcessor.Tracer.TraceDebug(0L, "{0}: Calling SentItemsProcessor.HandleEventInternal", new object[]
            {
                TraceContext.Get()
            });
            Item item = (Item)storeItem;

            if (item == null)
            {
                SentItemsProcessor.Tracer.TraceError(0L, "{0}: HandleEventInternal received null item", new object[]
                {
                    TraceContext.Get()
                });
                return;
            }
            if (ObjectClass.IsSmsMessage(item.ClassName))
            {
                try
                {
                    ConversationIndexTrackingEx conversationIndexTrackingEx = ConversationIndexTrackingEx.Create();
                    SentItemsProcessor.HandleSmsMessage(session, item, mailboxData, conversationIndexTrackingEx);
                    SentItemsProcessor.Tracer.TraceDebug <object, ConversationIndexTrackingEx>(0L, "{0}: ChunkSmsConversation traces: {1}", TraceContext.Get(), conversationIndexTrackingEx);
                }
                catch (ObjectNotFoundException)
                {
                    SentItemsProcessor.Tracer.TraceDebug(0L, "{0}: ObjectNotFoundException thrown while processing SMS item in Sent Items folder", new object[]
                    {
                        TraceContext.Get()
                    });
                }
                return;
            }
            try
            {
                ConversationId valueOrDefault = item.GetValueOrDefault <ConversationId>(ItemSchema.ConversationId);
                if (valueOrDefault == null)
                {
                    SentItemsProcessor.Tracer.TraceError(0L, "{0}: Found item without conversation id", new object[]
                    {
                        TraceContext.Get()
                    });
                }
                else
                {
                    int             totalActionItemCount;
                    IList <StoreId> list    = ConversationActionItem.QueryConversationActionsFolder(session, valueOrDefault, 1, out totalActionItemCount);
                    StoreId         storeId = (list != null) ? list[0] : null;
                    mailboxData.UpdateConversationActionsEnabledStatus(totalActionItemCount);
                    if (storeId == null)
                    {
                        SentItemsProcessor.Tracer.TraceDebug <object, ConversationId>(0L, "{0}: No action item associated found for message with conversation Id = {1}", TraceContext.Get(), valueOrDefault);
                    }
                    else
                    {
                        using (ConversationActionItem conversationActionItem = ConversationActionItem.Bind(session, storeId))
                        {
                            if (conversationActionItem.IsCorrectVersion())
                            {
                                if (conversationActionItem.AlwaysCategorizeValue != null)
                                {
                                    List <string> categoriesForItem = conversationActionItem.GetCategoriesForItem(item.TryGetProperty(ItemSchema.Categories) as string[]);
                                    if (categoriesForItem != null)
                                    {
                                        SentItemsProcessor.Tracer.TraceDebug(0L, "{0}: Processed categories on item", new object[]
                                        {
                                            TraceContext.Get()
                                        });
                                        item.SafeSetProperty(ItemSchema.Categories, categoriesForItem.ToArray());
                                        item.Save(SaveMode.ResolveConflicts);
                                        item.Load();
                                    }
                                }
                                conversationActionItem.Save(SaveMode.ResolveConflicts);
                            }
                        }
                    }
                }
            }
            catch (ObjectNotFoundException)
            {
                SentItemsProcessor.Tracer.TraceDebug(0L, "{0}: ObjectNotFoundException thrown while processing action item", new object[]
                {
                    TraceContext.Get()
                });
            }
        }
        public void OnPromotedMessageHandler(StoreDriverEventSource source, StoreDriverDeliveryEventArgs args)
        {
            ConversationsProcessingAgent.tracer.TraceDebug(0L, "Called ConversationsProcessingAgent.OnPromotedMessageHandler");
            if (args == null)
            {
                return;
            }
            StoreDriverDeliveryEventArgsImpl storeDriverDeliveryEventArgsImpl = (StoreDriverDeliveryEventArgsImpl)args;

            if (ConversationsProcessingAgent.ShouldSkipMessageProcessing(storeDriverDeliveryEventArgsImpl))
            {
                return;
            }
            if (storeDriverDeliveryEventArgsImpl.MailboxOwner == null)
            {
                return;
            }
            MailboxSession mailboxSession = storeDriverDeliveryEventArgsImpl.MailboxSession;

            if (mailboxSession.MailboxOwner.MailboxInfo.Location.ServerVersion <= 1937801369)
            {
                if (ConversationsProcessingAgent.tracer.IsTraceEnabled(TraceType.DebugTrace))
                {
                    ConversationsProcessingAgent.tracer.TraceDebug <string, string>((long)this.GetHashCode(), "Backend server version (0x{0}) is less than minimum required (0x{1})", mailboxSession.MailboxOwner.MailboxInfo.Location.ServerVersion.ToString("X"), 1937801369.ToString("X"));
                }
                return;
            }
            ConversationsProcessingAgent.tracer.TraceDebug((long)this.GetHashCode(), "Processing incoming message");
            Stopwatch stopwatch = Stopwatch.StartNew();

            try
            {
                if (storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies == null)
                {
                    storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies = new Dictionary <PropertyDefinition, object>();
                }
                ConversationIndexTrackingEx conversationIndexTrackingEx = ConversationIndexTrackingEx.Create();
                this.performanceContext = ConversationsProcessingAgent.conversationLatencyDetectionContextFactory.CreateContext("15.00.1497.012", "FIXUP", new IPerformanceDataProvider[0]);
                if (!this.isBodyTagCalculated)
                {
                    ConversationsProcessingAgent.tracer.TraceDebug((long)this.GetHashCode(), "Calculating body tag");
                    Stopwatch stopwatch2 = Stopwatch.StartNew();
                    if (storeDriverDeliveryEventArgsImpl.ReplayItem.IsRestricted)
                    {
                        if (!this.TryCalculateIrmBodyTag(storeDriverDeliveryEventArgsImpl))
                        {
                            this.bodyTag = null;
                        }
                    }
                    else if (PropertyError.IsPropertyNotFound(storeDriverDeliveryEventArgsImpl.ReplayItem.TryGetProperty(ItemSchema.BodyTag)))
                    {
                        this.bodyTag = storeDriverDeliveryEventArgsImpl.ReplayItem.Body.CalculateBodyTag(out this.latestMessageWordCount);
                    }
                    else
                    {
                        this.bodyTag = storeDriverDeliveryEventArgsImpl.ReplayItem.GetValueOrDefault <byte[]>(ItemSchema.BodyTag);
                        this.latestMessageWordCount = storeDriverDeliveryEventArgsImpl.ReplayItem.GetValueOrDefault <int>(MessageItemSchema.LatestMessageWordCount, int.MinValue);
                    }
                    stopwatch2.Stop();
                    conversationIndexTrackingEx.Trace("BT", stopwatch2.ElapsedMilliseconds.ToString());
                    this.isBodyTagCalculated = true;
                }
                if (this.bodyTag != null)
                {
                    storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.BodyTag] = this.bodyTag;
                    if (this.latestMessageWordCount >= 0)
                    {
                        storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[MessageItemSchema.LatestMessageWordCount] = this.latestMessageWordCount;
                        storeDriverDeliveryEventArgsImpl.ReplayItem.SafeSetProperty(MessageItemSchema.LatestMessageWordCount, this.latestMessageWordCount);
                    }
                }
                if (this.forceAllAttachmentsHidden)
                {
                    storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[MessageItemSchema.AllAttachmentsHidden] = true;
                }
                if (!ConversationIndex.CompareTopics(storeDriverDeliveryEventArgsImpl.ReplayItem.TryGetProperty(ItemSchema.ConversationTopic) as string, storeDriverDeliveryEventArgsImpl.ReplayItem.TryGetProperty(ItemSchema.NormalizedSubject) as string))
                {
                    storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.ConversationTopic] = ((storeDriverDeliveryEventArgsImpl.ReplayItem.TryGetProperty(ItemSchema.NormalizedSubject) as string) ?? string.Empty);
                }
                if (!storeDriverDeliveryEventArgsImpl.MessageClass.Equals("IPM.WorkingSet.Signal", StringComparison.InvariantCulture))
                {
                    ConversationAggregationResult conversationAggregationResult = new ConversationAggregationResult();
                    ConversationsProcessingAgent.tracer.TraceDebug((long)this.GetHashCode(), "Fixing up the conversation id");
                    try
                    {
                        IConversationAggregator conversationAggregator;
                        if (ConversationAggregatorFactory.TryInstantiateAggregatorForDelivery(mailboxSession, storeDriverDeliveryEventArgsImpl.MailboxOwner, conversationIndexTrackingEx, out conversationAggregator))
                        {
                            conversationAggregationResult = conversationAggregator.Aggregate(storeDriverDeliveryEventArgsImpl.ReplayItem.CoreItem);
                        }
                        else
                        {
                            ConversationsProcessingAgent.tracer.TraceError((long)this.GetHashCode(), "Not able to identify a valid conversationAggregator");
                            conversationAggregationResult.ConversationIndex = ConversationIndex.CreateNew();
                            conversationAggregationResult.Stage             = ConversationIndex.FixupStage.Error;
                        }
                    }
                    catch (ObjectNotFoundException arg)
                    {
                        ConversationsProcessingAgent.tracer.TraceError <ObjectNotFoundException>((long)this.GetHashCode(), "Exception - {0}", arg);
                        conversationAggregationResult.ConversationIndex = ConversationIndex.CreateNew();
                        conversationAggregationResult.Stage             = ConversationIndex.FixupStage.Error;
                    }
                    this.performanceContext.StopAndFinalizeCollection();
                    conversationIndexTrackingEx.Trace("FIXUP", this.performanceContext.Elapsed.TotalMilliseconds.ToString());
                    ConversationsProcessingAgent.tracer.TraceDebug <int>((long)this.GetHashCode(), "FixupStage = {0}", (int)conversationAggregationResult.Stage);
                    ConversationId conversationId = ConversationId.Create(conversationAggregationResult.ConversationIndex);
                    ConversationsProcessingAgent.tracer.TraceDebug <ConversationId>((long)this.GetHashCode(), "ConversationId (CID) for item: {0}", conversationId);
                    storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.ConversationIndex] = conversationAggregationResult.ConversationIndex.ToByteArray();
                    storeDriverDeliveryEventArgsImpl.ReplayItem.SafeSetProperty(ItemSchema.ConversationIndex, storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.ConversationIndex]);
                    storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.ConversationFamilyId] = conversationAggregationResult.ConversationFamilyId;
                    storeDriverDeliveryEventArgsImpl.ReplayItem.SafeSetProperty(ItemSchema.ConversationFamilyId, storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.ConversationFamilyId]);
                    storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.SupportsSideConversation] = conversationAggregationResult.SupportsSideConversation;
                    storeDriverDeliveryEventArgsImpl.ReplayItem.SafeSetProperty(ItemSchema.SupportsSideConversation, storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.SupportsSideConversation]);
                    byte[] value;
                    if (this.TryCalculateConversationCreatorSid(mailboxSession, storeDriverDeliveryEventArgsImpl.MailboxOwner, conversationAggregationResult, storeDriverDeliveryEventArgsImpl.ReplayItem.PropertyBag, out value))
                    {
                        storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.ConversationCreatorSID] = value;
                        storeDriverDeliveryEventArgsImpl.ReplayItem.SafeSetProperty(ItemSchema.ConversationCreatorSID, storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.ConversationCreatorSID]);
                    }
                    conversationIndexTrackingEx.TraceVersionAndHeuristics(conversationAggregationResult.Stage.ToString());
                    storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.ConversationIndexTrackingEx] = conversationIndexTrackingEx.ToString();
                    if (conversationAggregationResult.Stage != ConversationIndex.FixupStage.L1)
                    {
                        storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.ConversationIndexTracking] = true;
                        storeDriverDeliveryEventArgsImpl.ReplayItem.SafeSetProperty(ItemSchema.ConversationIndexTracking, storeDriverDeliveryEventArgsImpl.PropertiesForAllMessageCopies[ItemSchema.ConversationIndexTracking]);
                    }
                    ConversationsProcessingAgent.tracer.TraceDebug <ConversationIndexTrackingEx>((long)this.GetHashCode(), "Time Spent in different stages - {0}", conversationIndexTrackingEx);
                    ConversationsProcessingAgent.tracer.TraceDebug((long)this.GetHashCode(), "Processing conversation actions");
                    if (!ConversationIndex.IsFixUpCreatingNewConversation(conversationAggregationResult.Stage))
                    {
                        this.ProcessConversationActions(conversationId, storeDriverDeliveryEventArgsImpl);
                    }
                    if (ConversationIndex.IsFixupAddingOutOfOrderMessageToConversation(conversationAggregationResult.Stage))
                    {
                        if (storeDriverDeliveryEventArgsImpl.SharedPropertiesBetweenAgents == null)
                        {
                            storeDriverDeliveryEventArgsImpl.SharedPropertiesBetweenAgents = new Dictionary <PropertyDefinition, object>();
                        }
                        storeDriverDeliveryEventArgsImpl.SharedPropertiesBetweenAgents[ItemSchema.ConversationLoadRequiredByInference] = true;
                    }
                }
            }
            finally
            {
                stopwatch.Stop();
                MSExchangeConversationsProcessing.LastMessageProcessingTime.RawValue = stopwatch.ElapsedMilliseconds;
                ConversationsProcessingAgent.averageMessageProcessingTime.Update(stopwatch.ElapsedMilliseconds);
                ConversationsProcessingAgent.tracer.TraceDebug <long>((long)this.GetHashCode(), "Exiting ConversationsProcessing.ProcessMessage.  Total execution time = {0} ms.", stopwatch.ElapsedMilliseconds);
            }
        }