Skip to content

Commit

Permalink
All to-recipients now see all other to-recipients, as set by :header_to
Browse files Browse the repository at this point in the history
  • Loading branch information
BradyBonnette committed Jul 19, 2016
1 parent 2b75265 commit e8a3085
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 28 deletions.
9 changes: 5 additions & 4 deletions lib/sparkpost_rails/delivery_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ def prepare_recipients_from mail, sparkpost_data

def prepare_addresses emails, names
emails = [emails] unless emails.is_a?(Array)
emails.each_with_index.map {|email, index| prepare_address(email, index, names) }
header_to = emails.join(",")
emails.each_with_index.map {|email, index| prepare_address(email, index, names, header_to) }
end

def prepare_address email, index, names
def prepare_address email, index, names, header_to
if !names[index].nil?
{ address: { email: email, name: names[index] } }
{ address: { email: email, name: names[index], header_to: header_to } }
else
{ address: { email: email } }
{ address: { email: email, header_to: header_to } }
end
end

Expand Down
37 changes: 29 additions & 8 deletions spec/bcc_recipients_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
test_email = Mailer.test_email bcc: "[email protected]"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]"}}, {address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", header_to: anything}}),
{address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content]).not_to include(:headers)
end

it "handles name and email" do
test_email = Mailer.test_email to: "Joe Test <[email protected]>, Sam Test <[email protected]>", bcc: "Brock Test <[email protected]>"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]", name: "Joe Test"}}, {address: {email: "[email protected]", name: "Sam Test"}}, {address: {email: "[email protected]", name: "Brock Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", name: "Joe Test", header_to: anything}}),
a_hash_including({address: {email: "[email protected]", name: "Sam Test", header_to: anything}}),
{address: {email: "[email protected]", name: "Brock Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content]).not_to include(:headers)
end
end
Expand All @@ -31,23 +34,30 @@
test_email = Mailer.test_email bcc: "[email protected], [email protected]"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]"}}, {address: {email: "[email protected]", header_to: "[email protected]"}}, {address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", header_to: anything}}),
{address: {email: "[email protected]", header_to: "[email protected]"}},
{address: {email: "[email protected]", header_to: "[email protected]"}}])

expect(@delivery_method.data[:content]).not_to include(:headers)
end

it "handles name and email" do
test_email = Mailer.test_email to: "Joe Test <[email protected]>", bcc: "Brock Test <[email protected]>, Brack Test <[email protected]>"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]", name: "Joe Test"}}, {address: {email: "[email protected]", name: "Brock Test", header_to: "[email protected]"}}, {address: {email: "[email protected]", name: "Brack Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", name: "Joe Test", header_to: anything}}),
{address: {email: "[email protected]", name: "Brock Test", header_to: "[email protected]"}},
{address: {email: "[email protected]", name: "Brack Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content]).not_to include(:headers)
end

it "handles mix of email only and name/email" do
test_email = Mailer.test_email to: "Joe Test <[email protected]>", bcc: "Brock Test <[email protected]>, [email protected]"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]", name: "Joe Test"}}, {address: {email: "[email protected]", name: "Brock Test", header_to: "[email protected]"}}, {address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", name: "Joe Test", header_to: anything}}),
{address: {email: "[email protected]", name: "Brock Test", header_to: "[email protected]"}},
{address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content]).not_to include(:headers)
end
end
Expand All @@ -57,23 +67,34 @@
test_email = Mailer.test_email to: "[email protected], [email protected]", cc: "[email protected]", bcc: "[email protected]"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]"}}, {address: {email: "[email protected]"}}, {address: {email: "[email protected]", header_to: "[email protected]"}}, {address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", header_to: anything}}),
a_hash_including({address: {email: "[email protected]", header_to: anything}}),
{address: {email: "[email protected]", header_to: "[email protected]"}},
{address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]"]})
end

it "handles name and email" do
test_email = Mailer.test_email to: "Joe Test <[email protected]>, Sam Test <[email protected]>", cc: "Carl Test <[email protected]>", bcc: "Brock Test <[email protected]>"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]", name: "Joe Test"}}, {address: {email: "[email protected]", name: "Sam Test"}}, {address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}}, {address: {email: "[email protected]", name: "Brock Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", name: "Joe Test", header_to: anything}}),
a_hash_including({address: {email: "[email protected]", name: "Sam Test", header_to: anything}}),
{address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}},
{address: {email: "[email protected]", name: "Brock Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]"]})
end

it "handles mix of email only and name/email" do
test_email = Mailer.test_email to: "Joe Test <[email protected]>, [email protected]", cc: "[email protected], Chris Test <[email protected]>", bcc: "Brock Test <[email protected]>, [email protected]"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]", name: "Joe Test"}}, {address: {email: "[email protected]"}}, {address: {email: "[email protected]", header_to: "[email protected]"}}, {address: {email: "[email protected]", name: "Chris Test", header_to: "[email protected]"}}, {address: {email: "[email protected]", name: "Brock Test", header_to: "[email protected]"}}, {address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", name: "Joe Test", header_to: anything}}),
a_hash_including({address: {email: "[email protected]", header_to: anything}}),
{address: {email: "[email protected]", header_to: "[email protected]"}},
{address: {email: "[email protected]", name: "Chris Test", header_to: "[email protected]"}},
{address: {email: "[email protected]", name: "Brock Test", header_to: "[email protected]"}},
{address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]", "[email protected]"]})
end
end
Expand Down
41 changes: 31 additions & 10 deletions spec/cc_recipients_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
test_email = Mailer.test_email cc: "[email protected]"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]"}}, {address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", header_to: anything}}),
{address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]"]})
end

