示例#1
0
        private LoadedItemPart CreateLoadedItemPart(IItem item, IStorePropertyBag propertyBagFromTree, HtmlStreamOptionCallback htmlCallback, PropertyDefinition[] additionalPropertyDefinitions, ItemPartIrmInfo itemPartIrmInfo, bool isIrmEnabled, long bytesLoadedForConversation, bool isSmimeSupported, string domainName)
        {
            ConversationBodyScanner bodyScanner = null;
            long bytesLoaded = 0L;

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

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

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

            if (isSmimeSupported && ObjectClass.IsSmimeClearSigned(itemClass))
            {
                this.InitializeSmimeInfo(item, domainName, out attachmentCollection);
            }
            return(new LoadedItemPart(item, propertyBag, bodyFragmentInfo, loadedProperties, itemPartIrmInfo, didLoadSucceed, bytesLoaded, attachmentCollection));
        }
        public ItemPart GetItemPart(IConversationTree conversationTree, StoreObjectId itemId)
        {
            IStorePropertyBag     propertyBag          = null;
            ItemPart              itemPart             = null;
            IConversationTreeNode conversationTreeNode = null;

            if (!conversationTree.TryGetConversationTreeNode(itemId, out conversationTreeNode) || !conversationTreeNode.TryGetPropertyBag(itemId, out propertyBag))
            {
                throw new ArgumentException("No ConversationTreeNode/PropertyBag can be found for the passed StoreObjectId");
            }
            if (!this.itemParts.TryGetValue(itemId, out itemPart))
            {
                this.LoadItemPart(conversationTree, propertyBag);
                itemPart = this.loadedItemParts[itemId];
            }
            if (itemPart is LoadedItemPart && !itemPart.DidLoadSucceed)
            {
                return(itemPart);
            }
            if (itemPart.UniqueFragmentInfo == null)
            {
                LoadedItemPart loadedItemPart = (LoadedItemPart)itemPart;
                ExtractionData extractionData;
                if (!this.CanSkipDiffing(conversationTree, loadedItemPart, out extractionData))
                {
                    BodyFragmentInfo parentBodyFragment = null;
                    if (conversationTreeNode.ParentNode.HasData)
                    {
                        StoreObjectId mainStoreObjectId = conversationTreeNode.ParentNode.MainStoreObjectId;
                        if (this.treeNodeBodyFragment.ContainsKey(mainStoreObjectId))
                        {
                            parentBodyFragment = this.treeNodeBodyFragment[mainStoreObjectId].Key;
                        }
                        else
                        {
                            LoadedItemPart loadedItemPart2 = null;
                            if (!this.loadedItemParts.TryGetValue(mainStoreObjectId, out loadedItemPart2))
                            {
                                IStorePropertyBag propertyBag2;
                                if (!conversationTreeNode.ParentNode.TryGetPropertyBag(mainStoreObjectId, out propertyBag2))
                                {
                                    throw new ArgumentException("No Property bag can be found for the passed StoreObjectId on the ParentNode");
                                }
                                this.LoadItemPart(conversationTree, propertyBag2);
                                loadedItemPart2 = this.loadedItemParts[mainStoreObjectId];
                            }
                            parentBodyFragment = loadedItemPart2.BodyFragmentInfo;
                        }
                    }
                    ConversationDataExtractor.DiffItemParts(parentBodyFragment, loadedItemPart);
                }
                else
                {
                    itemPart.UniqueFragmentInfo     = extractionData.ChildUniqueBody;
                    itemPart.DisclaimerFragmentInfo = extractionData.ChildDisclaimer;
                }
            }
            return(itemPart);
        }
        public bool IsBodyPartPresent(BodyFragmentInfo childBodyFragment, IStorePropertyBag parentPropertyBag, bool ignoreCache, out ExtractionData extractionData)
        {
            StoreObjectId objectId = ((VersionedId)parentPropertyBag.TryGetProperty(ItemSchema.Id)).ObjectId;
            KeyValuePair <ConversationBodyScanner, StoreObjectId> key = new KeyValuePair <ConversationBodyScanner, StoreObjectId>(childBodyFragment.BodyScanner, objectId);

            if (this.loadStatus.TryGetValue(key, out extractionData))
            {
                bool flag = extractionData != null && extractionData.BodyFragment != null;
                if (flag || !ignoreCache)
                {
                    return(flag);
                }
            }
            if (!ignoreCache && this.loadedItemParts.ContainsKey(objectId))
            {
                extractionData = new ExtractionData();
            }
            else
            {
                byte[] array = parentPropertyBag.TryGetProperty(ItemSchema.BodyTag) as byte[];
                if (array == null && ignoreCache)
                {
                    LoadedItemPart loadedItemPart = null;
                    if (this.loadedItemParts.TryGetValue(objectId, out loadedItemPart) && loadedItemPart.BodyFragmentInfo != null && loadedItemPart.BodyFragmentInfo.BodyTag != null)
                    {
                        array = loadedItemPart.BodyFragmentInfo.BodyTag.ToByteArray();
                    }
                }
                this.optimizationInfo.IncrementBodyTagMatchingAttempts();
                if (array != null)
                {
                    extractionData = new ExtractionData(childBodyFragment, BodyTagInfo.FromByteArray(array));
                    if (extractionData.BodyFragment != null)
                    {
                        this.loadStatus[key] = extractionData;
                        if (!extractionData.IsFormatReliable)
                        {
                            this.optimizationInfo.UpdateItemBodyFormatMismatched(objectId);
                            this.optimizationInfo.IncrementBodyTagMatchingIssues();
                        }
                    }
                    else
                    {
                        this.optimizationInfo.UpdateItemBodyTagMismatched(objectId);
                        this.optimizationInfo.IncrementBodyTagMatchingIssues();
                    }
                }
                else
                {
                    extractionData = new ExtractionData();
                    this.optimizationInfo.UpdateItemBodyTagNotPresent(objectId);
                    this.optimizationInfo.IncrementBodyTagMatchingIssues();
                }
            }
            this.loadStatus[key] = extractionData;
            return(extractionData.BodyFragment != null);
        }
 private static void DiffItemParts(BodyFragmentInfo parentBodyFragment, LoadedItemPart childItemPart)
 {
     if (childItemPart.UniqueFragmentInfo != null)
     {
         return;
     }
     if (parentBodyFragment != null)
     {
         BodyDiffer bodyDiffer = new BodyDiffer(childItemPart.BodyFragmentInfo, parentBodyFragment);
         childItemPart.UniqueFragmentInfo     = bodyDiffer.UniqueBodyPart;
         childItemPart.DisclaimerFragmentInfo = bodyDiffer.DisclaimerPart;
         return;
     }
     childItemPart.UniqueFragmentInfo     = childItemPart.BodyFragmentInfo.Trim();
     childItemPart.DisclaimerFragmentInfo = FragmentInfo.Empty;
 }
