Skip to content

fix: return stdlib net/textproto.MIMEHeader from DecodeHeaders - #420

Merged
jhillyerd merged 1 commit into
jhillyerd:mainfrom
AdamMagued:fix-issue-405
Oct 19, 2026
Merged

jhillyerd merged 1 commit into
jhillyerd:mainfrom
AdamMagued:fix-issue-405

Conversation

@AdamMagued

@AdamMagued AdamMagued commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #405

Summary

DecodeHeaders returned github.com/jhillyerd/enmime/v2/internal/textproto.MIMEHeader instead of standard library net/textproto.MIMEHeader. Because the returned type resided in an internal package, external packages could not reference the type name directly.

Changes

  • Import net/textproto in inspect.go and return textproto.MIMEHeader from DecodeHeaders.
  • Alias github.com/jhillyerd/enmime/v2/internal/textproto as inttp in inspect.go and inspect_test.go.
  • Allocate an independent slice for headerList before appending addtlHeaders to avoid mutating the backing array of package-level defaultHeadersList.
  • Update inspect_test.go to verify DecodeHeaders returns net/textproto.MIMEHeader with accurate header decoding and case-insensitive lookup.

Summary by CodeRabbit

  • Bug Fixes
    • Header inspection now decodes encoded header values and supports case-insensitive header lookups.
    • Repeated custom headers retain all their values, while requests for missing headers return an empty result.
    • Header-reading errors are now reported with the expected protocol error type.

DecodeHeaders returned internal textproto.MIMEHeader instead of net/textproto.MIMEHeader. Update the return type and callers to standard library net/textproto.MIMEHeader. Also allocate an independent slice for headerList to prevent mutating package-level defaultHeadersList.

Fixes jhillyerd#405
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9e67fa55-e5cd-4325-b58e-c71dc888da6e

📥 Commits

Reviewing files that changed from the base of the PR and between 904d7c5 and a614eb1.


📒 Files selected for processing (2)
  • inspect.go
  • inspect_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.



📝 Walkthrough

Walkthrough

DecodeHeaders now returns the standard-library textproto.MIMEHeader type while using the internal reader and email-header canonicalizer. It builds a fresh list of header names before adding requested headers. Tests cover decoded values, lookups, repeated values, and read errors.

Changes

DecodeHeaders

Layer / File(s) Summary
Header decoding and return contract
inspect.go, inspect_test.go
DecodeHeaders returns a standard-library textproto.MIMEHeader and uses the internal reader and canonicalizer. It creates a fresh header-name slice before appending requested headers. Tests check decoded values, case-insensitive and missing-header lookups, repeated values, and the internal protocol error type.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low


Merge Risk: ⚪ Minimal · up to a614e

The return-type change appears ready to merge after normal checks.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the primary change: returning the standard-library net/textproto.MIMEHeader from DecodeHeaders.
Linked Issues check Passed Issue #405 requires DecodeHeaders to avoid returning the internal textproto.MIMEHeader type. inspect.go imports net/textproto and declares DecodeHeaders with return type `textproto.MIMEHeade…
Out of Scope Changes check Passed The reviewed changes stay within Issue #405. The inttp aliases distinguish internal parsing APIs from the public standard-library type. The independent header slice prevents mutation of the shared d…

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 87.396% (+0.003%) from 87.393% — AdamMagued:fix-issue-405 into jhillyerd:main

@jhillyerd
jhillyerd merged commit 2561c01 into jhillyerd:main Oct 19, 2026
8 checks passed
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.

DecodeHeaders returns an internal type

3 participants