it "handles name and email" do
test_email = Mailer.test_email to: "Joe Test <[email protected]>", cc: "Carl Test <[email protected]>"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]", name: "Joe Test"}}, {address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", name: "Joe Test", header_to: anything}}),
{address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]"]})
end
end
Expand All @@ -30,23 +32,29 @@
test_email = Mailer.test_email cc: "[email protected], [email protected]"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]"}}, {address: {email: "[email protected]", header_to: "[email protected]"}}, {address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", header_to: anything}}),
{address: {email: "[email protected]", header_to: "[email protected]"}},
{address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]", "[email protected]"]})
end

it "handles name and email" do
test_email = Mailer.test_email to: "Joe Test <[email protected]>", cc: "Carl Test <[email protected]>, Chris Test <[email protected]>"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]", name: "Joe Test"}}, {address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}}, {address: {email: "[email protected]", name: "Chris Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", name: "Joe Test", header_to: anything}}),
{address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}},
{address: {email: "[email protected]", name: "Chris Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]", "[email protected]"]})
end

it "handles mix of email only and name/email" do
test_email = Mailer.test_email to: "Joe Test <[email protected]>", cc: "Carl Test <[email protected]>, [email protected]"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]", name: "Joe Test"}}, {address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}}, {address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", name: "Joe Test", header_to: anything}}),
{address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}},
{address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]", "[email protected]"]})
end
end
Expand All @@ -56,15 +64,19 @@
test_email = Mailer.test_email to: "[email protected], [email protected]", cc: "[email protected]"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]"}}, {address: {email: "[email protected]"}}, {address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", header_to: anything}}),
a_hash_including({address: {email: "[email protected]", header_to: anything}}),
{address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]"]})
end

it "handles name and email" do
test_email = Mailer.test_email to: "Joe Test <[email protected]>, Sam Test <[email protected]>", cc: "Carl Test <[email protected]>"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]", name: "Joe Test"}}, {address: {email: "[email protected]", name: "Sam Test"}}, {address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", name: "Joe Test", header_to: anything}}),
a_hash_including({address: {email: "[email protected]", name: "Sam Test", header_to: anything}}),
{address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]"]})
end
end
Expand All @@ -74,23 +86,32 @@
test_email = Mailer.test_email to: "[email protected], [email protected]", cc: "[email protected], [email protected]"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]"}}, {address: {email: "[email protected]"}}, {address: {email: "[email protected]", header_to: "[email protected]"}}, {address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", header_to: anything}}),
a_hash_including({address: {email: "[email protected]", header_to: anything}}),
{address: {email: "[email protected]", header_to: "[email protected]"}},
{address: {email: "[email protected]", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]", "[email protected]"]})
end

it "handles name and email" do
test_email = Mailer.test_email to: "Joe Test <[email protected]>, Sam Test <[email protected]>", cc: "Carl Test <[email protected]>, Chris Test <[email protected]>"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]", name: "Joe Test"}}, {address: {email: "[email protected]", name: "Sam Test"}}, {address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}}, {address: {email: "[email protected]", name: "Chris Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", name: "Joe Test", header_to: anything}}),
a_hash_including({address: {email: "[email protected]", name: "Sam Test", header_to: anything}}),
{address: {email: "[email protected]", name: "Carl Test", header_to: "[email protected]"}},
{address: {email: "[email protected]", name: "Chris Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]", "[email protected]"]})
end

it "handles mix of email only and name/email for to recipients" do
test_email = Mailer.test_email to: "Joe Test <[email protected]>, [email protected]", cc: "[email protected], Chris Test <[email protected]>"
@delivery_method.deliver!(test_email)

expect(@delivery_method.data[:recipients]).to eq([{address: {email: "[email protected]", name: "Joe Test"}}, {address: {email: "[email protected]"}}, {address: {email: "[email protected]", header_to: "[email protected]"}}, {address: {email: "[email protected]", name: "Chris Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:recipients]).to match([a_hash_including({address: {email: "[email protected]", name: "Joe Test", header_to: anything}}),
a_hash_including({address: {email: "[email protected]", header_to: anything}}),
{address: {email: "[email protected]", header_to: "[email protected]"}},
{address: {email: "[email protected]", name: "Chris Test", header_to: "[email protected]"}}])
expect(@delivery_method.data[:content][:headers]).to eq({cc: ["[email protected]", "[email protected]"]})
end
end
Expand Down
Loading

0 comments on commit e8a3085

Please sign in to comment.