Skip to content

Commit

Permalink
Merge pull request rails#53513 from Mr0grog/reply-to-address-mail-ext…
Browse files Browse the repository at this point in the history
…ension

actionmailbox: Add `reply_to_address` Mail extension
  • Loading branch information
byroot authored Jan 27, 2025
2 parents 9e42358 + ac58320 commit 59a42a9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions actionmailbox/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
* Add `reply_to_address` extension method on `Mail::Message`.

*Mr0grog*

Please check [8-0-stable](https://github.com/rails/rails/blob/8-0-stable/actionmailbox/CHANGELOG.md) for previous changes.
4 changes: 4 additions & 0 deletions actionmailbox/lib/action_mailbox/mail_ext/addresses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ def from_address
address_list(header[:from])&.addresses&.first
end

def reply_to_address
address_list(header[:reply_to])&.addresses&.first
end

def recipients_addresses
to_addresses + cc_addresses + bcc_addresses + x_original_to_addresses + x_forwarded_to_addresses
end
Expand Down
5 changes: 5 additions & 0 deletions actionmailbox/test/unit/mail_ext/addresses_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class AddressesTest < ActiveSupport::TestCase
setup do
@mail = Mail.new \
from: "[email protected]",
reply_to: "[email protected]",
to: "[email protected]",
cc: "[email protected]",
bcc: "[email protected]",
Expand All @@ -18,6 +19,10 @@ class AddressesTest < ActiveSupport::TestCase
assert_equal "example.com", @mail.from_address.domain
end

test "reply to address uses address object" do
assert_equal "example.com", @mail.reply_to_address.domain
end

test "recipients include everyone from to, cc, bcc, x-original-to, and x-forwarded-to" do
assert_equal %w[ [email protected] [email protected] [email protected] [email protected] [email protected] ], @mail.recipients
end
Expand Down

0 comments on commit 59a42a9

Please sign in to comment.