Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Unreleased
## [2.9.0] - 2026-03-13

- Add Sending Stats API
- Parse `reply_to` as a structured address field instead of passing it as a raw
header when sending with Action Mailer

## [2.8.0] - 2026-03-03

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
mailtrap (2.8.0)
mailtrap (2.9.0)
base64

GEM
Expand Down
4 changes: 1 addition & 3 deletions lib/mailtrap/mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ def batch_base_from_content( # rubocop:disable Metrics/ParameterLists
# Builds a mail object from Mail::Message
# @param message [Mail::Message]
# @return [Mailtrap::Mail::Base]
# rubocop:disable Metrics/AbcSize
def from_message(message)
def from_message(message) # rubocop:disable Metrics/AbcSize
Mailtrap::Mail::Base.new(
from: prepare_addresses(message['from']).first,
to: prepare_addresses(message['to']),
Expand All @@ -209,7 +208,6 @@ def from_message(message)
template_variables: message['template_variables']&.unparsed_value
)
end
# rubocop:enable Metrics/AbcSize

private

Expand Down
2 changes: 1 addition & 1 deletion lib/mailtrap/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Mailtrap
VERSION = '2.8.0'
VERSION = '2.9.0'
end
54 changes: 2 additions & 52 deletions spec/mailtrap/mail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,6 @@

it { is_expected.to eq(expected_headers) }
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed the tests that test Mail gem rather then Mailtrap and tests that duplicate other tests.

context 'when reply-to is added in varying formats' do
before do
message.reply_to = 'Reply To <reply-to@railsware.com>'
end

it 'excludes reply-to from custom headers' do
expect(headers).not_to have_key('Reply-To')
end
end

context 'when custom header and reply-to variants are present' do
before do
message.header['Reply-To'] = 'Reply To <reply-to@railsware.com>'
message.header['REPLY-TO'] = 'Upper Case <upper-reply-to@railsware.com>'
message.header['reply-to'] = 'Lower Case <lower-reply-to@railsware.com>'
message.header['X-Special-Domain-Specific-Header'] = 'SecretValue'
end

it 'keeps only custom headers and strips all reply-to header variants' do
expect(headers).to eq('X-Special-Domain-Specific-Header' => 'SecretValue')
end
end
end

describe '#reply_to' do
Expand All @@ -85,18 +62,6 @@
it 'maps reply-to to the structured field' do
expect(mail.reply_to).to eq(email: 'reply-to@railsware.com', name: 'Reply To')
end

context 'when reply-to header variants are present' do
before do
message.header['Reply-To'] = 'Reply To <reply-to@railsware.com>'
message.header['REPLY-TO'] = 'Upper Case <upper-reply-to@railsware.com>'
message.header['reply-to'] = 'Lower Case <lower-reply-to@railsware.com>'
end

it 'maps the reply-to value to the structured field' do
expect(mail.reply_to).to eq({ email: 'lower-reply-to@railsware.com', name: 'Lower Case' })
end
end
end

describe '#attachment' do
Expand Down Expand Up @@ -199,32 +164,17 @@
its(:template_variables) { is_expected.to eq('first_name' => 'John') }
end

%i[from to cc bcc].each do |header|
%w[from to cc bcc reply-to].each do |header|
context "when '#{header}' is invalid" do
let(:message_params) { super().merge(header => 'invalid email@example.com') }

it 'raises an error' do
expect { mail }.to raise_error(
Mailtrap::Error,
"failed to parse '#{header.capitalize}': 'invalid email@example.com'"
"failed to parse '#{Mail::Field::FIELD_NAME_MAP[header]}': 'invalid email@example.com'"
)
end
end
end

context "when 'reply-to' is invalid" do
let(:invalid_reply_to) { 'invalid email@example.com' }

before do
message.header['Reply-To'] = invalid_reply_to
end

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