Skip to content

Commit

Permalink
introduce better email validation regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Krystof Beuermann committed Jan 15, 2019
1 parent 8f1af52 commit 5f8925c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/bamboo/adapters/rfc2822_with_bcc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ defmodule Bamboo.SesAdapter.RFC2822WithBcc do
@address_types ["From", "To", "Reply-To", "Cc", "Bcc"]

# https://tools.ietf.org/html/rfc2822#section-3.4.1
@email_validation_regex ~r/\w+@\w+\.\w+/
# taken from https://github.com/DockYard/elixir-mail/blob/bc27eba27ea0895a2fc12f5ac00de3e944a7fd8f/lib/mail/renderers/rfc_2822.ex#L25
@email_validation_regex ~r/[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,64}/

@doc """
Renders a message according to the RFC2882 spec
Expand Down
18 changes: 16 additions & 2 deletions test/lib/bamboo/adapters/ses_adapter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ defmodule Bamboo.SesAdapterTest do
alias Mail.Parsers.RFC2822
require IEx

defp new_email do
defp new_email(to \\ "[email protected]") do
Email.new_email(
to: "[email protected]",
to: to,
from: "[email protected]",
cc: "[email protected]",
bcc: "[email protected]",
Expand Down Expand Up @@ -54,6 +54,20 @@ defmodule Bamboo.SesAdapterTest do
new_email() |> SesAdapter.deliver(%{})
end

test "delivers mails with dashes in top level domain successfully" do
expected_request_fn = fn _, _, body, _, _ ->
message = parse_body(body)
assert Mail.get_to(message) == ["[email protected]"]

{:ok, %{status_code: 200}}
end

HttpMock
|> expect(:request, expected_request_fn)

new_email("[email protected]") |> SesAdapter.deliver(%{})
end

test "delivers attachments" do
expected_request_fn = fn _, _, body, _, _ ->
message = parse_body(body)
Expand Down

0 comments on commit 5f8925c

Please sign in to comment.