Exemplo n.º 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));
        }
Exemplo n.º 2
0
 internal FragmentInfo(ConversationBodyScanner bodyScanner)
 {
     this.startLineIndex = 0;
     this.startWordIndex = 0;
     this.endLineIndex   = bodyScanner.Lines.Count;
     this.endWordIndex   = bodyScanner.Words.Count;
     this.bodyScanner    = bodyScanner;
 }
Exemplo n.º 3
0
 internal static bool IsBlankLine(ConversationBodyScanner bodyScanner, int lineIndex)
 {
     if (lineIndex < 0 || lineIndex >= bodyScanner.Lines.Count)
     {
         return(false);
     }
     ConversationBodyScanner.Scanner.LineCategory category = bodyScanner.Lines[lineIndex].Category;
     return(category == ConversationBodyScanner.Scanner.LineCategory.Blank || category == ConversationBodyScanner.Scanner.LineCategory.HorizontalLineDelimiter || category == ConversationBodyScanner.Scanner.LineCategory.Skipped);
 }
Exemplo n.º 4
0
 internal FragmentInfo(ConversationBodyScanner bodyScanner, int startLineIndex, int endLineIndex)
 {
     this.bodyScanner    = bodyScanner;
     this.startLineIndex = startLineIndex;
     this.endLineIndex   = endLineIndex;
     if (bodyScanner == null)
     {
         this.startWordIndex = (this.endWordIndex = 0);
         return;
     }
     this.startWordIndex = this.GetFirstWordIndex(this.StartLineIndex);
     this.endWordIndex   = this.GetFirstWordIndex(this.EndLineIndex);
 }
Exemplo n.º 5
0
 internal static void TrimBoundary(ConversationBodyScanner bodyScanner, ref int startLineIndex, ref int endLineIndex)
 {
     while (endLineIndex > startLineIndex)
     {
         if (!FragmentInfo.IsBlankLine(bodyScanner, startLineIndex))
         {
             break;
         }
         startLineIndex++;
     }
     while (endLineIndex > startLineIndex && FragmentInfo.IsBlankLine(bodyScanner, endLineIndex - 1))
     {
         endLineIndex--;
     }
 }
Exemplo n.º 6
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]);
 }
Exemplo n.º 7
0
        public ConversationBodyScanner GetConversationBodyScanner(HtmlCallbackBase callback, long maxBytes, long bytesLoaded, bool fixCharset, bool filterHtml, out long bytesRead)
        {
            ConversationBodyScanner conversationBodyScanner = null;
            StorePropertyDefinition bodyProperty            = null;
            BodyFormat bodyFormat;

            if (fixCharset)
            {
                bodyFormat = this.RawFormat;
            }
            else
            {
                bodyFormat = this.Format;
            }
            switch (bodyFormat)
            {
            case BodyFormat.TextPlain:
            {
                TextConversationBodyScanner textConversationBodyScanner = new TextConversationBodyScanner();
                conversationBodyScanner = textConversationBodyScanner;
                if (fixCharset)
                {
                    textConversationBodyScanner.InputEncoding = ConvertUtils.UnicodeEncoding;
                }
                else
                {
                    textConversationBodyScanner.InputEncoding = this.GetBodyEncoding();
                }
                if (this.IsRtfEmbeddedBody)
                {
                    bodyProperty = ItemSchema.RtfBody;
                }
                else
                {
                    bodyProperty = ItemSchema.TextBody;
                }
                break;
            }

            case BodyFormat.TextHtml:
            {
                HtmlConversationBodyScanner htmlConversationBodyScanner = new HtmlConversationBodyScanner();
                conversationBodyScanner = htmlConversationBodyScanner;
                htmlConversationBodyScanner.InputEncoding             = this.GetBodyEncoding();
                htmlConversationBodyScanner.DetectEncodingFromMetaTag = false;
                bodyProperty = ItemSchema.HtmlBody;
                break;
            }

            case BodyFormat.ApplicationRtf:
                conversationBodyScanner = new RtfConversationBodyScanner();
                bodyProperty            = ItemSchema.RtfBody;
                break;
            }
            conversationBodyScanner.FilterHtml = filterHtml;
            if (callback != null)
            {
                conversationBodyScanner.HtmlCallback = new HtmlTagCallback(callback.ProcessTag);
            }
            if (this.IsBodyDefined)
            {
                using (Stream stream = this.InternalOpenBodyStream(bodyProperty, PropertyOpenMode.ReadOnly))
                {
                    bytesRead = stream.Length;
                    if (maxBytes > -1L && bytesRead + bytesLoaded > maxBytes)
                    {
                        throw new MessageLoadFailedInConversationException(new LocalizedString("Message body size exceeded the conversation threshold for loading"));
                    }
                    if (this.RawFormat == BodyFormat.ApplicationRtf)
                    {
                        using (Stream stream2 = new ConverterStream(stream, new RtfCompressedToRtf(), ConverterStreamAccess.Read))
                        {
                            conversationBodyScanner.Load(stream2);
                            goto IL_12F;
                        }
                    }
                    conversationBodyScanner.Load(stream);
IL_12F:
                    return(conversationBodyScanner);
                }
            }
            bytesRead = 0L;
            MemoryStream sourceStream = new MemoryStream(0);

            conversationBodyScanner.Load(sourceStream);
            return(conversationBodyScanner);
        }
