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

Use "non-strict" parsing for email.utils.getaddresses #4021

Closed
wants to merge 2 commits into from

Conversation

petschki
Copy link
Member

@petschki petschki commented Oct 8, 2024

fixes #4020

@mister-roboto
Copy link

@petschki thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

@petschki petschki force-pushed the getaddressess_strict_parsing branch from 61fc4d1 to 8243eb8 Compare October 8, 2024 12:33
@petschki
Copy link
Member Author

petschki commented Oct 8, 2024

@jenkins-plone-org please run jobs

Copy link
Sponsor Member

@mauritsvanrees mauritsvanrees left a comment

Choose a reason for hiding this comment

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

It sounds a bit weird: the test expects that "email\nemail" fails, which it does not, and you fix it by being less strict. I don't quite follow the logic, but I see locally that this fixes a test failure, also on Python 3.10.

@mauritsvanrees
Copy link
Sponsor Member

Can be merged when green.

@petschki
Copy link
Member Author

petschki commented Oct 8, 2024

in our case strict=False means "old parsing behavior" ... what I don't really understand is the new parsing behavior that when you do getaddresses(["[email protected]\[email protected]"]) you get [("", "")] back:

>>> email.utils.getaddresses(["[email protected]\[email protected]"])
[('', '')]
>>> email.utils.getaddresses(["[email protected]\[email protected]"], strict=False)
[('', '[email protected]'), ('', '[email protected]')]
>>>

@yurj
Copy link
Contributor

yurj commented Oct 8, 2024

python/cpython#102988 maybe this?

From the tests in the python email package (python/cpython@2a9273a), I think the problem is the use of '\n' in the Plone test.

@petschki
Copy link
Member Author

petschki commented Oct 9, 2024

Update: I think we should update the email validation to follow the actual strict behavior. So inputs like [email protected]\n [email protected] aren't valid anymore. But I found out, that if you separate mails only with a comma it returns the expected result:

python 3.11.10

>>> email.utils.getaddresses(["[email protected],\n [email protected]"])
[('', '[email protected]'), ('', '[email protected]')]
>>> email.utils.getaddresses(["[email protected]\n [email protected]"])
[('', '')]

python 3.11.5

>>> email.utils.getaddresses(["[email protected],\n [email protected]"])
[('', '[email protected]'), ('', '[email protected]')]
>>> email.utils.getaddresses(["[email protected]\n [email protected]"])
[('', '[email protected]'), ('', '[email protected]')]

So in addition to the len() I'd check for the fallback return value [('', '')] here https://github.com/plone/Products.CMFPlone/blob/master/Products/CMFPlone/PloneTool.py#L163
Checking for an empty address in validateSingleNormalizedEmailAddress() is the better idea because EMAIL_RE.sub("", "") is always empty (therefore True).

What do you think? -> see #4023

@mauritsvanrees
Copy link
Sponsor Member

What I still don't get is why these tests pass fine on Jenkins with the CMFPlone master branch, but locally they fail.
Ah, if you already get a difference between Python 3.11.10 and 3.11.15, then that may be the explanation. Locally I have all the latest bugfix releases installed, and Jenkins probably lags a bit behind.

Also, https://docs.python.org/3/library/email.utils.html says the "strict" parameter was introduced in 3.13. But the links you pointed to in issue #4020 already mention this in the release notes of 3.11 and 3.12. Ah, those are also notes for bug fix releases, they were not yet in the first final releases.

Meanwhile locally I see that even the latest Python 3.8 has the "strict" parameter.

So indeed the way to go is not to rely on getaddresses working properly, but to have our own extra checks.

@mauritsvanrees
Copy link
Sponsor Member

Closing this PR in favour of #4023

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.

email.utils.getaddresses was changed to "strict-parsing" in Python 3.11.10 and 3.12.6
4 participants