Mime Compliance Options Class
Options that control how a MimeReader reports MIME compliance violations.
Definition
Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public class MimeComplianceOptions- Inheritance
- Object MimeComplianceOptions
Remarks
These options only have an effect when a ComplianceLogger has been set. When no logger is set, no compliance checks are performed at all.
The options are read at the start of each parse operation, so changes made while a message is being parsed take effect from the next parse operation.
Example
C#
// IMimeComplianceLogger receives a MimeComplianceIssue for each violation of the MIME
// specifications that the MimeReader (or MimeParser) encounters while parsing.
class ComplianceReport : IMimeComplianceLogger
{
public readonly List<MimeComplianceIssue> Issues = new List<MimeComplianceIssue> ();
public void Log (in MimeComplianceIssue issue)
{
Issues.Add (issue);
}
}
public static MimeMessage ParseAndReportCompliance (string fileName)
{
using (var stream = File.OpenRead (fileName)) {
var report = new ComplianceReport ();
var parser = new MimeParser (stream, MimeFormat.Entity) {
ComplianceLogger = report,
// Messages from a local message store (such as an mbox or Maildir) are not
// subject to the transport requirements (such as line-length limits) and so
// such violations are rated with a lower severity.
ComplianceContext = MimeComplianceContext.Storage,
// When parsing untrusted messages, limit the number of times that each violation
// may be reported to avoid unbounded memory usage.
MaxComplianceIssuesPerViolation = 100
};
var message = parser.ParseMessage ();
foreach (var issue in report.Issues) {
// Each issue includes the location in the stream where the violation was found,
// how severe it is, and a description of the problem.
Console.WriteLine ("[{0}] line {1}, column {2}: {3}", issue.Severity, issue.LineNumber, issue.ColumnNumber, issue.Description);
// The Categories property describes the kinds of risk that the violation poses.
if ((issue.Categories & MimeComplianceCategories.Security) != 0)
Console.WriteLine (" This violation may have security implications: {0}", issue.Remarks);
}
return message;
}
}
Constructors
| MimeComplianceOptions | Initialize a new instance of the MimeComplianceOptions class. |
Properties
| Context | Get or set the context that the message is being used in. |
| EnabledValidators | Get or set the validators that should be run. |
| MaxIssuesPerViolation | Get or set the maximum number of times that each compliance violation may be reported. |
Methods
| Clone | Clones an instance of MimeComplianceOptions. |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
| Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) |
| GetHashCode | Serves as the default hash function. (Inherited from Object) |
| GetType | Gets the Type of the current instance. (Inherited from Object) |
| MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) |
| ToString | Returns a string that represents the current object. (Inherited from Object) |
Fields
| Default | The default compliance options. |