示例#5
0
 public byte[] CalculateBodyTag(out int latestMessagePartWordCount)
 {
     latestMessagePartWordCount = int.MinValue;
     if (this.IsBodyDefined && this.Size / 2048L <= 2048L)
     {
         try
         {
             ConversationBodyScanner conversationBodyScanner = this.GetConversationBodyScanner();
             latestMessagePartWordCount = conversationBodyScanner.CalculateLatestMessagePartWordCount();
             BodyFragmentInfo bodyFragmentInfo = new BodyFragmentInfo(conversationBodyScanner);
             return(bodyFragmentInfo.BodyTag.ToByteArray());
         }
         catch (TextConvertersException)
         {
             return(new byte[Body.BodyTagLength]);
         }
     }
     if (ObjectClass.IsSmime(this.coreItem.ClassName()) && !ObjectClass.IsSmimeClearSigned(this.coreItem.ClassName()))
     {
         Item item = null;
         try
         {
             InboundConversionOptions inboundConversionOptions = ConvertUtils.GetInboundConversionOptions();
             if (ItemConversion.TryOpenSMimeContent(this.coreItem, inboundConversionOptions, out item))
             {
                 return(item.Body.CalculateBodyTag(out latestMessagePartWordCount));
             }
         }
         finally
         {
             if (item != null)
             {
                 item.Dispose();
             }
         }
     }
     return(new byte[12]);
 }
