aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael França <rafael@franca.dev>2019-07-26 13:27:23 -0400
committerGitHub <noreply@github.com>2019-07-26 13:27:23 -0400
commita40da823d729296514f310d13a09ce8e0b37b699 (patch)
treee23975a060a7621825afe7706381ad01f71e08ef
parentd937e1f4ca6da53cc641fca808fd79919f579c62 (diff)
parent09e5d6d0040211a513d47ea7309af31aa719ed5b (diff)
downloadrails-a40da823d729296514f310d13a09ce8e0b37b699.tar.gz
rails-a40da823d729296514f310d13a09ce8e0b37b699.tar.bz2
rails-a40da823d729296514f310d13a09ce8e0b37b699.zip
Merge pull request #35992 from jduff/include_bcc
Fix Bcc header missing with emails from conductor and test helpers
-rw-r--r--actionmailbox/CHANGELOG.md4
-rw-r--r--actionmailbox/lib/action_mailbox/test_helper.rb6
-rw-r--r--actionmailbox/test/controllers/rails/action_mailbox/inbound_emails_controller_test.rb21
-rw-r--r--actionmailbox/test/unit/router_test.rb9
4 files changed, 39 insertions, 1 deletions
diff --git a/actionmailbox/CHANGELOG.md b/actionmailbox/CHANGELOG.md
index bca3d1d9ed..0d4799a7b8 100644
--- a/actionmailbox/CHANGELOG.md
+++ b/actionmailbox/CHANGELOG.md
@@ -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*
diff --git a/actionmailbox/lib/action_mailbox/test_helper.rb b/actionmailbox/lib/action_mailbox/test_helper.rb
index d248fa8734..dc6a0229f7 100644
--- a/actionmailbox/lib/action_mailbox/test_helper.rb
+++ b/actionmailbox/lib/action_mailbox/test_helper.rb
@@ -14,7 +14,11 @@ module ActionMailbox
#
# 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.
diff --git a/actionmailbox/test/controllers/rails/action_mailbox/inbound_emails_controller_test.rb b/actionmailbox/test/controllers/rails/action_mailbox/inbound_emails_controller_test.rb
index 06f5a9d6db..33282d36f7 100644
--- a/actionmailbox/test/controllers/rails/action_mailbox/inbound_emails_controller_test.rb
+++ b/actionmailbox/test/controllers/rails/action_mailbox/inbound_emails_controller_test.rb
@@ -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
diff --git a/actionmailbox/test/unit/router_test.rb b/actionmailbox/test/unit/router_test.rb
index 4dd3730604..7eb8e04a73 100644
--- a/actionmailbox/test/unit/router_test.rb
+++ b/actionmailbox/test/unit/router_test.rb
@@ -51,6 +51,15 @@ module ActionMailbox
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)