public override void ProcessTag(HtmlTagContext context, HtmlWriter writer)
        {
            bool           flag           = false;
            bool           flag2          = false;
            bool           flag3          = false;
            bool           flag4          = false;
            string         text           = null;
            string         text2          = null;
            string         text3          = null;
            AttachmentLink attachmentLink = null;

            if (context.TagId == HtmlTagId.Link)
            {
                context.DeleteTag();
                return;
            }
            if (context.TagId == HtmlTagId.Head)
            {
                if (this.owaContext.UserContext.IsBasicExperience || this.bodyFormat != BodyFormat.TextPlain)
                {
                    context.WriteTag(true);
                    return;
                }
                if (!context.IsEndTag)
                {
                    context.WriteTag(true);
                    context.InvokeCallbackForEndTag();
                    return;
                }
                writer.WriteStartTag(HtmlTagId.Style);
                writer.WriteText("div.PlainText ");
                if (ObjectClass.IsSmsMessage(this.objectClass))
                {
                    writer.WriteText(OwaPlainTextStyle.GetStyleFromUserOption(this.owaContext.UserContext.UserOptions));
                }
                else
                {
                    writer.WriteText(OwaPlainTextStyle.GetStyleFromCharset(this.charSet));
                }
                writer.WriteEndTag(HtmlTagId.Style);
                context.WriteTag(true);
                return;
            }
            else
            {
                if (this.isOutputFragment && context.TagId == HtmlTagId.Form)
                {
                    context.DeleteTag();
                    return;
                }
                if (context.TagId == HtmlTagId.Form || (!this.isOutputFragment && OwaSafeHtmlOutboundCallbacks.IsFormElementTag(context.TagId)))
                {
                    this.ProcessUnfragFormTagContext(context, writer);
                    return;
                }
                if (context.TagId == HtmlTagId.Base)
                {
                    foreach (HtmlTagContextAttribute attribute in context.Attributes)
                    {
                        if (OwaSafeHtmlCallbackBase.IsBaseTag(context.TagId, attribute))
                        {
                            string value = attribute.Value;
                            this.baseRef = Utilities.TryParseUri(value);
                            break;
                        }
                    }
                    return;
                }
                foreach (HtmlTagContextAttribute filterAttribute in context.Attributes)
                {
                    if (filterAttribute.Id == HtmlAttributeId.Src || filterAttribute.Id == HtmlAttributeId.Href)
                    {
                        if (context.TagId == HtmlTagId.Img && string.IsNullOrEmpty(filterAttribute.Value))
                        {
                            return;
                        }
                        if (string.CompareOrdinal(filterAttribute.Value, this.inlineRTFattachmentScheme) == 0 || filterAttribute.Value.StartsWith(this.inlineHTMLAttachmentScheme, StringComparison.OrdinalIgnoreCase))
                        {
                            attachmentLink = this.IsInlineImage(filterAttribute);
                            if (attachmentLink == null)
                            {
                                return;
                            }
                            if (context.TagId != HtmlTagId.Img)
                            {
                                writer.WriteEmptyElementTag(HtmlTagId.Img);
                                this.OutputInlineReference(filterAttribute, context, attachmentLink, writer);
                                context.DeleteTag(false);
                                context.DeleteInnerContent();
                                return;
                            }
                            flag2 = true;
                            break;
                        }
                        else
                        {
                            if (string.CompareOrdinal(filterAttribute.Value, this.embeddedRTFImage) == 0)
                            {
                                this.hasRtfEmbeddedImages = true;
                                break;
                            }
                            break;
                        }
                    }
                }
                context.WriteTag();
                foreach (HtmlTagContextAttribute htmlTagContextAttribute in context.Attributes)
                {
                    if (!this.isOutputFragment || htmlTagContextAttribute.Id != HtmlAttributeId.Name || !OwaSafeHtmlOutboundCallbacks.IsFormElementTag(context.TagId))
                    {
                        if (htmlTagContextAttribute.Id == HtmlAttributeId.UseMap)
                        {
                            this.ProcessUseMapAttribute(htmlTagContextAttribute, context, writer);
                        }
                        else if (OwaSafeHtmlCallbackBase.IsUrlTag(context.TagId, htmlTagContextAttribute))
                        {
                            if (!flag)
                            {
                                this.ProcessHtmlUrlTag(htmlTagContextAttribute, context, writer);
                                flag = true;
                            }
                        }
                        else if (OwaSafeHtmlCallbackBase.IsImageTag(context.TagId, htmlTagContextAttribute))
                        {
                            if (htmlTagContextAttribute.Id == HtmlAttributeId.Src && attachmentLink != null)
                            {
                                this.OutputInlineReference(htmlTagContextAttribute, context, attachmentLink, writer);
                            }
                            else
                            {
                                if ((htmlTagContextAttribute.Id != HtmlAttributeId.Src || flag2) && (htmlTagContextAttribute.Id != HtmlAttributeId.DynSrc || flag3) && (htmlTagContextAttribute.Id != HtmlAttributeId.LowSrc || flag4))
                                {
                                    continue;
                                }
                                this.ProcessImageTag(htmlTagContextAttribute, context, writer);
                            }
                            if (htmlTagContextAttribute.Id == HtmlAttributeId.Src)
                            {
                                flag2 = true;
                            }
                            else if (htmlTagContextAttribute.Id == HtmlAttributeId.DynSrc)
                            {
                                flag3 = true;
                            }
                            else if (htmlTagContextAttribute.Id == HtmlAttributeId.LowSrc)
                            {
                                flag4 = true;
                            }
                        }
                        else if (OwaSafeHtmlCallbackBase.IsBackgroundAttribute(htmlTagContextAttribute))
                        {
                            if (this.isOutputFragment && context.TagId == HtmlTagId.Div)
                            {
                                attachmentLink = this.IsInlineImage(htmlTagContextAttribute);
                                if (attachmentLink != null)
                                {
                                    AttachmentPolicy.Level attachmentLevel = this.GetAttachmentLevel(attachmentLink);
                                    if (AttachmentPolicy.Level.Allow == attachmentLevel)
                                    {
                                        writer.WriteAttribute(HtmlAttributeId.Style, "background:url('" + this.GetInlineReferenceUrl(attachmentLevel, attachmentLink, writer) + "');");
                                    }
                                }
                            }
                            else
                            {
                                this.ProcessImageTag(htmlTagContextAttribute, context, writer);
                            }
                        }
                        else if (!OwaSafeHtmlOutboundCallbacks.IsTargetTagInAnchor(context.TagId, htmlTagContextAttribute))
                        {
                            if (OwaSafeHtmlCallbackBase.IsSanitizingAttribute(htmlTagContextAttribute))
                            {
                                if (htmlTagContextAttribute.Id == HtmlAttributeId.Border)
                                {
                                    text = htmlTagContextAttribute.Value;
                                }
                                else if (htmlTagContextAttribute.Id == HtmlAttributeId.Height)
                                {
                                    text2 = htmlTagContextAttribute.Value;
                                }
                                else if (htmlTagContextAttribute.Id == HtmlAttributeId.Width)
                                {
                                    text3 = htmlTagContextAttribute.Value;
                                }
                            }
                            else
                            {
                                htmlTagContextAttribute.Write();
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(text2) && !string.IsNullOrEmpty(text3) && this.hasBlockedImagesInCurrentPass)
                {
                    OwaSafeHtmlOutboundCallbacks.SanitizeImage(writer, text, text2, text3);
                }
                else if (!this.hasBlockedImagesInCurrentPass)
                {
                    if (!string.IsNullOrEmpty(text2))
                    {
                        writer.WriteAttribute(HtmlAttributeId.Height, text2);
                    }
                    if (!string.IsNullOrEmpty(text3))
                    {
                        writer.WriteAttribute(HtmlAttributeId.Width, text3);
                    }
                    if (!string.IsNullOrEmpty(text))
                    {
                        writer.WriteAttribute(HtmlAttributeId.Border, text);
                    }
                }
                if (this.hasFoundNonLocalUrlInCurrentPass)
                {
                    if (this.owaContext.UserContext.IsBasicExperience)
                    {
                        if (!this.hasFoundMailToUrlInCurrentPass || this.openMailtoInNewWindow)
                        {
                            this.WriteSafeTargetBlank(writer);
                        }
                    }
                    else
                    {
                        this.WriteSafeTargetBlank(writer);
                    }
                }
                this.hasBlockedImagesInCurrentPass    = false;
                this.hasFoundNonLocalUrlInCurrentPass = false;
                this.hasFoundMailToUrlInCurrentPass   = false;
                return;
            }
        }
Exemplo n.º 2
0
 public override void ProcessTag(HtmlTagContext context, HtmlWriter writer)
 {
     context.WriteTag(false);
     foreach (HtmlTagContextAttribute htmlTagContextAttribute in context.Attributes)
     {
         if (OwaSafeHtmlCallbackBase.IsUrlTag(context.TagId, htmlTagContextAttribute))
         {
             OwaSafeHtmlInboundCallbacks.RestoreUrl(htmlTagContextAttribute, writer);
         }
         else if (OwaSafeHtmlCallbackBase.IsImageTag(context.TagId, htmlTagContextAttribute) || OwaSafeHtmlCallbackBase.IsBackgroundAttribute(htmlTagContextAttribute))
         {
             this.RestoreInlineAttachment(htmlTagContextAttribute, context, writer);
         }
         else
         {
             htmlTagContextAttribute.Write();
         }
     }
 }