TnefComplianceIssue Structure

A TNEF compliance issue detected while parsing.

Definition

Namespace: MimeKit.Tnef
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public readonly struct TnefComplianceIssue : IEquatable<TnefComplianceIssue>
Inheritance
Object    ValueType    TnefComplianceIssue
Implements
IEquatableTnefComplianceIssue

Remarks

Describes a single deviation from the TNEF 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 and cannot be constructed, so it may be used to detect an uninitialized instance.

Example

C#
                    class TnefComplianceCollector : ITnefComplianceLogger
{
    public List<TnefComplianceIssue> Issues { get; } = new List<TnefComplianceIssue> ();

    public void Log (in TnefComplianceIssue issue)
    {
        Issues.Add (issue);
    }
}

class StrictTnefComplianceLogger : ITnefComplianceLogger
{
    public void Log (in TnefComplianceIssue issue)
    {
        // Reject anything that is likely to cause real problems; tolerate the rest.
        if (issue.Severity >= MimeComplianceSeverity.Major)
            throw new TnefException (issue.Violation, issue.Description);
    }
}

public static TnefMessage LoadAndReportIssues (Stream stream)
{
    var collector = new TnefComplianceCollector ();
    TnefMessage tnef;

    // The reader never throws for malformed TNEF; it recovers as best it can and reports each problem
    // to the ComplianceLogger. MaxComplianceIssuesPerViolation limits how many times each kind of
    // violation is reported.
    using (var reader = new TnefReader (stream, null, leaveOpen: true) { ComplianceLogger = collector, MaxComplianceIssuesPerViolation = 16 })
        tnef = TnefMessage.Load (reader);

    foreach (var issue in collector.Issues)
        Console.WriteLine ("{0} ({1}) @ offset {2}: {3}", issue.Violation, issue.Severity, issue.StreamOffset, issue.Description);

    return tnef;
}

public static TnefMessage LoadStrict (Stream stream)
{
    using (var reader = new TnefReader (stream, null, leaveOpen: true) { ComplianceLogger = new StrictTnefComplianceLogger () })
        return TnefMessage.Load (reader);
}
                  

Constructors

TnefComplianceIssue(TnefComplianceViolation, Int64) Initialize a new instance of the TnefComplianceIssue struct.
TnefComplianceIssue(TnefComplianceViolation, Int64, Int32, TnefAttributeTag, TnefPropertyTag) Initialize a new instance of the TnefComplianceIssue struct.

Properties

AttributeTag Get the attribute that was being read when the violation was found.
Categories Get the categories of harm that the TNEF compliance violation may cause.
Depth Get the nesting depth of the embedded message that the violation was found in.
Description Get a brief description of the TNEF compliance violation.
PropertyTag Get the property that was being read when the violation was found.
Remarks Get a detailed explanation of the TNEF compliance violation.
Severity Get the severity of the TNEF compliance violation.
StreamOffset Get the offset within the stream where the violation was found.
Violation Get the specific TNEF compliance violation that occurred.

Methods

Equals(Object) Determine whether the specified Object is equal to the current TnefComplianceIssue.
(Overrides ValueTypeEquals(Object))
Equals(TnefComplianceIssue) Determine whether the specified TnefComplianceIssue is equal to the current TnefComplianceIssue.
GetCategories Get the categories of harm that a TNEF compliance violation may cause.
GetDescription Get a brief description of a TNEF compliance violation.
GetHashCode Serve as a hash function for a TnefComplianceIssue object.
(Overrides ValueTypeGetHashCode)
GetRemarks Get a detailed explanation of a TNEF compliance violation.
GetSeverity Get the severity of a TNEF compliance violation.
GetType Gets the Type of the current instance.
(Inherited from Object)
ToString Get a string representation of the TNEF compliance issue.
(Overrides ValueTypeToString)

Operators

Equality(TnefComplianceIssue, TnefComplianceIssue) Compare two TnefComplianceIssue objects for equality.
Inequality(TnefComplianceIssue, TnefComplianceIssue) Compare two TnefComplianceIssue objects for inequality.

See Also