Skip to content

Map Reply-To into structured field and strip Reply-To header from payload#1

Merged
ryush00 merged 1 commit intomainfrom
codex/fix-reply-to-serialization-bug-in-mailtrap-gem
Mar 7, 2026
Merged

Map Reply-To into structured field and strip Reply-To header from payload#1
ryush00 merged 1 commit intomainfrom
codex/fix-reply-to-serialization-bug-in-mailtrap-gem

Conversation

@ryush00
Copy link
Copy Markdown
Member

@ryush00 ryush00 commented Mar 7, 2026

Motivation

  • Make the library treat the Reply-To header as a structured reply_to field instead of leaving a redundant header in the payload sent to the API.
  • Ensure various Reply-To header casing/format variations are normalized and removed from the final headers hash.

Description

  • Added replyto to SPECIAL_HEADERS so Reply-To is removed from headers sent to the API.
  • Populates the reply_to attribute in from_message by mapping message['reply-to'] into a structured address (using prepare_addresses(...).first).
  • Updated the VCR fixture spec/fixtures/vcr_cassettes/.../converts_the_message_and_sends_via_API.yml to reflect the reply_to structured payload instead of a Reply-To header copy.
  • Added/extended specs in spec/mailtrap/mail_spec.rb to validate mapping of different reply-to formats, stripping of header variants, and error handling for invalid Reply-To values.

Testing

  • Ran the test suite with rspec focusing on spec/mailtrap/mail_spec.rb, and the updated examples for reply_to mapping and header stripping passed.
  • Updated VCR cassette Mailtrap_ActionMailer_DeliveryMethod/_deliver_/converts_the_message_and_sends_via_API.yml was used to validate the API payload change and matching tests passed.

Codex Task

Summary by CodeRabbit

  • New Features

    • Added support for processing reply-to headers; reply-to information is now extracted and mapped to a structured field for API transmission.
  • Tests

    • Added comprehensive test coverage for reply-to header handling, including validation of various formats and edge cases.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the handling of the Reply-To email header within the library. It transitions Reply-To from being a raw header to a structured reply_to field in the API payload, ensuring consistent data representation and normalization across various formats. This change also ensures that redundant Reply-To headers are stripped from the final API request, improving data integrity and API efficiency.

Highlights

  • Structured Reply-To Field: The Reply-To header is now processed as a structured reply_to field within the API payload, rather than a raw header.
  • Header Stripping: The Reply-To header, along with its various casing formats, is explicitly removed from the final headers sent to the API to prevent redundancy.
  • Format Normalization: The library now normalizes different Reply-To header formats (e.g., with/without names, different encodings) into a consistent structured format.
  • Error Handling: Error handling has been added to catch and report invalid Reply-To email address formats.
  • VCR Fixture Update: A VCR fixture was updated to reflect the new structured reply_to payload and the absence of the Reply-To header in the API request.
Changelog
  • lib/mailtrap/mail.rb
    • Added replyto to the SPECIAL_HEADERS list to ensure it is processed and removed from raw headers.
    • Updated the from_message method to map message['reply-to'] into a structured reply_to attribute using prepare_addresses(...).first.
  • spec/fixtures/vcr_cassettes/Mailtrap_ActionMailer_DeliveryMethod/deliver/converts_the_message_and_sends_via_API.yml
    • Updated the VCR fixture to reflect the API payload now containing a structured reply_to field and the absence of the Reply-To header in the headers section.
  • spec/mailtrap/mail_spec.rb
    • Modified an existing test's expected_headers to no longer expect the Reply-To header.
    • Added new test contexts to validate the mapping of various reply-to formats (e.g., with/without names, different encodings) to the structured reply_to field.
    • Added a new test context to ensure all Reply-To header variants (different casings) are correctly stripped while custom headers are preserved.
    • Added a new test context to verify that an error is raised when an invalid Reply-To email format is provided.
