Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

failing test for from header parser containing an additional @ #180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kant01ne
Copy link

@kant01ne kant01ne commented Oct 18, 2024

Hello,

Here is a failing test when the sender name contains an @:

  1) test parses utf-8 encoded from (Mail.Parsers.RFC2822Test)
     test/mail/parsers/rfc_2822_test.exs:421
     Assertion with == failed
     code:  assert message.headers["from"] == {"me@examp...", "<[email protected]>"}
     left:  "me@examp..."
     right: {"me@examp...", "<[email protected]>"}
     stacktrace:
       test/mail/parsers/rfc_2822_test.exs:427: (test)

@kant01ne kant01ne force-pushed the error-parsing-utf8-encoded-from-header branch 2 times, most recently from 1af85bb to 1865ef6 Compare October 18, 2024 09:32
@kant01ne kant01ne changed the title failing test for error on parsing utf8 encoded from failing test for from header parser containing an additional @ Oct 18, 2024
@andrewtimberlake
Copy link
Collaborator

Hi @kant01ne

That would be an invalid From header. To be valid, the name should be in quotes.
This test, with a valid quoted recipient, passes correctly:

test "parses utf-8 encoded from" do
  message =
    parse_email("""
    From: "me@examp..." <[email protected]>
    """)

  assert message.headers["from"] == {"me@examp...", "[email protected]"}
end

From: me@examp... <[email protected]>
""")

assert message.headers["from"] == {"me@examp...", "<[email protected]>"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: the expected result would not have the angular brackets.

@kant01ne
Copy link
Author

kant01ne commented Oct 18, 2024

Interesting. The original was an UTF8 encoded from a google comment. Could it be the source of the issue ?

From: =?UTF-8?B?am9obi5kb2VAcmVkYWN0ZS4uLg==?= <[email protected]>

@andrewtimberlake
Copy link
Collaborator

That gets decoded as john.doe.redacte... <[email protected]> which is still correct

@kant01ne kant01ne force-pushed the error-parsing-utf8-encoded-from-header branch from 1865ef6 to efd6ba1 Compare October 19, 2024 11:51
@kant01ne
Copy link
Author

kant01ne commented Oct 19, 2024

Arf, forgive me, the previous value comes from some tests I've done. I've updated the comment and I've updated the UTF8 encoded value in the tests to john.doe@redacte....

1) test parses utf-8 encoded from (Mail.Parsers.RFC2822Test)
     test/mail/parsers/rfc_2822_test.exs:421
     Assertion with == failed
     code:  assert message.headers["from"] == {"john.doe@redacte...", "<[email protected]>"}
     left:  "john.doe@redacte..."
     right: {"john.doe@redacte...", "<[email protected]>"}
     stacktrace:
       test/mail/parsers/rfc_2822_test.exs:427: (test)

@andrewtimberlake
Copy link
Collaborator

Hi @kant01ne, It turns out that we are decoding quoted words too early. RFC 2047 §6.2 specifically states that you cannot decode a header and then guarantee it parses to RFC822

NOTE: Decoding and display of encoded-words occurs after a
structured field body is parsed into tokens. It is therefore
possible to hide 'special' characters in encoded-words which, when
displayed, will be indistinguishable from 'special' characters in the
surrounding text. For this and other reasons, it is NOT generally
possible to translate a message header containing 'encoded-word's to
an unencoded form which can be parsed by an RFC 822 mail reader.

I’ll work on a fix. Thanks for reporting this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants