Ejemplo n.º 1
0
        internal static Charset GetItemMimeCharset(ICorePropertyBag propertyBag)
        {
            int     valueOrDefault = propertyBag.GetValueOrDefault <int>(InternalSchema.InternetCpid, 0);
            Charset mimeCharset;

            if (ConvertUtils.TryGetValidCharset(valueOrDefault, out mimeCharset))
            {
                return(mimeCharset);
            }
            int  num  = propertyBag.GetValueOrDefault <int>(InternalSchema.Codepage, 0);
            bool flag = false;

            if (num == 1252)
            {
                num  = 28605;
                flag = true;
            }
            if (Charset.TryGetCharset(num, out mimeCharset))
            {
                if (!flag)
                {
                    mimeCharset = mimeCharset.Culture.MimeCharset;
                }
                if (mimeCharset != null && mimeCharset.IsAvailable)
                {
                    return(mimeCharset);
                }
            }
            return(Culture.Default.MimeCharset);
        }
Ejemplo n.º 2
0
        internal static bool UpdateEmailAddressProperty(ICorePropertyBag propertyBag, EmailAddressProperties emailAddressProperty)
        {
            if (!propertyBag.IsPropertyDirty(emailAddressProperty.OriginalDisplayName) || propertyBag.IsPropertyDirty(emailAddressProperty.Address))
            {
                return(false);
            }
            string valueOrDefault = propertyBag.GetValueOrDefault <string>(emailAddressProperty.RoutingType, null);

            if (!"SMTP".Equals(valueOrDefault, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }
            string valueOrDefault2 = propertyBag.GetValueOrDefault <string>(emailAddressProperty.OriginalDisplayName, null);

            if (string.IsNullOrEmpty(valueOrDefault2))
            {
                return(false);
            }
            string valueOrDefault3 = propertyBag.GetValueOrDefault <string>(emailAddressProperty.Address, null);

            if (string.IsNullOrEmpty(valueOrDefault3))
            {
                propertyBag[emailAddressProperty.Address] = valueOrDefault2;
                return(true);
            }
            return(false);
        }
 public bool TryCalculateOnDelivery(ICorePropertyBag itemPropertyBag, ConversationIndex.FixupStage stage, ConversationIndex conversationIndex, out byte[] conversationCreatorSid, out bool updateAllConversationMessages)
 {
     ConversationCreatorSidCalculator.MessageType messageType = this.CalculateMessageTypeOnDelivery(conversationIndex, itemPropertyBag, stage);
     updateAllConversationMessages = (messageType == ConversationCreatorSidCalculator.MessageType.OutOfOrderRootMessage);
     byte[] valueOrDefault = itemPropertyBag.GetValueOrDefault <byte[]>(InternalSchema.SenderSID, null);
     return(this.TryCalculateConversationCreatorSid(conversationIndex, messageType, valueOrDefault, out conversationCreatorSid));
 }
Ejemplo n.º 4
0
        internal static void CoreObjectUpdateConversationTopic(CoreItem coreItem)
        {
            ICorePropertyBag propertyBag     = coreItem.PropertyBag;
            string           valueOrDefault  = propertyBag.GetValueOrDefault <string>(InternalSchema.NormalizedSubjectInternal);
            string           valueOrDefault2 = propertyBag.GetValueOrDefault <string>(InternalSchema.ConversationTopic);

            byte[] valueOrDefault3 = propertyBag.GetValueOrDefault <byte[]>(InternalSchema.ConversationIndex);
            if (valueOrDefault != null)
            {
                if (valueOrDefault2 == null)
                {
                    propertyBag[InternalSchema.ConversationTopic] = valueOrDefault;
                }
                if (valueOrDefault3 == null)
                {
                    propertyBag[InternalSchema.ConversationIndex] = Microsoft.Exchange.Data.Storage.ConversationIndex.CreateNew().ToByteArray();
                }
            }
        }
Ejemplo n.º 5
0
        internal static void GetEntryIds(ICorePropertyBag propertyBag, out ParticipantEntryId[] mainEntryIds, out ParticipantEntryId[] oneOffEntryIds, out byte[][] extraBytes, out uint computedCheckSum, out bool alwaysStream)
        {
            mainEntryIds     = new ParticipantEntryId[0];
            oneOffEntryIds   = new ParticipantEntryId[0];
            extraBytes       = new byte[0][];
            computedCheckSum = 0U;
            alwaysStream     = false;
            PropertyError propertyError = propertyBag.TryGetProperty(DistributionListSchema.DLStream) as PropertyError;

            if (propertyError == null || PropertyError.IsPropertyValueTooBig(propertyError))
            {
                long num = -1L;
                try
                {
                    using (Stream stream = propertyBag.OpenPropertyStream(DistributionListSchema.DLStream, PropertyOpenMode.ReadOnly))
                    {
                        if (stream != null && stream.Length > 0L)
                        {
                            num = stream.Length;
                            byte[][] memberIds;
                            DistributionList.ParseEntryIdStream(stream, out mainEntryIds, out oneOffEntryIds, out memberIds, out extraBytes, out alwaysStream);
                            computedCheckSum = DistributionList.ComputeChecksum(memberIds);
                            return;
                        }
                        ExTraceGlobals.StorageTracer.TraceWarning <string>(0L, "DistributionList::GetEntryIds. DLStream property is {0}.", (stream == null) ? "null" : "empty");
                    }
                }
                catch (EndOfStreamException innerException)
                {
                    string          arg     = (propertyError == null) ? "<null>" : propertyError.ToLocalizedString();
                    LocalizedString message = ServerStrings.ExPDLCorruptOutlookBlob(string.Format("EndOfStreamException: propertyError={0}, streamLength={1}", arg, num.ToString()));
                    throw new CorruptDataException(message, innerException);
                }
                catch (OutOfMemoryException innerException2)
                {
                    throw new CorruptDataException(ServerStrings.ExPDLCorruptOutlookBlob("OutOfMemoryException"), innerException2);
                }
            }
            mainEntryIds     = DistributionList.ParseEntryIds(propertyBag.GetValueOrDefault <byte[][]>(DistributionListSchema.Members, DistributionList.EmptyEntryIds));
            oneOffEntryIds   = DistributionList.ParseEntryIds(propertyBag.GetValueOrDefault <byte[][]>(DistributionListSchema.OneOffMembers, DistributionList.EmptyEntryIds));
            extraBytes       = new byte[mainEntryIds.Length][];
            computedCheckSum = DistributionList.ComputeChecksum(propertyBag.GetValueOrDefault <byte[][]>(DistributionListSchema.Members, DistributionList.EmptyEntryIds));
        }
Ejemplo n.º 6
0
        protected sealed override bool WriteEnforceRule(ICorePropertyBag propertyBag)
        {
            bool   result          = false;
            bool   isPropertyDirty = propertyBag.IsPropertyDirty(this.propertyToSet);
            object propertyValue   = propertyBag.TryGetProperty(this.propertyToSet);

            if (this.ShouldEnforce(isPropertyDirty, propertyValue))
            {
                TSet    valueOrDefault  = propertyBag.GetValueOrDefault <TSet>(this.propertyToSet);
                TDepend valueOrDefault2 = propertyBag.GetValueOrDefault <TDepend>(this.propertyToDepend);
                TSet    tset;
                if (this.CalculateValue(valueOrDefault2, valueOrDefault, out tset) && (PropertyError.IsPropertyNotFound(propertyValue) || !object.Equals(tset, valueOrDefault)))
                {
                    propertyBag.SetOrDeleteProperty(this.propertyToSet, tset);
                    result = true;
                }
            }
            return(result);
        }
 public bool HasNonEmptyValue(ICorePropertyBag propertyBag)
 {
     foreach (NativeStorePropertyDefinition propertyDefinition in this.PropertyDefinitions)
     {
         if (propertyBag.GetValueOrDefault <string>(propertyDefinition, string.Empty).Trim() != string.Empty)
         {
             return(true);
         }
     }
     return(false);
 }
 public static bool TryCalculateConversationCreatorSidOnDeliveryProcessing(MailboxSession mailboxSession, ICorePropertyBag itemPropertyBag, ConversationIndex.FixupStage fixupStage, ConversationIndex conversationIndex, out byte[] conversationCreatorSid, out bool updateAllConversationMessages)
 {
     conversationCreatorSid        = null;
     updateAllConversationMessages = false;
     if (!ConversationCreatorHelper.SupportsConversationCreator(mailboxSession))
     {
         return(false);
     }
     byte[] valueOrDefault = itemPropertyBag.GetValueOrDefault <byte[]>(InternalSchema.SenderSID, null);
     return(ConversationCreatorHelper.TryCalculateConversationCreatorSid(mailboxSession, itemPropertyBag, fixupStage, conversationIndex, valueOrDefault, out conversationCreatorSid, out updateAllConversationMessages));
 }
        private static void GetDisplayNamesFromNameProperties(ICorePropertyBag propertyBag, out string displayNameFirstLast, out string displayNameLastFirst)
        {
            string valueOrDefault  = propertyBag.GetValueOrDefault <string>(InternalSchema.GivenName, string.Empty);
            string valueOrDefault2 = propertyBag.GetValueOrDefault <string>(InternalSchema.MiddleName, string.Empty);
            string valueOrDefault3 = propertyBag.GetValueOrDefault <string>(InternalSchema.Surname, string.Empty);
            string valueOrDefault4 = propertyBag.GetValueOrDefault <string>(InternalSchema.DisplayName, string.Empty);

            displayNameFirstLast = ContactDisplayNamePropertyRule.BuildDisplayName(valueOrDefault4, " ", new string[]
            {
                valueOrDefault,
                valueOrDefault2,
                valueOrDefault3
            });
            displayNameLastFirst = ContactDisplayNamePropertyRule.BuildDisplayName(valueOrDefault4, " ", new string[]
            {
                valueOrDefault3,
                valueOrDefault,
                valueOrDefault2
            });
        }
        private ConversationAggregatorFactory.AggregationApproach IdentifyAggregationApproachForSave(CoreItemOperation saveOperation, ICoreItem item)
        {
            if (this.session.LogonType == LogonType.Transport)
            {
                return(ConversationAggregatorFactory.AggregationApproach.NoOp);
            }
            ICorePropertyBag propertyBag    = item.PropertyBag;
            string           valueOrDefault = propertyBag.GetValueOrDefault <string>(InternalSchema.ItemClass, string.Empty);

            if (string.IsNullOrEmpty(valueOrDefault) || ConversationIdFromIndexProperty.CheckExclusionList(valueOrDefault) || propertyBag.GetValueOrDefault <bool>(InternalSchema.IsAssociated))
            {
                return(ConversationAggregatorFactory.AggregationApproach.NoOp);
            }
            if (this.mailboxOwner.ThreadedConversationProcessingEnabled || this.mailboxOwner.SideConversationProcessingEnabled)
            {
                if (saveOperation == CoreItemOperation.Send || (item.Origin == Origin.New && !ConversationIndex.WasMessageEverProcessed(propertyBag)))
                {
                    if (!this.mailboxOwner.ThreadedConversationProcessingEnabled)
                    {
                        return(ConversationAggregatorFactory.AggregationApproach.SideConversation);
                    }
                    return(ConversationAggregatorFactory.AggregationApproach.ThreadedConversation);
                }
                else
                {
                    if (this.mailboxOwner.IsGroupMailbox && !propertyBag.GetValueOrDefault <bool>(InternalSchema.IsDraft))
                    {
                        return(ConversationAggregatorFactory.AggregationApproach.SideConversation);
                    }
                    return(ConversationAggregatorFactory.AggregationApproach.NoOp);
                }
            }
            else
            {
                if (item.Origin == Origin.New && !ConversationIndex.WasMessageEverProcessed(propertyBag))
                {
                    return(ConversationAggregatorFactory.AggregationApproach.SameConversation);
                }
                return(ConversationAggregatorFactory.AggregationApproach.NoOp);
            }
        }
Ejemplo n.º 11
0
        private static bool CheckUserEquality(ICorePropertyBag item, StorePropertyDefinition participantPropertyDefinition, IGenericADUser adUser)
        {
            Participant participant = item.GetValueOrDefault <Participant>(participantPropertyDefinition, null);

            if (participant == null)
            {
                return(false);
            }
            byte[] valueOrDefault = participant.GetValueOrDefault <byte[]>(ParticipantSchema.ParticipantSID);
            byte[] array          = MailboxOwnerAdapter.CalculateEffectiveId(adUser);
            return((array != null && valueOrDefault != null && ByteArrayComparer.Instance.Equals(valueOrDefault, array)) || StringComparer.OrdinalIgnoreCase.Equals(adUser.LegacyDn, participant.EmailAddress) || StringComparer.OrdinalIgnoreCase.Equals(adUser.PrimarySmtpAddress.ToString(), participant.EmailAddress) || adUser.EmailAddresses.Any((ProxyAddress address) => StringComparer.OrdinalIgnoreCase.Equals(address.AddressString, participant.EmailAddress)));
        }
        private static bool IsRootMessage(Conversation conversation, ICorePropertyBag messagePropertyBag)
        {
            StoreObjectId rootMessageId = conversation.RootMessageId;

            if (rootMessageId == null)
            {
                return(false);
            }
            VersionedId valueOrDefault = messagePropertyBag.GetValueOrDefault <VersionedId>(ItemSchema.Id, null);

            return(rootMessageId.Equals(valueOrDefault.ObjectId));
        }
        private bool IsRootMessage(IConversation conversation, ICorePropertyBag message)
        {
            string valueOrDefault = conversation.RootMessageNode.GetValueOrDefault <string>(InternalSchema.InReplyTo, string.Empty);

            if (string.IsNullOrEmpty(valueOrDefault))
            {
                return(false);
            }
            string valueOrDefault2 = message.GetValueOrDefault <string>(InternalSchema.InternetMessageId, string.Empty);

            return(valueOrDefault.Equals(valueOrDefault2, StringComparison.InvariantCultureIgnoreCase));
        }
Ejemplo n.º 14
0
        public bool UpdateProperties(ICorePropertyBag propertyBag)
        {
            string valueOrDefault = propertyBag.GetValueOrDefault <string>(StoreObjectSchema.ItemClass, null);

            if (string.IsNullOrEmpty(valueOrDefault))
            {
                return(false);
            }
            if (!ObjectClass.IsContact(valueOrDefault) && !ObjectClass.IsDistributionList(valueOrDefault))
            {
                return(false);
            }
            bool valueOrDefault2 = propertyBag.GetValueOrDefault <bool>(InternalSchema.ConversationIndexTracking, false);

            if (valueOrDefault2)
            {
                return(false);
            }
            propertyBag[InternalSchema.ConversationIndexTracking] = true;
            return(true);
        }
Ejemplo n.º 15
0
        public override bool UpdateDisplayNameProperties(ICorePropertyBag propertyBag)
        {
            bool   flag = base.UpdateDisplayNameProperties(propertyBag);
            string text = propertyBag.GetValueOrDefault <string>(InternalSchema.DisplayNameFirstLast, string.Empty).Trim();

            if (text != string.Empty)
            {
                propertyBag[ContactBaseSchema.FileAs]      = text;
                propertyBag[ItemSchema.Subject]            = text;
                propertyBag[DistributionListSchema.DLName] = text;
            }
            return(flag | this.TruncateSubject(propertyBag));
        }
 private static bool CopyCloudIdFromOscContactSourcesIfCurrentCloudIdIsBlank(ICorePropertyBag propertyBag, OscNetworkProperties networkProperties)
 {
     if (propertyBag.IsPropertyDirty(ItemSchema.CloudId))
     {
         return(false);
     }
     if (!string.IsNullOrEmpty(propertyBag.GetValueOrDefault <string>(ItemSchema.CloudId)))
     {
         return(false);
     }
     if (networkProperties != null && !string.IsNullOrEmpty(networkProperties.NetworkUserId))
     {
         propertyBag[ItemSchema.CloudId] = networkProperties.NetworkUserId;
         return(true);
     }
     return(false);
 }
Ejemplo n.º 17
0
        internal void UpdateParentMsgRichContentFlags(RichContentFlags richContentFlags)
        {
            this.CheckDisposed(null);
            if (this.parentCollection == null || this.parentCollection.ContainerItem == null)
            {
                return;
            }
            ICoreItem        containerItem   = this.parentCollection.ContainerItem;
            ICorePropertyBag corePropertyBag = containerItem.PropertyBag;

            corePropertyBag.Load(new PropertyDefinition[]
            {
                InternalSchema.RichContent
            });
            short valueOrDefault = corePropertyBag.GetValueOrDefault <short>(InternalSchema.RichContent, 0);
            short num            = valueOrDefault | (short)richContentFlags;

            corePropertyBag[InternalSchema.RichContent] = num;
        }
        public bool Aggregate(ICorePropertyBag propertyBag, out ConversationIndex newIndex, out ConversationIndex.FixupStage stage)
        {
            newIndex = ConversationIndex.Empty;
            Participant valueOrDefault = propertyBag.GetValueOrDefault <Participant>(InternalSchema.From);

            if (valueOrDefault != null && string.Equals("MOBILE", valueOrDefault.RoutingType, StringComparison.OrdinalIgnoreCase))
            {
                newIndex = ConversationIndex.GenerateFromPhoneNumber(valueOrDefault.EmailAddress);
            }
            if (newIndex != ConversationIndex.Empty)
            {
                stage = ConversationIndex.FixupStage.S1;
                AggregationBySmsItemClassProcessor.ChunkSmsConversation(this.xsoFactory, this.session, newIndex, this.indexTrackingEx);
            }
            else
            {
                newIndex = ConversationIndex.CreateNew();
                stage    = ConversationIndex.FixupStage.S2;
            }
            return(false);
        }
 public bool UpdatePartnerNetworkProperties(ICorePropertyBag propertyBag)
 {
     if (!propertyBag.IsPropertyDirty(ContactSchema.OscContactSourcesForContact))
     {
         return(false);
     }
     byte[] valueOrDefault = propertyBag.GetValueOrDefault <byte[]>(ContactSchema.OscContactSourcesForContact, null);
     if (valueOrDefault == null || valueOrDefault.Length == 0)
     {
         return(OscContactSourcesForContactUpdateRule.UpdateDependentProperties(propertyBag, null, null));
     }
     try
     {
         return(OscContactSourcesForContactUpdateRule.UpdateDependentProperties(propertyBag, valueOrDefault, this.oscParser.ReadOscContactSource(valueOrDefault)));
     }
     catch (OscContactSourcesForContactParseException arg)
     {
         OscContactSourcesForContactUpdateRule.Tracer.TraceError <OscContactSourcesForContactParseException>((long)this.GetHashCode(), "Encountered exception when parsing: {0}", arg);
     }
     return(false);
 }
Ejemplo n.º 20
0
        private static bool MatchMessageIdWithReferences(ICorePropertyBag persistPropertyBag, IStorePropertyBag foundPropertyBag)
        {
            string valueOrDefault = persistPropertyBag.GetValueOrDefault <string>(ItemSchema.InternetMessageId, null);

            if (string.IsNullOrEmpty(valueOrDefault))
            {
                return(false);
            }
            List <string> list = new List <string>(0);
            string        text = foundPropertyBag.TryGetProperty(ItemSchema.InReplyTo) as string;

            if (!string.IsNullOrEmpty(text))
            {
                list.Add(text);
            }
            string text2 = foundPropertyBag.TryGetProperty(ItemSchema.InternetReferences) as string;

            if (!string.IsNullOrEmpty(text2))
            {
                string[] array = text2.Split(AggregationByItemClassReferencesSubjectProcessor.ReferencesSeparators, StringSplitOptions.RemoveEmptyEntries);
                if (array != null)
                {
                    list.AddRange(array);
                }
            }
            int num = 0;

            while (num < list.Count && num < 50)
            {
                if (string.Compare(valueOrDefault, list[num], StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(true);
                }
                num++;
            }
            return(false);
        }
Ejemplo n.º 21
0
 private static StoreObjectType?TryDetectShortcutMessageEntryStoreObjectType(ICorePropertyBag propertyBag, string itemClass, StoreObjectType detectedType)
 {
     if (detectedType != StoreObjectType.Message || !ObjectClass.IsShortcutMessageEntry(propertyBag.GetValueOrDefault <int>(CoreItemSchema.FavLevelMask, -1)))
     {
         return(null);
     }
     return(new StoreObjectType?(StoreObjectType.ShortcutMessage));
 }
 public static bool TryCalculateConversationCreatorSidOnSaving(MailboxSession mailboxSession, ICorePropertyBag itemPropertyBag, ConversationIndex.FixupStage fixupStage, ConversationIndex conversationIndex, out byte[] conversationCreatorSid)
 {
     conversationCreatorSid = null;
     if (!ConversationCreatorHelper.SupportsConversationCreator(mailboxSession) || itemPropertyBag.GetValueOrDefault <bool>(InternalSchema.DeleteAfterSubmit, false))
     {
         return(false);
     }
     conversationCreatorSid = ConversationCreatorHelper.CalculateConversationCreatorSid(mailboxSession, itemPropertyBag, fixupStage, conversationIndex, ValueConvertor.ConvertValueToBinary(mailboxSession.MailboxOwner.Sid, null));
     return(conversationCreatorSid != null);
 }
Ejemplo n.º 23
0
 private static StoreObjectType?TryDetectRightsManagementStoreObjectType(ICorePropertyBag propertyBag, string itemClass, StoreObjectType detectedType)
 {
     if (detectedType != StoreObjectType.Message || !ObjectClass.IsRightsManagedContentClass(propertyBag.GetValueOrDefault <string>(CoreObjectSchema.ContentClass, null)))
     {
         return(null);
     }
     return(new StoreObjectType?(StoreObjectType.RightsManagedMessage));
 }
Ejemplo n.º 24
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);
        }
Ejemplo n.º 25
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);
        }
Ejemplo n.º 26
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;
            }
        }
Ejemplo n.º 27
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);
        }