Fix email headers

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-04-27 09:06:28 +02:00
parent cdedd0ef27
commit 6d99b04a7a
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773

View file

@ -5,7 +5,6 @@ defmodule Mobilizon.Web.Email do
use Bamboo.Phoenix, view: Mobilizon.Web.EmailView
alias Ecto.UUID
alias Mobilizon.{Config, Events}
alias Mobilizon.Events.Event
alias Mobilizon.Service.Export.ICalendar
@ -19,27 +18,27 @@ defmodule Mobilizon.Web.Email do
|> new_email()
|> from({Config.instance_name(), Config.instance_email_from()})
|> put_header("Reply-To", Config.instance_email_reply_to())
|> put_header("Date", date())
|> put_header("Message-Id", message_id())
|> maybe_put_date_header()
|> maybe_put_message_id()
|> assign(:instance, instance)
|> put_html_layout({EmailView, "email.html"})
|> put_text_layout({EmailView, "email.text"})
end
# Generating an UUID randomly causes Bamboo.Test.assert_delivered_email/1 to fail
defp message_id do
defp maybe_put_message_id(email) do
if Application.fetch_env!(:mobilizon, :env) == :test do
"TEST_ENV_MESSAGE_ID@#{Config.instance_hostname()}"
put_header(email, "Message-Id", "TEST_ENV_MESSAGE_ID@#{Config.instance_hostname()}")
else
"#{UUID.generate()}@#{Config.instance_hostname()}"
email
end
end
defp date do
defp maybe_put_date_header(email) do
if Application.fetch_env!(:mobilizon, :env) == :test do
"REMOVED FOR TESTING"
put_header(email, "Date", "REMOVED FOR TESTING")
else
Timex.format!(DateTime.utc_now(), "{WDshort}, {D} {Mshort} {YYYY} {h24}:{m}:{s} {Z}")
email
end
end