Mime Compliance Issue Structure
A MIME compliance issue detected while parsing.
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 readonly struct MimeComplianceIssue : IEquatable<MimeComplianceIssue>- Implements
- IEquatableMimeComplianceIssue
Remarks
Describes a single deviation from the Internet Message and MIME specifications along with the location within the stream where it was detected.
New properties may be added to this structure in future versions of MimeKit in order to provide richer context about a violation. For that reason, always construct instances using one of the available constructors rather than relying on the default value.
The default value of this structure has a Violation of None, which is never reported by MimeReader and cannot be constructed, so it may be used to detect an uninitialized instance.
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
| MimeComplianceIssue(MimeComplianceContext, MimeComplianceViolation, Int64, Int32, Int32) | Initialize a new instance of the MimeComplianceIssue struct. |
| MimeComplianceIssue(MimeComplianceContext, MimeComplianceViolation, Int64, Int32, Int32, MimeCompliancePositionKind) | Initialize a new instance of the MimeComplianceIssue struct. |
Properties
| Categories | Get the categories of harm that the MIME compliance violation may cause. |
| ColumnNumber | Get the column number where the violation was found. |
| Context | Get the context that the message is being used in. |
| Description | Get a brief description of the MIME compliance violation. |
| LineNumber | Get the line number where the violation was found. |
| PositionKind | Get what the position of the issue refers to. |
| Remarks | Get a detailed explanation of the MIME compliance violation. |
| Severity | Get the severity of the MIME compliance violation. |
| StreamOffset | Get the offset within the stream where the violation was found. |
| Violation | Get the specific MIME compliance violation that occurred. |
Methods
| Equals(MimeComplianceIssue) | Determine whether the specified MimeComplianceIssue is equal to the current MimeComplianceIssue. |
| Equals(Object) |
Determine whether the specified Object is equal to the current MimeComplianceIssue.
(Overrides ValueTypeEquals(Object)) |
| GetCategories | Get the categories of harm that a MIME compliance violation may cause. |
| GetDescription | Get a brief description of a MIME compliance violation. |
| GetHashCode |
Serve as a hash function for a MimeComplianceIssue object.
(Overrides ValueTypeGetHashCode) |
| GetRemarks | Get a detailed explanation of a MIME compliance violation. |
| GetSeverity(MimeComplianceContext) | Get the severity of the MIME compliance violation in a particular context. |
| GetSeverity(MimeComplianceViolation) | Get the severity of a MIME compliance violation. |
| GetSeverity(MimeComplianceViolation, MimeComplianceContext) | Get the severity of a MIME compliance violation in a particular context. |
| GetType | Gets the Type of the current instance. (Inherited from Object) |
| ToString |
Get a string representation of the MIME compliance issue.
(Overrides ValueTypeToString) |
Operators
| Equality(MimeComplianceIssue, MimeComplianceIssue) | Compare two MimeComplianceIssue objects for equality. |
| Inequality(MimeComplianceIssue, MimeComplianceIssue) | Compare two MimeComplianceIssue objects for inequality. |