Skip to content

Commit

Permalink
email parse depends on python patch version (move-coop#1146)
Browse files Browse the repository at this point in the history
  • Loading branch information
austinweisgrau authored Oct 10, 2024
1 parent 710532a commit 22c3175
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions test/test_gmail/test_gmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import json
import os
import requests_mock
import email
import unittest
import shutil
import base64
import email


_dir = os.path.dirname(__file__)
Expand Down Expand Up @@ -516,10 +516,27 @@ def test__validate_email_string(self):
{"email": "<[email protected]>", "expected": True},
{"email": "Sender [email protected]", "expected": False},
{"email": "Sender <sender2email.com>", "expected": False},
{"email": "Sender <sender@email,com>", "expected": True},
{"email": "Sender <sender+alias@email,com>", "expected": True},
]

# The behavior of email.parseaddr depends on the python patch version
# See https://github.com/python/cpython/issues/102988
# or associated changelogs, e.g.
# https://docs.python.org/3.8/whatsnew/changelog.html#python-3-8-20-final
if getattr(email.utils, "supports_strict_parsing", False):
emails.extend(
[
{"email": "Sender <sender@email,com>", "expected": False},
{"email": "Sender <sender+alias@email,com>", "expected": False},
]
)
else:
emails.extend(
[
{"email": "Sender <sender@email,com>", "expected": True},
{"email": "Sender <sender+alias@email,com>", "expected": True},
]
)

for e in emails:
if e["expected"]:
self.assertTrue(self.gmail._validate_email_string(e["email"]))
Expand Down

0 comments on commit 22c3175

Please sign in to comment.