示例#6
0
 public ExtractionData(BodyFragmentInfo childFragment, BodyTagInfo parentBodyTag)
 {
     childFragment.ExtractNestedBodyParts(parentBodyTag, out this.bodyFragment, out this.childUniqueBody, out this.childDisclaimer);
     this.originalTagInfo = parentBodyTag;
 }
示例#7
0
 internal LoadedItemPart(IItem item, IStorePropertyBag propertyBag, BodyFragmentInfo bodyFragmentInfo, PropertyDefinition[] loadedProperties, ItemPartIrmInfo irmInfo, bool didLoadSucceed, long bytesLoaded, AttachmentCollection attachmentCollection) : base(loadedProperties)
 {
     this.irmInfo = irmInfo;
     this.InitializeLoadedItemPart(item, propertyBag, bodyFragmentInfo, didLoadSucceed, bytesLoaded, attachmentCollection);
 }
示例#8
0
        private void InitializeLoadedItemPart(IItem item, IStorePropertyBag propertyBag, BodyFragmentInfo bodyFragmentInfo, bool didLoadSucceed, long bytesLoaded, AttachmentCollection attachmentCollection)
        {
            this.bodyFragmentInfo = bodyFragmentInfo;
            if (this.bodyFragmentInfo == null)
            {
                base.UniqueFragmentInfo = (base.DisclaimerFragmentInfo = FragmentInfo.Empty);
            }
            this.didLoadSucceed = didLoadSucceed;
            if (this.didLoadSucceed)
            {
                this.bytesLoaded = bytesLoaded;
            }
            base.ItemId  = item.Id.ObjectId;
            base.Subject = (item.TryGetProperty(ItemSchema.Subject) as string);
            if (attachmentCollection != null)
            {
                foreach (AttachmentHandle handle in attachmentCollection)
                {
                    using (Attachment attachment = attachmentCollection.Open(handle, null))
                    {
                        base.RawAttachments.Add(new AttachmentInfo(item.Id.ObjectId, attachment));
                    }
                }
            }
            IMessageItem messageItem = item as IMessageItem;

            if (messageItem != null)
            {
                if (messageItem.Sender != null)
                {
                    this.displayNameToParticipant[messageItem.Sender.DisplayName] = messageItem.Sender;
                }
                if (messageItem.From != null)
                {
                    this.displayNameToParticipant[messageItem.From.DisplayName] = messageItem.From;
                }
                foreach (Recipient recipient in messageItem.Recipients)
                {
                    recipient.Participant.Submitted = recipient.Submitted;
                    this.displayNameToParticipant[recipient.Participant.DisplayName] = recipient.Participant;
                    base.Recipients.Add(recipient.RecipientItemType, new IParticipant[]
                    {
                        recipient.Participant
                    });
                }
                foreach (Participant participant in messageItem.ReplyTo)
                {
                    this.displayNameToParticipant[participant.DisplayName] = participant;
                }
            }
            if (propertyBag != null)
            {
                base.StorePropertyBag = propertyBag;
            }
        }
        private void RecursiveLoadBodyFragments(IConversationTree conversationTree, IConversationTreeNode treeNode, ICollection <StoreObjectId> itemPartsToLoad, out bool forceParentLoadBodyFragment)
        {
            IStorePropertyBag storePropertyBag = null;
            StoreObjectId     storeObjectId    = null;

            forceParentLoadBodyFragment = false;
            if (treeNode.HasData)
            {
                foreach (IStorePropertyBag storePropertyBag2 in treeNode.StorePropertyBags)
                {
                    StoreObjectId objectId = ((VersionedId)storePropertyBag2.TryGetProperty(ItemSchema.Id)).ObjectId;
                    storePropertyBag = storePropertyBag2;
                    storeObjectId    = objectId;
                    if (itemPartsToLoad == null || itemPartsToLoad.Contains(objectId))
                    {
                        forceParentLoadBodyFragment = true;
                        break;
                    }
                }
            }
            BodyFragmentInfo bodyFragmentInfo = null;
            bool             flag             = false;
            bool             flag2            = false;

            foreach (IConversationTreeNode conversationTreeNode in treeNode.ChildNodes)
            {
                ConversationTreeNode conversationTreeNode2 = (ConversationTreeNode)conversationTreeNode;
                bool flag3;
                this.RecursiveLoadBodyFragments(conversationTree, conversationTreeNode2, itemPartsToLoad, out flag3);
                flag2 = (flag2 || flag3);
                if (storePropertyBag != null)
                {
                    if (this.itemParts.ContainsKey(storeObjectId))
                    {
                        flag             = true;
                        bodyFragmentInfo = (this.treeNodeBodyFragment.ContainsKey(treeNode.MainStoreObjectId) ? this.treeNodeBodyFragment[treeNode.MainStoreObjectId].Key : null);
                    }
                    else if (this.treeNodeBodyFragment.ContainsKey(conversationTreeNode2.MainStoreObjectId))
                    {
                        ExtractionData extractionData;
                        this.IsBodyPartPresent(this.treeNodeBodyFragment[conversationTreeNode2.MainStoreObjectId].Key, storePropertyBag, out extractionData);
                        if (extractionData != null && extractionData.BodyFragment != null)
                        {
                            if (!flag && extractionData.IsFormatReliable)
                            {
                                bodyFragmentInfo = extractionData.BodyFragment;
                                flag             = true;
                            }
                            else if (bodyFragmentInfo == null)
                            {
                                bodyFragmentInfo = extractionData.BodyFragment;
                            }
                        }
                    }
                }
            }
            if (!treeNode.HasData)
            {
                return;
            }
            bool flag4 = false;

            if (itemPartsToLoad != null && itemPartsToLoad.Contains(storeObjectId) && !flag)
            {
                flag4 = true;
            }
            else if (bodyFragmentInfo == null && (forceParentLoadBodyFragment || flag2))
            {
                flag4 = true;
            }
            if (flag4 && !this.loadedItemParts.ContainsKey(storeObjectId))
            {
                this.LoadItemPart(conversationTree, storePropertyBag);
            }
            if (this.loadedItemParts.ContainsKey(storeObjectId))
            {
                LoadedItemPart loadedItemPart = this.loadedItemParts[storeObjectId];
                if (this.InternalHasIrmFailed(storeObjectId))
                {
                    bodyFragmentInfo = null;
                }
                else
                {
                    bodyFragmentInfo = loadedItemPart.BodyFragmentInfo;
                    flag             = true;
                }
            }
            if (bodyFragmentInfo != null)
            {
                this.treeNodeBodyFragment[treeNode.MainStoreObjectId] = new KeyValuePair <BodyFragmentInfo, bool>(bodyFragmentInfo, flag);
            }
        }
 private void LoadItemPartsOrBodySummaries(IConversationTree conversationTree, ICollection <StoreObjectId> storeIds)
 {
     conversationTree.ExecuteSortedAction(ConversationTreeSortOrder.ChronologicalDescending, delegate(ConversationTreeSortOrder param0)
     {
         HashSet <StoreObjectId> hashSet = null;
         if (storeIds != null && storeIds.Any <StoreObjectId>())
         {
             hashSet = new HashSet <StoreObjectId>(storeIds);
         }
         this.RecursiveLoadBodyFragments(conversationTree, hashSet);
         foreach (IConversationTreeNode conversationTreeNode in conversationTree)
         {
             if (!this.treeNodeBodyFragment.ContainsKey(conversationTreeNode.MainStoreObjectId))
             {
                 for (int i = 0; i < conversationTreeNode.StorePropertyBags.Count; i++)
                 {
                     IStorePropertyBag storePropertyBag = conversationTreeNode.StorePropertyBags[i];
                     this.AddBodySummaryError(conversationTree, ref storePropertyBag);
                 }
             }
             else
             {
                 FragmentInfo fragmentInfo         = FragmentInfo.Empty;
                 FragmentInfo disclaimerFragment   = FragmentInfo.Empty;
                 BodyFragmentInfo bodyFragmentInfo = this.treeNodeBodyFragment[conversationTreeNode.MainStoreObjectId].Key;
                 fragmentInfo = bodyFragmentInfo;
                 if (conversationTreeNode.ParentNode.HasData && this.treeNodeBodyFragment.ContainsKey(conversationTreeNode.ParentNode.MainStoreObjectId))
                 {
                     BodyFragmentInfo key = this.treeNodeBodyFragment[conversationTreeNode.ParentNode.MainStoreObjectId].Key;
                     ExtractionData extractionData;
                     if (this.IsBodyPartPresent(bodyFragmentInfo, conversationTreeNode.ParentNode.StorePropertyBags[0], out extractionData))
                     {
                         fragmentInfo       = extractionData.ChildUniqueBody;
                         disclaimerFragment = extractionData.ChildDisclaimer;
                     }
                     else
                     {
                         BodyDiffer bodyDiffer = new BodyDiffer(bodyFragmentInfo, key);
                         fragmentInfo          = bodyDiffer.UniqueBodyPart;
                         disclaimerFragment    = bodyDiffer.DisclaimerPart;
                     }
                 }
                 for (int j = 0; j < conversationTreeNode.StorePropertyBags.Count; j++)
                 {
                     IStorePropertyBag storePropertyBag2 = conversationTreeNode.StorePropertyBags[j];
                     StoreObjectId objectId = ((VersionedId)storePropertyBag2.TryGetProperty(ItemSchema.Id)).ObjectId;
                     this.AddBodySummary(conversationTree, ref storePropertyBag2, fragmentInfo);
                     if (!conversationTreeNode.HasChildren)
                     {
                         this.OptimizationCounters.UpdateItemIsLeafNode(objectId);
                     }
                     if (!this.itemParts.ContainsKey(objectId))
                     {
                         ParticipantTable recipients;
                         List <Participant> replyToParticipants;
                         if (this.treeNodeBodyFragment[conversationTreeNode.MainStoreObjectId].Value && this.CanExtractItemPart(conversationTree, storePropertyBag2, out recipients, out replyToParticipants))
                         {
                             this.optimizationInfo.UpdateItemExtracted(objectId);
                             ItemPart itemPart = this.itemPartLoader.Create(objectId, storePropertyBag2, fragmentInfo, disclaimerFragment, recipients, replyToParticipants);
                             this.itemParts.Add(objectId, itemPart);
                             this.AddRecipientToRecipientDisplayNameCache(itemPart);
                         }
                         else if (hashSet != null && hashSet.Contains(objectId))
                         {
                             this.LoadItemPart(conversationTree, storePropertyBag2);
                             bodyFragmentInfo = this.loadedItemParts[objectId].BodyFragmentInfo;
                         }
                     }
                 }
             }
         }
     });
 }
 private bool IsBodyPartPresent(BodyFragmentInfo childBodyFragment, IStorePropertyBag parentPropertyBag, out ExtractionData extractionData)
 {
     return(this.IsBodyPartPresent(childBodyFragment, parentPropertyBag, false, out extractionData));
 }