Skip to content

Commit

Permalink
Merge branch 'release/1.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
tgautier committed Aug 23, 2016
2 parents 21df42f + cd23034 commit 8010a51
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 25 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## 1.2.1 - 2016-08-23

* Fix From/To headers passed to gen_smtp not to be formated that caused an error with some SMTP cloud providers like Amazon SES ([#31])

[#31]: https://github.com/fewlinesco/bamboo_smtp/pull/31

## 1.2.0 - 2016-08-02

* Fix order of name/email in `format_email` function ([#22])
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The package can be installed as:

```elixir
def deps do
[{:bamboo_smtp, "~> 1.2.0"}]
[{:bamboo_smtp, "~> 1.2.1"}]
end
```

Expand Down
23 changes: 12 additions & 11 deletions lib/bamboo/adapters/smtp_adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,17 @@ defmodule Bamboo.SMTPAdapter do
|> raise_on_missing_configuration(config)
end

defp format_email({nil, email}), do: email
defp format_email({name, email}), do: "#{name}<#{email}>"
defp format_email(emails) when is_list(emails) do
Enum.map(emails, &format_email/1)
defp format_email({nil, email}, _format), do: email
defp format_email({name, email}, true), do: "#{name} <#{email}>"
defp format_email({_name, email}, false), do: email
defp format_email(emails, format) when is_list(emails) do
Enum.map(emails, &format_email(&1, format))
end

defp format_email(email, type) do
defp format_email(email, type, format \\ true) do
email
|> Bamboo.Formatter.format_email_address(type)
|> format_email
|> format_email(format)
end

defp format_email_as_string(emails) when is_list(emails) do
Expand All @@ -234,9 +235,9 @@ defmodule Bamboo.SMTPAdapter do
|> format_email_as_string
end

defp from(%Bamboo.Email{from: from}) do
defp from_without_format(%Bamboo.Email{from: from}) do
from
|> format_email(:from)
|> format_email(:from, false)
end

defp put_default_configuration(config) do
Expand Down Expand Up @@ -268,14 +269,14 @@ defmodule Bamboo.SMTPAdapter do
"""
end

defp to(%Bamboo.Email{} = email) do
defp to_without_format(%Bamboo.Email{} = email) do
email
|> Bamboo.Email.all_recipients
|> format_email(:to)
|> format_email(:to, false)
end

defp to_gen_smtp_message(%Bamboo.Email{} = email) do
{from(email), to(email), body(email)}
{from_without_format(email), to_without_format(email), body(email)}
end

defp to_gen_smtp_server_config(config) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule BambooSmtp.Mixfile do

def project do
[app: :bamboo_smtp,
version: "1.2.0",
version: "1.2.1",
elixir: "~> 1.2",
source_url: @project_url,
homepage_url: @project_url,
Expand Down
26 changes: 14 additions & 12 deletions test/lib/bamboo/adapters/smtp_adapter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule Bamboo.SMTPAdapterTest do

defp check_email({from, _to, _raw}) do
case from do
"Wrong User<[email protected]>" ->
"[email protected]" ->
{:error, :no_more_hosts, {:permanent_failure,
"an-smtp-adddress", "554 Message rejected: Email address is not verified.\r\n"}}
_ ->
Expand Down Expand Up @@ -210,8 +210,8 @@ defmodule Bamboo.SMTPAdapterTest do
raw_email,
capture: :all_but_first)

assert format_email_as_string(bamboo_email.from) == from
assert format_email(bamboo_email.to ++ bamboo_email.cc ++ bamboo_email.bcc) == to
assert format_email_as_string(bamboo_email.from, false) == from
assert format_email(bamboo_email.to ++ bamboo_email.cc ++ bamboo_email.bcc, false) == to

rfc822_subject = "Subject: =?UTF-8?B?SGVsbG8gZnJvbSBCYW1ib28=?=\r\n"
assert String.contains?(raw_email, rfc822_subject)
Expand Down Expand Up @@ -249,8 +249,8 @@ defmodule Bamboo.SMTPAdapterTest do
raw_email,
capture: :all_but_first)

assert format_email_as_string(bamboo_email.from) == from
assert format_email(bamboo_email.to ++ bamboo_email.cc ++ bamboo_email.bcc) == to
assert format_email_as_string(bamboo_email.from, false) == from
assert format_email(bamboo_email.to ++ bamboo_email.cc ++ bamboo_email.bcc, false) == to

rfc822_subject = "Subject: =?UTF-8?B?SGVsbG8gZnJvbSBCYW1ib28=?=\r\n"
assert String.contains?(raw_email, rfc822_subject)
Expand Down Expand Up @@ -288,8 +288,8 @@ defmodule Bamboo.SMTPAdapterTest do
raw_email,
capture: :all_but_first)

assert format_email_as_string(bamboo_email.from) == from
assert format_email(bamboo_email.to ++ bamboo_email.cc ++ bamboo_email.bcc) == to
assert format_email_as_string(bamboo_email.from, false) == from
assert format_email(bamboo_email.to ++ bamboo_email.cc ++ bamboo_email.bcc, false) == to

rfc822_subject = "Subject: =?UTF-8?B?SGVsbG8gZnJvbSBCYW1ib28=?=\r\n"
assert String.contains?(raw_email, rfc822_subject)
Expand Down Expand Up @@ -327,17 +327,19 @@ defmodule Bamboo.SMTPAdapterTest do
assert String.contains?(raw_email, rfc822_subject)
end

defp format_email(emails), do: format_email(emails, true)

defp format_email({name, email}), do: "#{name}<#{email}>"
defp format_email(emails) when is_list(emails) do
emails |> Enum.map(&format_email/1)
defp format_email({name, email}, true), do: "#{name} <#{email}>"
defp format_email({_name, email}, false), do: email
defp format_email(emails, format) when is_list(emails) do
emails |> Enum.map(&format_email_as_string(&1, format))
end

defp format_email_as_string(emails) when is_list(emails) do
emails |> format_email |> Enum.join(", ")
end
defp format_email_as_string(email) do
format_email(email)
defp format_email_as_string(email, format \\ true) do
format_email(email, format)
end

defp assert_configuration(bamboo_config, gen_smtp_config) do
Expand Down

0 comments on commit 8010a51

Please sign in to comment.