DockYard / elixir-mail

Build composable mail messages
388 stars 61 forks source link

UTF-8 in subject #129

Closed sam701 closed 3 years ago

sam701 commented 3 years ago

The library does not encode UTF-8 characters in the (subject) header. This test fails:

  test "subject" do
    import Mail
    subject = "test üä test"
    txt = Mail.build()
      |> put_subject(subject)
      |> render()
    encoded_subject = "=?UTF-8?Q?" <> Mail.Encoders.QuotedPrintable.encode(subject) <> "?="

    assert String.contains?(txt, encoded_subject)
  end
bcardarella commented 3 years ago

@sam701 can you PR this test?

sam701 commented 3 years ago

@bcardarella do you mean only the test or also the fix?

bcardarella commented 3 years ago

@sam701 if you want to implement the fix by all means :) If you PR this test I can PR your branch with a fix in the near future.

sam701 commented 3 years ago

As far as I understand from rfc 2047 every header value must be word-encoded if it contains any non US-ASCII characters. Also in multipart. But I'm not sure how to handle the choice what encoding (B or Q) to use. Is this the user choice Mail.build_multipart(encoding: :base64) or the encoder decides what encoding to use. 🤔