Skip to content

Commit

Permalink
Encode strings with backslashes in email name part
Browse files Browse the repository at this point in the history
  • Loading branch information
mtarnovan committed Aug 29, 2024
1 parent 5959bce commit 1b5c4f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/bamboo/adapters/message/encoding.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions test/lib/bamboo/adapters/encoding_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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")}?=" <chuck@example.com>)
for sym <- ["\"", "?", "\\"],
do:
assert(
Encoding.prepare_address({"Chuck (#{sym}) Eager", "chuck@example.com"}) ==
~s("=?utf-8?B?#{Base.encode64("Chuck (#{sym}) Eager")}?=" <chuck@example.com>)
)
end

test "encodes emojis" do
Expand Down

0 comments on commit 1b5c4f4

Please sign in to comment.