diff --git a/lib/bamboo/adapters/render/raw.ex b/lib/bamboo/adapters/render/raw.ex index 1f3d840..e42a1e1 100644 --- a/lib/bamboo/adapters/render/raw.ex +++ b/lib/bamboo/adapters/render/raw.ex @@ -165,13 +165,19 @@ defmodule BambooSes.Render.Raw do [ {"From", mailbox(email.from)}, {"Subject", email.subject} - ] ++ Map.to_list(email.headers) + ] ++ Enum.map(email.headers, &preprocess_header/1) Enum.filter(headers, fn i -> elem(i, 1) != "" end) end defp mailbox({name, address}), do: "#{name} <#{address}>" + defp preprocess_header({"Reply-To" = key, {_name, _address} = value}) do + {key, BambooSes.Encoding.prepare_address(value)} + end + + defp preprocess_header({key, value}), do: {key, value} + defp compile_parts(email) do [ {:plain, email.text_body}, diff --git a/test/lib/bamboo/adapters/ses_adapter_test.exs b/test/lib/bamboo/adapters/ses_adapter_test.exs index dbae6d1..3cbb7b7 100644 --- a/test/lib/bamboo/adapters/ses_adapter_test.exs +++ b/test/lib/bamboo/adapters/ses_adapter_test.exs @@ -340,6 +340,34 @@ defmodule Bamboo.SesAdapterTest do SesAdapter.deliver(TestHelpers.new_email(), %{}) end + test "does not crash with Reply-To tuple and sending raw content" do + expected_request_fn = fn _, _, body, _, _ -> + {:ok, message} = Jason.decode(body) + + %{ + "Content" => %{ + "Raw" => %{ + "Data" => raw_content + } + } + } = message + + email = EmailParser.parse(raw_content) + + assert header_value = EmailParser.header(email, "Reply-To") + assert header_value == "John Schmidt " + + {:ok, %{status_code: 200, body: body}} + end + + expect(HttpMock, :request, expected_request_fn) + + TestHelpers.new_email() + |> Email.put_header("X-Custom-Header", "header-value") + |> Email.put_header("Reply-To", {"John Schmidt", "reply-to@example.com"}) + |> SesAdapter.deliver(%{}) + end + test "uses configured aws region" do expect(HttpMock, :request, fn _, "https://email.eu-west-1.amazonaws.com/v2/email/outbound-emails",