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
Email address display name fails with both encoded words and special chars #81663
Comments
Special characters in email headers are normally put within double quotes. However, encoded words (=?charset?x?...?=) are not allowed withing double quotes. When the header contains a word with special characters and another word that must be encoded, the first one must also be encoded. In the next example, The From header is quoted and therefore the comma is allowed; in the To header, the comma is not within quotes and not encoded, which is not allowed and rejected. From: "Foo Bar, France" <foo@example.com> |
FYI, it would have been most helpful if you had posted your example in the issue text instead of as an attached file, as it explains the problem better than your text does :) Here is a minimal reproducer: >>> m = EmailMessage(policy=strict)
>>> m['From'] = '"Foo Bar, España" <foo@example.com>'
>>> bytes(m)
b'From: Foo Bar, =?utf-8?q?Espa=C3=B1a?= <foo@example.com>\n\n' This serialization of the header is, as you say, invalid. Either the comma should be encoded, or the "Foo Bar," should be in quotes. |
Hello David, thank you for the suggestion. Regarding your comment:
According to RFC5322 the display name cannot contain both a quoted part and an encoded word, so the only option is to encode the comma. Please let me know if I can do anything else. |
The display name is a phrase, and a phrase is a sequence of words, and a word is either a quoted string or an atom. So it is legal to mix quoted strings and encoded words in a display name. I'd vote to do whichever one is easier to implement :) (I haven't looked at your PR yet and unfortunately my time is limited :( |
Yes, you are right! The fix is to encode the special characters. |
I manually merged the stalled 3.8 backport to make 3.8.0b4. Can this issue now be closed? |
Thank you all! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: