From 98613e1a6f31c8d6de036397f082fdea102ea6f5 Mon Sep 17 00:00:00 2001 From: Dejan Strbac Date: Fri, 29 Jul 2016 15:12:39 +0200 Subject: [PATCH] updated for elixir 1.3 --- .DS_Store | Bin 6148 -> 0 bytes .gitignore | 1 + lib/mailex/address.ex | 37 ++++++++++++++---------------------- lib/mailex/render.ex | 43 +++++++++++++++++------------------------- test/.DS_Store | Bin 6148 -> 0 bytes 5 files changed, 32 insertions(+), 49 deletions(-) delete mode 100644 .DS_Store delete mode 100644 test/.DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 7acdae2d41ca15ec4aab8271549bc2ae5c321d6a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK&1%~~5Z-m%R!(zJNdtji_FC}4rY=rzis~E-29<=;1Xrp=y&xoGt!;ua=-kK1 zPus@`gybFiD7|%NcP$c}Ttic4#LPDu&8)QFnq3cLjQf+g&6vv=b3hSm4KQ~IK1W@V znvJXhavUR?6{9H4Be?&wl1+hskpW!0I#VoR1yeWIFB+w?P_5Q)UR$d_dHT$0tgmmt z<-XWB3WoVCP@$R>emMTD?_``r*6)XExb#2fd0P2lv@es{znM!rsXgF{U-0k^%XQ$H??RVWpQ_Q>F zR#SA|bQcTv!f{@`e!KhO(`fPifEaij4A|YvdHy&)m%fr1AO;?g0o)%1D57VvG^n=@FuDZ* ztV37}_}EKejj-rhEDgdF5N=8VO)0l61~=sp7dFqcSQ<3tjN9ge+c$IDp>X|n7+>gg z#yx{%i2-8ZHUrrEfw*}7@7>@3>m)M705R}?GQjJ-py$Kf?Af|9OFU}@=oe5F%qtC6 lCE)0z7;^C_-UihIae)q?XR$O05fJ(#plKjO3_K_Ue*ut%X>b4l diff --git a/.gitignore b/.gitignore index 755b605..2311b3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.DS_Store /_build /cover /deps diff --git a/lib/mailex/address.ex b/lib/mailex/address.ex index 9afc2f9..fd8a318 100644 --- a/lib/mailex/address.ex +++ b/lib/mailex/address.ex @@ -1,10 +1,8 @@ defmodule Mailex.Address do defstruct name: nil, address: nil - def rfc_822_format(emails) when is_list(emails), do: - emails |> Enum.map(&rfc_822_format(&1)) - + Enum.map(emails, &rfc_822_format(&1)) def rfc_822_format(email) when is_map(email) do email_address = Map.get(email, "address", Map.get(email, :address)) @@ -14,17 +12,21 @@ defmodule Mailex.Address do "#{email_name} <#{email_address}>" 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 - if email_name do - email_name = String.strip(email_name) - else - email_name = address |> - String.split("@") |> - List.first |> - String.split(~r/([^\w\s]|_)/) |> - Enum.map(&String.capitalize/1) |> - Enum.join(" ") + email_name = case email_name do + nil -> address + |> String.split("@") + |> List.first + |> String.split(~r/([^\w\s]|_)/) + |> Enum.map(&String.capitalize/1) + |> Enum.join(" ") + _ -> String.strip(email_name) end if String.match?(email_name, ~r/[\(\)\<\>\@\,\;\:\"\.\[\]\\]/) do "\"\\\"" <> String.replace(email_name, "\"", "\\\"") <> "\\\"\"" @@ -33,15 +35,4 @@ defmodule Mailex.Address do 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 diff --git a/lib/mailex/render.ex b/lib/mailex/render.ex index 7003d95..355dcf1 100644 --- a/lib/mailex/render.ex +++ b/lib/mailex/render.ex @@ -3,15 +3,14 @@ defmodule Mailex.Render do alias Mailex.Address def render(email) do - mimemail_args = [] - if email.text, do: - mimemail_args = [ { :plain, email.text } | mimemail_args] - if email.html, do: - mimemail_args = [ { :html, email.html } | mimemail_args] - if email.attachments, do: - mimemail_args = [ Enum.map(email.attachments, fn(a) -> { :attachment, a.data, a } end) | mimemail_args ] + mimemail_args = if email.text, do: + [ { :plain, email.text } ], else: [] + mimemail_args = if email.html, do: + [ { :html, email.html } | mimemail_args], else: mimemail_args + mimemail_args = if email.attachments, do: + [ Enum.map(email.attachments, fn(a) -> { :attachment, a.data, a } end) | mimemail_args ], else: mimemail_args - mimemail_args |> List.flatten |> to_tuple(email) |> :mimemail.encode + List.flatten(mimemail_args) |> to_tuple(email) |> :mimemail.encode end @@ -107,24 +106,16 @@ defmodule Mailex.Render 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 } ] - + headers = if email.reply_to && (length(email.reply_to) > 0), do: + [ { "Reply-To", email.reply_to |> stringify_addresses } ], else: [] # BCC should not go into headers - - if email.cc && (length(email.cc) > 0), do: - headers = [ { "Cc", email.cc |> stringify_addresses } | headers ] - - if email.to && (length(email.to) > 0), do: - headers = [ { "To", email.to |> stringify_addresses } | headers ] - - if email.headers && (length(email.headers) > 0), do: - headers = headers ++ email.headers - - [ { "From", email.from |> stringify_addresses }, - { "Subject", email.subject || "" } | headers ] + headers = if email.cc && (length(email.cc) > 0), do: + [ { "Cc", email.cc |> stringify_addresses } | headers ], else: headers + headers = if email.to && (length(email.to) > 0), do: + [ { "To", email.to |> stringify_addresses } | headers ], else: headers + headers = if email.headers && (length(email.headers) > 0), do: + headers ++ email.headers, else: headers + [ { "From", email.from |> stringify_addresses }, { "Subject", email.subject || "" } | headers ] end @@ -141,4 +132,4 @@ defmodule Mailex.Render do end -end \ No newline at end of file +end diff --git a/test/.DS_Store b/test/.DS_Store deleted file mode 100644 index faa1621ce9425202f06babe31f9064b697fa96fd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKPfP1S5Z|rUm#T+|PY}H9Rp_CjQoY4KJqm@0A}Td8!7hZPG^s^OA?Noo{Qofo z(eL0#@#f6#wkXxBsLX_!-()hg$^N$Nb{J#4)(Msvvl(L+C}N=m<^#d!s3TG^kugAy zWBA>)rSi-RW5w}_KUQgSavCmsX8Oo& zCS5o4vQAp_+6U@R2BB~Kx|cNv{!WraL*MgvW!P=lfBz+M=E*p0zbQT3lW~xAYe^># z(nD8|ws}o0%2fI?lG%BwWWm+2=X<@iwUx41TCeuYqF1d}%3@`? z+V9)i@sEyt=-*y?c1ntH9w0t7O*T0G_}Z5)z~*kq=YAwRM0|EdXET?(j6xoI)DE{C``m