Skip to content

Commit

Permalink
Add Mailings.sender_from_line/1
Browse files Browse the repository at this point in the history
  • Loading branch information
wmnnd committed Nov 24, 2024
1 parent d909a88 commit 05ffdfd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
22 changes: 22 additions & 0 deletions lib/keila/mailings/mailings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ defmodule Keila.Mailings do
end)
end

@doc """
Returns the Sender from line in the form of `"Name <[email protected]>"`
If the Sender uses a Send with Keila proxy address, the Reply-to email is printed instead.
"""
@spec sender_from_line(Sender.t()) :: String.t()
def sender_from_line(sender) do
email =
if String.ends_with?(sender.from_email, "@mailings.keilausercontent.com") do
sender.reply_to_email
else
sender.from_email
end

name = sender.from_name || sender.reply_to_name

if name do
"#{name} <#{email}>"
else
email
end
end

@doc """
Updates an existing Sender with given params.
"""
Expand Down
5 changes: 4 additions & 1 deletion lib/keila_web/templates/campaign/_settings_dialog.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@
do: [{gettext("Please select a sender"), nil}],
else: []
) ++
Enum.map(@senders, &{"#{&1.name} (#{&1.from_name} <#{&1.from_email}>)", &1.id}),
Enum.map(
@senders,
&{"#{&1.name} (#{Keila.Mailings.sender_from_line(&1)})", &1.id}
),
class: "text-black w-full"
) %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion lib/keila_web/templates/sender/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<%= sender.name %>
</h2>
<p>
<%= sender.from_name %> &lt;<%= sender.from_email %>&gt;
<%= Keila.Mailings.sender_from_line(sender) %>
</p>
<br />
<a
Expand Down

0 comments on commit 05ffdfd

Please sign in to comment.