DockYard / elixir-mail

Build composable mail messages
392 stars 64 forks source link

Fails to parse multipart message due to Content-Type header case sensitivity #160

Closed alexpls closed 8 months ago

alexpls commented 8 months ago

Version

0.3.1

Test Case

  test "parses multipart emails with case insensitive Content-Type header" do
    raw =
      """
      Content-type: multipart/alternative; boundary=banana
      Mime-Version: 1.0

      --banana
      Content-Type: text/plain; charset=utf-8

      Hi

      --banana--
      """

    message =
      raw
      |> String.replace("\n", "\r\n")
      |> Mail.Parsers.RFC2822.parse()

    refute message.parts == [] # <-- I'd expect this to have one plain text part
  end

Expected Behavior

I can parse a multipart email whose content type header's case is Content-type.

Actual Behavior

I can't. Only emails where the header case is exactly Content-Type will be parsed.

Email headers aren't required to be case sensitive, and indeed I've observed mail servers in the wild sending messages with headers like Content-type instead of Content-Type. When this happens, elixir-mail fails to parse the message as multipart.

This relates to #148

bcardarella commented 8 months ago

Can you try main ?

alexpls commented 8 months ago

@bcardarella Latest commit on master branch works!

I've run my regression tests on emails that previously failed to have their Content-type parsed and they now work as expected.

Thanks for fixing this, and for responding so quickly!

bcardarella commented 8 months ago

Don't thank me, thank the gummies I took two hours ago 🚀

princemaple commented 7 months ago

Would be great to have a release!