Skip to content

Commit

Permalink
Merge pull request #35992 from jduff/include_bcc
Browse files Browse the repository at this point in the history
Fix Bcc header missing with emails from conductor and test helpers
  • Loading branch information
rafaelfranca committed Jul 26, 2019
2 parents d937e1f + 09e5d6d commit a40da82
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
4 changes: 4 additions & 0 deletions actionmailbox/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Fix Bcc header not being included with emails from `create_inbound_email_from` test helpers.

*jduff*

* Add `ApplicationMailbox.mailbox_for` to expose mailbox routing.

*James Dabbs*
Expand Down
6 changes: 5 additions & 1 deletion actionmailbox/lib/action_mailbox/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ def create_inbound_email_from_fixture(fixture_name, status: :processing)
#
# create_inbound_email_from_mail(from: "david@loudthinking.com", subject: "Hello!")
def create_inbound_email_from_mail(status: :processing, **mail_options)
create_inbound_email_from_source Mail.new(mail_options).to_s, status: status
mail = Mail.new(mail_options)
# Bcc header is not encoded by default
mail[:bcc].include_in_headers = true if mail[:bcc]

create_inbound_email_from_source mail.to_s, status: status
end

# Create an +InboundEmail+ using the raw rfc822 +source+ as text.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ class Rails::Conductor::ActionMailbox::InboundEmailsControllerTest < ActionDispa
end
end

test "create inbound email with bcc" do
with_rails_env("development") do
assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do
post rails_conductor_inbound_emails_path, params: {
mail: {
from: "Jason Fried <jason@37signals.com>",
bcc: "Replies <replies@example.com>",
subject: "Hey there",
body: "How's it going?"
}
}
end

mail = ActionMailbox::InboundEmail.last.mail
assert_equal %w[ jason@37signals.com ], mail.from
assert_equal %w[ replies@example.com ], mail.bcc
assert_equal "Hey there", mail.subject
assert_equal "How's it going?", mail.body.decoded
end
end

test "create inbound email with attachments" do
with_rails_env("development") do
assert_difference -> { ActionMailbox::InboundEmail.count }, +1 do
Expand Down
9 changes: 9 additions & 0 deletions actionmailbox/test/unit/router_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ class RouterTest < ActiveSupport::TestCase
assert_equal inbound_email.mail, $processed_mail
end

test "single string routing on bcc" do
@router.add_routes("first@example.com" => :first)

inbound_email = create_inbound_email_from_mail(to: "someone@example.com", bcc: "first@example.com", subject: "This is a reply")
@router.route inbound_email
assert_equal "FirstMailbox", $processed_by
assert_equal inbound_email.mail, $processed_mail
end

test "single string routing case-insensitively" do
@router.add_routes("first@example.com" => :first)

Expand Down

0 comments on commit a40da82

Please sign in to comment.