1
0
forked from migadu/mailex

support both formats of email address

This commit is contained in:
Dejan Strbac 2015-12-23 20:03:53 +01:00
parent f40ecb33f8
commit 905405a46e

View File

@ -7,16 +7,19 @@ defmodule Mailex.Address do
def rfc_822_format(email) when is_map(email) do
if email.name do
"#{email.name} <#{email.address}>"
email_address = Map.get(email, "address", Map.get(email, :address))
email_name = Map.get(email, "name", Map.get(email, :name))
if email_name do
"#{email_name} <#{email_address}>"
else
name = email.address |>
name = email_address |>
String.split("@") |>
List.first |>
String.split(~r/([^\w\s]|_)/) |>
Enum.map(&String.capitalize/1) |>
Enum.join " "
"#{name} <#{email.address}>"
"#{name} <#{email_address}>"
end
end
@ -25,8 +28,10 @@ defmodule Mailex.Address do
emails |> Enum.map(&envelope_format(&1))
def envelope_format(email) when is_map(email), do:
"<#{email.address}>"
def envelope_format(email) when is_map(email) do
email_address = Map.get(email, "address", Map.get(email, :address))
"<#{email_address}>"
end
end