Exemplo n.º 8
0
		public BodyFragmentInfo(ConversationBodyScanner bodyScanner) : base(bodyScanner, 0, bodyScanner.Lines.Count)
		{
		}
Exemplo n.º 9
0
		internal BodyFragmentInfo(ConversationBodyScanner bodyScanner, int startLineIndex, int endLineIndex) : base(bodyScanner, startLineIndex, endLineIndex)
		{
		}
Exemplo n.º 10
0
 public BodyDiffer(ConversationBodyScanner parentScanner, ConversationBodyScanner childScanner)
 {
     this.childBodyFragment  = new BodyFragmentInfo(childScanner);
     this.parentBodyFragment = new BodyFragmentInfo(parentScanner);
     this.WordByWordDiff();
 }
Exemplo n.º 11
0
        private bool TryLoadBodyScanner(IItem item, HtmlStreamOptionCallback callback, long bytesLoadedForConversation, bool isIrmEnabled, out ConversationBodyScanner bodyScanner, out long bytesRead)
        {
            bodyScanner = null;
            Item item2 = null;

            bytesRead = 0L;
            Body body = item.Body;

            if (body == null)
            {
                ExTraceGlobals.ConversationTracer.TraceError(0L, "ConversationDataExtractor::LoadBodyScanner: ConversationItem has no body");
                return(false);
            }
            try
            {
                if (ObjectClass.IsSmime(item.ClassName) && !ObjectClass.IsSmimeClearSigned(item.ClassName) && item is MessageItem)
                {
                    if (ItemConversion.TryOpenSMimeContent((MessageItem)item, ConvertUtils.GetInboundConversionOptions(), out item2))
                    {
                        body = item2.Body;
                    }
                }
                else if (isIrmEnabled)
                {
                    body = this.GetBodyFromRightsManagedMessageItem(item);
                }
                if (body != null)
                {
                    if (callback != null)
                    {
                        KeyValuePair <HtmlStreamingFlags, HtmlCallbackBase> keyValuePair = callback((Item)item);
                        bodyScanner = body.GetConversationBodyScanner(keyValuePair.Value, ConversationDataExtractor.MaxBytesForConversation, bytesLoadedForConversation, true, keyValuePair.Key == HtmlStreamingFlags.FilterHtml, out bytesRead);
                    }
                    else
                    {
                        bodyScanner = body.GetConversationBodyScanner(null, ConversationDataExtractor.MaxBytesForConversation, bytesLoadedForConversation, true, true, out bytesRead);
                    }
                }
                else
                {
                    ExTraceGlobals.ConversationTracer.TraceError(0L, "ConversationDataExtractor::LoadBodyScanner: ConversationItem has no body");
                }
            }
            catch (ObjectNotFoundException)
            {
                ExTraceGlobals.ConversationTracer.TraceError(0L, "ObjectNotFoundException thrown from ConversationDataExtractor::LoadBodyScanner");
                bodyScanner = null;
                bytesRead   = 0L;
            }
            catch (TextConvertersException)
            {
                ExTraceGlobals.ConversationTracer.TraceError(0L, "TextConvertersException thrown from Body::GetConversationBodyScanner");
                bodyScanner = null;
                bytesRead   = 0L;
            }
            catch (MessageLoadFailedInConversationException)
            {
                ExTraceGlobals.ConversationTracer.TraceError(0L, "MessageLoadFailedInConversationException thrown from Body::GetConversationBodyScanner");
                bodyScanner = null;
                bytesRead   = 0L;
            }
            finally
            {
                if (item2 != null)
                {
                    item2.Dispose();
                    item2 = null;
                }
            }
            return(bodyScanner != null);
        }