MailBee.NET Objects 7.1

RuleSet.GetSafeHtmlRules Method 

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

public static RuleSet GetSafeHtmlRules();

Return Value

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 or ProcessToString method, it will perform the following actions:

Example

This sample applies the safe-HTML rules to clean up the HTML message.

[C#]
// 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:\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));
    }
}
[Visual Basic]
' To use the code below, import these namespaces at the top of your code.
Imports System
Imports MailBee.Mime
Imports MailBee.Html

Module Sample
    Sub Main()
        ' Load HTML message from file.
        Dim message As New MailMessage
        message.LoadMessage("C:\message.eml")

        Dim htmlProcessor As New Processor

        htmlProcessor.Dom.OuterHtml = message.BodyHtmlText

        ' Get rules for removing all uneasy things (such as scripts) from the body.
        Dim rules As RuleSet = RuleSet.GetSafeHtmlRules()

        ' Process the rules and display the results.
        Console.WriteLine(htmlProcessor.Dom.ProcessToString(rules, Nothing))
    End Sub
End Module

See Also

RuleSet Class | MailBee.Html Namespace