RuleSetGetSafeHtmlRules Method
Returns a set of rules which specify removing of all potentially unsafe content from the HTML document.

Namespace: MailBee.Html
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax
public static RuleSet GetSafeHtmlRules()

Return Value

Type: RuleSet
A RuleSet object containing the rules which cause all potentially unsafe content be removed during processing.
Remarks
If you pass the returned object to Process(RuleSet, ProcessElementDelegate) or ProcessToString(RuleSet, ProcessElementDelegate) method, it will perform the following actions:
  • remove <SCRIPT>...</SCRIPT> tags with all their contents
  • remove <IFRAME>...</IFRAME> tags with all their contents
  • remove <BGSOUND> tags
  • remove <EMBED> tags
  • remove <FRAME> tags
  • remove <FRAMESET>...</FRAMESET> tags with all their contents
  • remove <OBJECT>...</OBJECT> tags with all their contents
  • remove <APPLET>...</APPLET> tags with all their contents
  • remove SRC/LOWSRC attributes from <IMG> and <INPUT> tags if these attributes contain scripts (i.e. the attribute value starts with javascript, vbscript or about)
  • remove HREF attribute from <A> tags if this attribute contains scripts
  • remove contenteditable attribute from any tag
  • remove data* (e.g. dataSrc) attributes from any tag
  • remove on* (e.g. onclick) attributes from any tag
Examples
This sample applies the safe-HTML rules to clean up the HTML message.
// To use the code below, import these namespaces at the top of your code.
using System;
using MailBee.Mime;
using MailBee.Html;

class Sample
{
    static void Main(string[] args)
    {
        // Load HTML message from file.
        MailMessage message = new MailMessage();
        message.LoadMessage(@"C:\Temp\message.eml");

        Processor htmlProcessor = new Processor();

        htmlProcessor.Dom.OuterHtml = message.BodyHtmlText;

        // Get rules for removing all uneasy things (such as scripts) from the body.
        RuleSet rules = RuleSet.GetSafeHtmlRules();

        // Process the rules and display the results.
        Console.WriteLine(htmlProcessor.Dom.ProcessToString(rules, null));
    }
}
See Also