Skip to content

fix: filter Content-Transfer-Encoding from custom headers#158

Merged
drish merged 1 commit intoresend:mainfrom
ryanwi:fix/filter-content-transfer-encoding-header
Feb 27, 2026
Merged

fix: filter Content-Transfer-Encoding from custom headers#158
drish merged 1 commit intoresend:mainfrom
ryanwi:fix/filter-content-transfer-encoding-header

Conversation

@ryanwi
Copy link
Contributor

@ryanwi ryanwi commented Feb 27, 2026

Problem

The IGNORED_HEADERS list filters MIME headers that the Resend API / Amazon
SES handles automatically (content-type, mime-version, etc.), but
content-transfer-encoding was missing.

The Mail gem includes this as a header field on every message. When
headers_values() reads its unparsed_value, some versions of the Mail gem
return the Ruby constant name (e.g. Mail::Encodings::SevenBit) instead of
the actual encoding string 7bit. This gets passed through to the Resend API
as a custom header and appears verbatim in outgoing emails:

Content-Transfer-Encoding: Mail::Encodings::SevenBit

Email providers like Yahoo flag this malformed header and route messages to spam.

Fix

Add content-transfer-encoding to IGNORED_HEADERS, consistent with
content-type and mime-version which are already filtered.

Test plan

  • Added spec verifying content-transfer-encoding is in IGNORED_HEADERS
    and not passed through as a custom header
  • All existing specs pass

Summary by cubic

Filters Content-Transfer-Encoding from custom headers to prevent malformed values (e.g., Mail::Encodings::SevenBit) from being sent. Aligns with other auto-handled MIME headers and helps avoid spam routing.

  • Bug Fixes
    • Added content-transfer-encoding to IGNORED_HEADERS so SES/Resend handles it.
    • Added spec to confirm the header is filtered and not sent as a custom header.

Written for commit 217d3a5. Summary will update on new commits.

The Mail gem includes Content-Transfer-Encoding as a header field, and
its `unparsed_value` can return the Ruby constant name (e.g.
`Mail::Encodings::SevenBit`) instead of the actual encoding string
`7bit`. Since this header was not in IGNORED_HEADERS, it was passed
through to the Resend API as a custom header, resulting in malformed
Content-Transfer-Encoding values in outgoing emails.

This causes email providers like Yahoo to flag messages as spam.

The Resend API already handles Content-Transfer-Encoding via Amazon SES,
so this header should be filtered like content-type and mime-version.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

@drish drish self-requested a review February 27, 2026 14:08
Copy link
Collaborator

@drish drish left a comment

Choose a reason for hiding this comment

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

looks good to me, thank you for your contribution @ryanwi

@drish drish merged commit 0153cec into resend:main Feb 27, 2026
4 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.

2 participants