Ejemplo n.º 1
0
        protected BodyConversionCallbacks GetCallbacksInternal(Body defaultItemBody, AttachmentCollection defaultAttachmentCollection)
        {
            BodyConversionCallbacks result = default(BodyConversionCallbacks);

            if (this.parameters.HtmlCallbacks != null)
            {
                result.HtmlCallback = this.parameters.HtmlCallbacks;
            }
            else
            {
                DefaultHtmlCallbacks defaultHtmlCallbacks = new DefaultHtmlCallbacks(defaultAttachmentCollection.CoreAttachmentCollection, defaultItemBody, true);
                if (this.parameters.ConversionOptionsForSmime != null && !this.parameters.ConversionOptionsForSmime.IgnoreImceaDomain && this.parameters.ConversionOptionsForSmime.ImceaEncapsulationDomain != null)
                {
                    defaultHtmlCallbacks.SetContentIdDomain(this.parameters.ConversionOptionsForSmime.ImceaEncapsulationDomain);
                }
                defaultHtmlCallbacks.ClearingEmptyLinks = true;
                defaultHtmlCallbacks.RemoveLinksToNonImageAttachments = true;
                result.HtmlCallback = defaultHtmlCallbacks;
            }
            if (this.parameters.RtfCallbacks != null)
            {
                result.RtfCallback = this.parameters.RtfCallbacks;
            }
            else if (this.parameters.TargetFormat == BodyFormat.ApplicationRtf && this.originalItem.Body.Format == BodyFormat.TextHtml)
            {
                result.RtfCallback = new DefaultRtfCallbacks(defaultAttachmentCollection.CoreAttachmentCollection, defaultItemBody, true);
            }
            return(result);
        }
Ejemplo n.º 2
0
 public static bool IsInlineImage(string contentType, string fileExtension)
 {
     if (contentType != null && DefaultHtmlCallbacks.IsInlineImage(contentType))
     {
         return(true);
     }
     if (fileExtension != null)
     {
         contentType = Attachment.CalculateContentType(fileExtension);
         return(DefaultHtmlCallbacks.IsInlineImage(contentType));
     }
     return(false);
 }
Ejemplo n.º 3
0
        private static ConversionCallbackBase CreateConversionDelegateProvider(ICoreItem coreItem, BodyReadConfiguration configuration)
        {
            ConversionCallbackBase conversionCallbackBase;

            if (coreItem.Body.RawFormat == BodyFormat.ApplicationRtf && configuration.Format == BodyFormat.TextHtml)
            {
                if (configuration.HtmlCallback == null)
                {
                    conversionCallbackBase = new DefaultHtmlCallbacks(coreItem, false)
                    {
                        ClearInlineOnUnmarkedAttachments = false
                    };
                    configuration.ConversionCallback = conversionCallbackBase;
                }
                else
                {
                    conversionCallbackBase = configuration.ConversionCallback;
                }
            }
            else if (coreItem.Body.RawFormat == BodyFormat.TextHtml && configuration.Format == BodyFormat.ApplicationRtf)
            {
                if (configuration.ImageRenderingCallback == null)
                {
                    conversionCallbackBase = new DefaultRtfCallbacks(coreItem, false)
                    {
                        ClearInlineOnUnmarkedAttachments = false
                    };
                    configuration.ConversionCallback = conversionCallbackBase;
                }
                else
                {
                    conversionCallbackBase = configuration.ConversionCallback;
                }
            }
            else
            {
                conversionCallbackBase = null;
            }
            return(conversionCallbackBase);
        }
Ejemplo n.º 4
0
        public override void ProcessTag(HtmlTagContext tagContext, HtmlWriter htmlWriter)
        {
            if (tagContext.TagId != HtmlTagId.Img)
            {
                tagContext.WriteTag(true);
                return;
            }
            AttachmentLink attachmentLink = null;
            string         text           = null;

            foreach (HtmlTagContextAttribute htmlTagContextAttribute in tagContext.Attributes)
            {
                if (htmlTagContextAttribute.Id == HtmlAttributeId.Src)
                {
                    text = htmlTagContextAttribute.Value;
                    break;
                }
            }
            if (!string.IsNullOrEmpty(text))
            {
                attachmentLink = base.FindAttachmentByBodyReference(text);
            }
            if (attachmentLink == null)
            {
                if (!this.clearEmptyLinks || !DefaultHtmlCallbacks.IsEmptyLink(text))
                {
                    tagContext.WriteTag(true);
                }
                return;
            }
            string text2;
            string text3;

            if (attachmentLink.AttachmentType == AttachmentType.Ole)
            {
                text2 = "image/jpeg";
                text3 = "jpg";
                attachmentLink.ConvertToImage();
            }
            else
            {
                text2 = attachmentLink.ContentType;
                text3 = attachmentLink.FileExtension;
            }
            bool flag = text.StartsWith("cid:Microsoft-Infopath-", StringComparison.OrdinalIgnoreCase) && string.IsNullOrEmpty(text3) && !string.IsNullOrEmpty(text2) && text2.Equals("application/octet-stream");

            if (DefaultHtmlCallbacks.IsInlineImage(text2, text3) || flag)
            {
                tagContext.WriteTag(false);
                foreach (HtmlTagContextAttribute htmlTagContextAttribute2 in tagContext.Attributes)
                {
                    if (htmlTagContextAttribute2.Id == HtmlAttributeId.Src)
                    {
                        string value = "cid:" + this.GetOrGenerateAttachContentId(attachmentLink);
                        htmlWriter.WriteAttribute(HtmlAttributeId.Src, value);
                    }
                    else
                    {
                        htmlTagContextAttribute2.Write();
                    }
                }
                attachmentLink.MarkInline(true);
                return;
            }
            if (!this.RemoveLinksToNonImageAttachments)
            {
                string text4 = attachmentLink.Filename;
                if (text4 == null)
                {
                    text4 = ServerStrings.DefaultHtmlAttachmentHrefText;
                }
                htmlWriter.WriteStartTag(HtmlTagId.A);
                htmlWriter.WriteAttribute(HtmlAttributeId.Href, "cid:" + this.GetOrGenerateAttachContentId(attachmentLink));
                htmlWriter.WriteText(text4);
                htmlWriter.WriteEndTag(HtmlTagId.A);
                attachmentLink.MarkInline(false);
            }
        }