From 1b5c4f41e6feec96c0e56bda6c28fb1df30ff694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mihai=20T=C3=A2rnovan?= Date: Thu, 29 Aug 2024 13:41:21 +0300 Subject: [PATCH] Encode strings with backslashes in email name part --- lib/bamboo/adapters/message/encoding.ex | 2 +- test/lib/bamboo/adapters/encoding_test.exs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/bamboo/adapters/message/encoding.ex b/lib/bamboo/adapters/message/encoding.ex index 5edd35b..e7ebb1c 100644 --- a/lib/bamboo/adapters/message/encoding.ex +++ b/lib/bamboo/adapters/message/encoding.ex @@ -29,7 +29,7 @@ defmodule BambooSes.Encoding do """ @spec maybe_rfc1342_encode(String.t()) :: String.t() def maybe_rfc1342_encode(string) when is_binary(string) do - should_encode? = not ascii?(string) || String.contains?(string, ["\"", "?"]) + should_encode? = not ascii?(string) || String.contains?(string, ["\"", "?", "\\"]) if should_encode? do rfc1342_encode(string) diff --git a/test/lib/bamboo/adapters/encoding_test.exs b/test/lib/bamboo/adapters/encoding_test.exs index 29b2f59..fd9dc09 100644 --- a/test/lib/bamboo/adapters/encoding_test.exs +++ b/test/lib/bamboo/adapters/encoding_test.exs @@ -25,8 +25,12 @@ defmodule BambooSes.EncodingTest do end test "encodes special symbols" do - assert Encoding.prepare_address({"Chuck (?) Eager", "chuck@example.com"}) == - ~s("=?utf-8?B?#{Base.encode64("Chuck (?) Eager")}?=" ) + for sym <- ["\"", "?", "\\"], + do: + assert( + Encoding.prepare_address({"Chuck (#{sym}) Eager", "chuck@example.com"}) == + ~s("=?utf-8?B?#{Base.encode64("Chuck (#{sym}) Eager")}?=" ) + ) end test "encodes emojis" do