From 9e5e9f8352128b67aac50c9c4c277f862d9a8a96 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Thu, 18 Jan 2024 11:39:38 +0100 Subject: [PATCH] DRY-up SMTP LF workaround --- lib/asciinema/emails/email.ex | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/asciinema/emails/email.ex b/lib/asciinema/emails/email.ex index 237b4d5aa..d8af66c9b 100644 --- a/lib/asciinema/emails/email.ex +++ b/lib/asciinema/emails/email.ex @@ -5,27 +5,23 @@ defmodule Asciinema.Emails.Email do def signup_email(email_address, signup_url) do hostname = instance_hostname() - email = - base_email() - |> to(email_address) - |> subject("Welcome to #{hostname}") - |> render("signup.text", signup_url: signup_url, hostname: hostname) - |> render("signup.html", signup_url: signup_url, hostname: hostname) - - %{email | text_body: String.replace(email.text_body, "\n", "\r\n")} + base_email() + |> to(email_address) + |> subject("Welcome to #{hostname}") + |> render("signup.text", signup_url: signup_url, hostname: hostname) + |> render("signup.html", signup_url: signup_url, hostname: hostname) + |> fix_text_body() end def login_email(email_address, login_url) do hostname = instance_hostname() - email = - base_email() - |> to(email_address) - |> subject("Login to #{hostname}") - |> render("login.text", login_url: login_url, hostname: hostname) - |> render("login.html", login_url: login_url, hostname: hostname) - - %{email | text_body: String.replace(email.text_body, "\n", "\r\n")} + base_email() + |> to(email_address) + |> subject("Login to #{hostname}") + |> render("login.text", login_url: login_url, hostname: hostname) + |> render("login.html", login_url: login_url, hostname: hostname) + |> fix_text_body() end def test_email(email_address) do @@ -56,4 +52,8 @@ defmodule Asciinema.Emails.Email do defp instance_hostname do System.get_env("URL_HOST") || "localhost" end + + defp fix_text_body(email) do + %{email | text_body: String.replace(email.text_body, "\n", "\r\n")} + end end