Skip to content

MIME Compliance Logger - #1244

Open
jstedfast wants to merge 29 commits into
masterfrom
mime-compliance-violations
Open

MIME Compliance Logger#1244
jstedfast wants to merge 29 commits into
masterfrom
mime-compliance-violations

Conversation

@jstedfast

Copy link
Copy Markdown
Owner

This PR adds a "ComplianceLogger" to MimeReader, allowing developers to hook in to get information about where the MIME content is non-conformat with the specifications.

@coveralls

coveralls commented May 21, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 94.812% (-0.1%) from 94.926% — mime-compliance-violations into master

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces MIME compliance reporting to MimeReader via a pluggable IMimeComplianceLogger, allowing consumers to record spec violations (line endings, invalid/duplicate headers, invalid multipart boundaries, illegal encodings, unexpected 8-bit/null bytes, and encoding-level violations like invalid base64/qp/uuencode).

Changes:

  • Added MimeReader.ComplianceLogger and integrated compliance checks throughout header/body parsing (sync + async).
  • Introduced encoding validators (Base64Validator, QuotedPrintableValidator, UUValidator) and related test coverage.
  • Added extensive unit tests + compliance fixture .eml files to validate violation reporting (including stream offsets across Unix/DOS newline transformations).

Reviewed changes

Copilot reviewed 43 out of 45 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
UnitTests/Utils/MemoryTests.cs Adds low-level tests for byte scanning/detection helpers used by compliance detection.
UnitTests/UnitTests.csproj Updates unit test project configuration (incl. unsafe blocks); currently contains a duplicated property.
UnitTests/TestMimeComplianceLogger.cs Adds a concrete logger used by unit tests to capture violations.
UnitTests/TestData/compliance/unexpected-8bit-bytes-in-preamble.eml Adds fixture to validate unexpected 8-bit detection in multipart preamble.
UnitTests/TestData/compliance/unexpected-8bit-bytes-in-epilogue.eml Adds fixture to validate unexpected 8-bit detection in multipart epilogue.
UnitTests/TestData/compliance/unexpected-8bit-bytes-in-body.eml Adds fixture to validate unexpected 8-bit detection in multipart body content.
UnitTests/TestData/compliance/raw-utf8-header.eml Adds fixture to validate UTF-8 header allowance behavior.
UnitTests/TestData/compliance/raw-koi8r-header.eml Adds fixture to validate non-UTF8 8-bit header violation reporting.
UnitTests/TestData/compliance/multiple-content-types.eml Adds fixture for duplicate Content-Type header detection.
UnitTests/TestData/compliance/multiple-content-transfer-encodings.eml Adds fixture for duplicate Content-Transfer-Encoding header detection.
UnitTests/TestData/compliance/missing-multipart-end-boundary.eml Adds fixture for missing multipart boundary detection (truncated multipart).
UnitTests/TestData/compliance/missing-multipart-boundary.eml Adds fixture for mismatched/missing boundary marker detection.
UnitTests/TestData/compliance/missing-multipart-boundary-parameter.eml Adds fixture for missing boundary parameter detection.
UnitTests/TestData/compliance/missing-body-separator.eml Adds fixture for missing header/body separator detection.
UnitTests/TestData/compliance/invalid-wrapping.eml Adds fixture for SMTP line-length wrapping violations.
UnitTests/TestData/compliance/invalid-header-field-with-space.eml Adds fixture for invalid header field-name detection.
UnitTests/TestData/compliance/invalid-content-type.eml Adds fixture for invalid Content-Type parsing detection.
UnitTests/TestData/compliance/invalid-content-transfer-encoding-rfc822.eml Adds fixture for illegal CTE on message/rfc822.
UnitTests/TestData/compliance/invalid-content-transfer-encoding-multiple.eml Adds fixture for invalid CTE within multipart structures.
UnitTests/TestData/compliance/invalid-content-transfer-encoding-multipart.eml Adds fixture for illegal CTE on multiparts.
UnitTests/TestData/compliance/invalid-content-transfer-encoding-basic.eml Adds fixture for invalid CTE token detection.
UnitTests/TestData/compliance/incomplete-header.eml Adds fixture for truncated/incomplete header detection.
UnitTests/MimeReaderTests.cs Extends reader tests to assert compliance logging, including offset mapping under newline filters.
UnitTests/MimeComplianceIssue.cs Adds test-side issue models for expected/actual compliance assertions.
UnitTests/Encodings/UUValidatorTests.cs Adds tests for UUEncode compliance validation behavior.
UnitTests/Encodings/QuotedPrintableValidatorTests.cs Adds tests for quoted-printable compliance validation behavior.
UnitTests/Encodings/EncodingValidatorTestsBase.cs Adds shared validator test utilities and test data loading helpers.
UnitTests/Encodings/Base64ValidatorTests.cs Adds tests for base64 compliance validation behavior.
MimeKit/Utils/Utf8.cs Adds UTF-8 validation implementation for frameworks lacking System.Text.Unicode.Utf8.
MimeKit/Utils/ParseUtils.cs Centralizes fast end-of-line scanning (+ optional byte detection) for parser use.
MimeKit/Utils/ByteDetectionResults.cs Introduces flags representing detected 8-bit/null content during scans.
MimeKit/Utils/ByteDetectionOptions.cs Introduces flags controlling 8-bit/null detection during scans.
MimeKit/MimeReader.cs Core integration of compliance logging across parsing stages + boundary validation + encoding validators.
MimeKit/MimeKit.csproj Adds BOM/formatting change in project file header.
MimeKit/MimeComplianceViolation.cs Introduces the public enum describing compliance violation types and their docs.
MimeKit/IMimeComplianceLogger.cs Introduces the public logging interface consumed by MimeReader and validators.
MimeKit/Encodings/UUValidator.cs Adds UUEncode incremental validator that logs compliance violations.
MimeKit/Encodings/UUDecoder.cs Exposes UUDecode rank table internally for validator use.
MimeKit/Encodings/QuotedPrintableValidator.cs Adds quoted-printable incremental validator that logs compliance violations.
MimeKit/Encodings/IEncodingValidator.cs Adds shared validator interface used by MIME parsing to validate encoded bodies.
MimeKit/Encodings/Base64Validator.cs Adds base64 incremental validator that logs compliance violations.
MimeKit/AsyncMimeReader.cs Mirrors compliance logic for async parsing path (headers/content scanning/validators).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread UnitTests/UnitTests.csproj
Comment thread MimeKit/MimeReader.cs
Comment thread MimeKit/Encodings/Base64Validator.cs Outdated
Comment thread MimeKit/MimeComplianceViolation.cs
Comment thread MimeKit/MimeComplianceViolation.cs
Comment thread MimeKit/MimeComplianceViolation.cs Outdated
Comment thread UnitTests/Utils/MemoryTests.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants