RuleSetGetSafeHtmlRules Method |
Returns a set of rules which specify removing of all potentially unsafe content from the HTML document.
Namespace: MailBee.HtmlAssembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax public static RuleSet GetSafeHtmlRules()
Public Shared Function GetSafeHtmlRules As RuleSet
Return Value
Type:
RuleSetA
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.
using System;
using MailBee.Mime;
using MailBee.Html;
class Sample
{
static void Main(string[] args)
{
MailMessage message = new MailMessage();
message.LoadMessage(@"C:\Temp\message.eml");
Processor htmlProcessor = new Processor();
htmlProcessor.Dom.OuterHtml = message.BodyHtmlText;
RuleSet rules = RuleSet.GetSafeHtmlRules();
Console.WriteLine(htmlProcessor.Dom.ProcessToString(rules, null));
}
}
Imports System
Imports MailBee.Mime
Imports MailBee.Html
Module Sample
Sub Main()
Dim message As New MailMessage
message.LoadMessage("C:\Temp\message.eml")
Dim htmlProcessor As New Processor
htmlProcessor.Dom.OuterHtml = message.BodyHtmlText
Dim rules As RuleSet = RuleSet.GetSafeHtmlRules()
Console.WriteLine(htmlProcessor.Dom.ProcessToString(rules, Nothing))
End Sub
End Module
See Also