Activity
  • The test suite was run with rspec, specifically focusing on spec/mailtrap/mail_spec.rb, and all updated examples for reply_to mapping and header stripping passed.
  • The updated VCR cassette Mailtrap_ActionMailer_DeliveryMethod/_deliver_/converts_the_message_and_sends_via_API.yml was used to validate the API payload change, and matching tests passed.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 7, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 965676f9-a2f4-490e-ba4e-bf009598f71a

📥 Commits

Reviewing files that changed from the base of the PR and between af396c8 and 3e979b0.

📒 Files selected for processing (3)
  • lib/mailtrap/mail.rb
  • spec/fixtures/vcr_cassettes/Mailtrap_ActionMailer_DeliveryMethod/_deliver_/converts_the_message_and_sends_via_API.yml
  • spec/mailtrap/mail_spec.rb

📝 Walkthrough

Walkthrough

The changes introduce support for handling reply-to addresses as a structured field in the Mailtrap mail library. The implementation adds "replyto" to recognized special headers, extracts reply-to data from messages into a dedicated reply_to attribute during message conversion, and includes comprehensive test coverage for various reply-to formats and edge cases.

Changes

Cohort / File(s) Summary
Core Implementation
lib/mailtrap/mail.rb
Added "replyto" to SPECIAL_HEADERS constant and modified from_message to extract and populate the reply_to field from the message's 'reply-to' header into the resulting Base object.
Test Fixtures
spec/fixtures/vcr_cassettes/Mailtrap_ActionMailer_DeliveryMethod/_deliver_/converts_the_message_and_sends_via_API.yml
Updated VCR cassette to reflect the transition from Reply-To header to a structured reply_to field in the JSON payload, maintaining consistency with the new API format.
Test Specifications
spec/mailtrap/mail_spec.rb
Removed default Reply-To header from test setup and added comprehensive test contexts validating reply-to format mapping, header removal, interaction with custom headers, and error handling for invalid reply-to values.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A letter comes with "please reply"
To addresses both far and nigh,
Now structured clean, not just a header,
The reply_to field grows better!
With tests to guard each format's way,
The bouncing bunny's here to stay!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: mapping Reply-To header into a structured reply_to field and removing the header from the API payload.
Description check ✅ Passed The description covers motivation, detailed changes, and testing approach. While it uses 'Description' instead of 'Changes' and 'Testing' instead of 'How to test', all essential information is present and well-organized.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/fix-reply-to-serialization-bug-in-mailtrap-gem

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

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly implements the mapping of the Reply-To header to a structured reply_to field, and removes it from the general headers payload. The changes are well-tested, including various formats and casings of the Reply-To header. I have one suggestion to improve the test suite's maintainability by reducing code duplication.

Comment on lines +186 to +197
context "when 'reply-to' is invalid" do
before do
message.header['Reply-To'] = 'invalid email@example.com'
end

it 'raises an error' do
expect { mail }.to raise_error(
Mailtrap::Error,
"failed to parse 'Reply-To': 'invalid email@example.com'"
)
end
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While this test for an invalid reply-to header is correct, it duplicates the structure of the existing tests for invalid from, to, cc, and bcc headers. To improve maintainability and adhere to the DRY (Don't Repeat Yourself) principle, consider refactoring this new test and the existing ones into a single, data-driven test.

This would also be an opportunity to fix a likely bug in the existing test: header.capitalize is called on a symbol, which will raise a NoMethodError. It should probably be header.to_s.capitalize.

Here is an example of how you could combine and fix them:

    {
      from: 'From',
      to: 'To',
      cc: 'Cc',
      bcc: 'Bcc',
      reply_to: 'Reply-To'
    }.each do |header_key, header_name|
      context "when '#{header_key}' is invalid" do
        let(:message_params) { super().merge(header_key => 'invalid email@example.com') }

        it 'raises an error' do
          expect { mail }.to raise_error(
            Mailtrap::Error,
            "failed to parse '#{header_name}': 'invalid email@example.com'"
          )
        end
      end
    end

This refactoring would make the test suite cleaner, more robust, and easier to extend in the future.

@ryush00 ryush00 merged commit 13d18c9 into main Mar 7, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant