Compare commits
No commits in common. "da1e914af061126ae3015e20e1cadd41c76996ae" and "ee242ca92a5a6f014720654ed89be1e665558d4d" have entirely different histories.
da1e914af0
...
ee242ca92a
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,3 @@
|
|||||||
.DS_Store
|
|
||||||
/_build
|
/_build
|
||||||
/cover
|
/cover
|
||||||
/deps
|
/deps
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
defmodule Mailex.Address do
|
defmodule Mailex.Address do
|
||||||
defstruct name: nil, address: nil
|
defstruct name: nil, address: nil
|
||||||
|
|
||||||
|
|
||||||
def rfc_822_format(emails) when is_list(emails), do:
|
def rfc_822_format(emails) when is_list(emails), do:
|
||||||
Enum.map(emails, &rfc_822_format(&1))
|
emails |> Enum.map(&rfc_822_format(&1))
|
||||||
|
|
||||||
|
|
||||||
def rfc_822_format(email) when is_map(email) do
|
def rfc_822_format(email) when is_map(email) do
|
||||||
email_address = Map.get(email, "address", Map.get(email, :address))
|
email_address = Map.get(email, "address", Map.get(email, :address))
|
||||||
@ -12,21 +14,17 @@ defmodule Mailex.Address do
|
|||||||
"#{email_name} <#{email_address}>"
|
"#{email_name} <#{email_address}>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def envelope_format(emails) when is_list(emails), do:
|
|
||||||
Enum.map(emails, &envelope_format(&1))
|
|
||||||
|
|
||||||
def envelope_format(email) when is_map(email), do:
|
|
||||||
"<#{Map.get(email, "address", Map.get(email, :address))}>"
|
|
||||||
|
|
||||||
defp prepare_name(email_name, address) do
|
defp prepare_name(email_name, address) do
|
||||||
email_name = case email_name do
|
if email_name do
|
||||||
nil -> address
|
email_name = String.strip(email_name)
|
||||||
|> String.split("@")
|
else
|
||||||
|> List.first
|
email_name = address |>
|
||||||
|> String.split(~r/([^\w\s]|_)/)
|
String.split("@") |>
|
||||||
|> Enum.map(&String.capitalize/1)
|
List.first |>
|
||||||
|> Enum.join(" ")
|
String.split(~r/([^\w\s]|_)/) |>
|
||||||
_ -> String.strip(email_name)
|
Enum.map(&String.capitalize/1) |>
|
||||||
|
Enum.join(" ")
|
||||||
end
|
end
|
||||||
if String.match?(email_name, ~r/[\(\)\<\>\@\,\;\:\"\.\[\]\\]/) do
|
if String.match?(email_name, ~r/[\(\)\<\>\@\,\;\:\"\.\[\]\\]/) do
|
||||||
"\"\\\"" <> String.replace(email_name, "\"", "\\\"") <> "\\\"\""
|
"\"\\\"" <> String.replace(email_name, "\"", "\\\"") <> "\\\"\""
|
||||||
@ -35,4 +33,15 @@ defmodule Mailex.Address do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def envelope_format(emails) when is_list(emails), do:
|
||||||
|
emails |> Enum.map(&envelope_format(&1))
|
||||||
|
|
||||||
|
|
||||||
|
def envelope_format(email) when is_map(email) do
|
||||||
|
email_address = Map.get(email, "address", Map.get(email, :address))
|
||||||
|
"<#{email_address}>"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -3,14 +3,15 @@ defmodule Mailex.Render do
|
|||||||
alias Mailex.Address
|
alias Mailex.Address
|
||||||
|
|
||||||
def render(email) do
|
def render(email) do
|
||||||
mimemail_args = if email.text, do:
|
mimemail_args = []
|
||||||
[ { :plain, email.text } ], else: []
|
if email.text, do:
|
||||||
mimemail_args = if email.html, do:
|
mimemail_args = [ { :plain, email.text } | mimemail_args]
|
||||||
[ { :html, email.html } | mimemail_args], else: mimemail_args
|
if email.html, do:
|
||||||
mimemail_args = if email.attachments, do:
|
mimemail_args = [ { :html, email.html } | mimemail_args]
|
||||||
[ Enum.map(email.attachments, fn(a) -> { :attachment, a.data, a } end) | mimemail_args ], else: mimemail_args
|
if email.attachments, do:
|
||||||
|
mimemail_args = [ Enum.map(email.attachments, fn(a) -> { :attachment, a.data, a } end) | mimemail_args ]
|
||||||
|
|
||||||
List.flatten(mimemail_args) |> to_tuple(email) |> :mimemail.encode
|
mimemail_args |> List.flatten |> to_tuple(email) |> :mimemail.encode
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -106,16 +107,24 @@ defmodule Mailex.Render do
|
|||||||
|
|
||||||
|
|
||||||
def headers_for(email) do
|
def headers_for(email) do
|
||||||
headers = if email.reply_to && (length(email.reply_to) > 0), do:
|
headers = []
|
||||||
[ { "Reply-To", email.reply_to |> stringify_addresses } ], else: []
|
|
||||||
|
if email.reply_to && (length(email.reply_to) > 0), do:
|
||||||
|
headers = [ { "Reply-To", email.reply_to |> stringify_addresses } ]
|
||||||
|
|
||||||
# BCC should not go into headers
|
# BCC should not go into headers
|
||||||
headers = if email.cc && (length(email.cc) > 0), do:
|
|
||||||
[ { "Cc", email.cc |> stringify_addresses } | headers ], else: headers
|
if email.cc && (length(email.cc) > 0), do:
|
||||||
headers = if email.to && (length(email.to) > 0), do:
|
headers = [ { "Cc", email.cc |> stringify_addresses } | headers ]
|
||||||
[ { "To", email.to |> stringify_addresses } | headers ], else: headers
|
|
||||||
headers = if email.headers && (length(email.headers) > 0), do:
|
if email.to && (length(email.to) > 0), do:
|
||||||
headers ++ email.headers, else: headers
|
headers = [ { "To", email.to |> stringify_addresses } | headers ]
|
||||||
[ { "From", email.from |> stringify_addresses }, { "Subject", email.subject || "" } | headers ]
|
|
||||||
|
if email.headers && (length(email.headers) > 0), do:
|
||||||
|
headers = headers ++ email.headers
|
||||||
|
|
||||||
|
[ { "From", email.from |> stringify_addresses },
|
||||||
|
{ "Subject", email.subject || "" } | headers ]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -132,4 +141,4 @@ defmodule Mailex.Render do
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
2
mix.lock
2
mix.lock
@ -1,2 +1,2 @@
|
|||||||
%{"eiconv": {:git, "https://github.com/zotonic/eiconv.git", "644fb5e7bd6640fbd073f4d28957914ea979aea0", []},
|
%{"eiconv": {:git, "https://github.com/zotonic/eiconv.git", "644fb5e7bd6640fbd073f4d28957914ea979aea0", []},
|
||||||
"gen_smtp": {:hex, :gen_smtp, "0.11.0", "d90ff2f021fc86cb2a4259b1f2b177ab6e506676265e26454bf5755855adc956", [:rebar3], []}}
|
"gen_smtp": {:hex, :gen_smtp, "0.9.0"}}
|
||||||
|
BIN
test/.DS_Store
vendored
Normal file
BIN
test/.DS_Store
vendored
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user