DockYard / elixir-mail

Build composable mail messages
392 stars 64 forks source link

CC parsing presumes the header is capitalized as "CC", though being defined as "Cc" is at least somewhat of an occurence. #148

Closed LetThereBeDwight closed 8 months ago

LetThereBeDwight commented 2 years ago

Version

0.2.3

Test Case

test "parses a multipart message" do
  message =
    parse_email("""
    To: Test User <user@example.com>, Other User <other@example.com>
    Cc: The Dude <dude@example.com>, Batman <batman@example.com>
    From: Me <me@example.com>
    Reply-To: OtherMe <otherme@example.com>
    Subject: Test email
    Mime-Version: 1.0
    Content-Type: multipart/alternative; boundary=foobar

    --foobar
    Content-Type: text/plain

    This is some text

    --foobar
    Content-Type: text/html

    <h1>This is some HTML</h1>
    --foobar--
    """)

  assert message.headers["cc"] == [
           {"The Dude", "dude@example.com"},
           {"Batman", "batman@example.com"}
         ]
end

This test will fail, it is a trimmed down version of the test defined at test/mail/parsers/rfc_2822_test.exs:42 - the only functional difference is that line 46 CC: The Dude <dude@example.com>, Batman <batman@example.com> is that the header is defined as "Cc" as opposed to "CC"

Steps to reproduce

See above and run that test - not entirely sure what the spec says about this but email from gmail routed through AWS SES -> SNS -> S3 has the header defined as Cc.

Expected Behavior

Should be able to parse the cc header properly.

Actual Behavior

Cannot properly parse cc recipients if the header is defined with "Cc"

htulipe commented 1 year ago

It actually is the case for a bunch of headers which are read case-sensitively. A fix might be to downcase name here and then downcase any header pattern match. Eg: this line would become:

  defp parse_header_value("to", value),

From what I could gather, the spec does not enforce a specific case for headers.

alexpls commented 8 months ago

Hey @LetThereBeDwight - I'm fairly sure this issue will have been resolved by https://github.com/DockYard/elixir-mail/commit/c728ffc74121ba668965cc5e528129f82d631e19.

LetThereBeDwight commented 8 months ago

Hey @LetThereBeDwight - I'm fairly sure this issue will have been resolved by c728ffc.

Yea that should resolve this issue as well, I can close this one.