Fix inconsistent handling of upper and lower cases of email addresses. (#7021)

fixes #7016
This commit is contained in:
Dirk Klimpel 2020-07-03 15:03:13 +02:00 committed by GitHub
parent 8097659f6e
commit 21a212f8e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 282 additions and 51 deletions

View file

@ -48,3 +48,26 @@ def check_3pid_allowed(hs, medium, address):
return True
return False
def canonicalise_email(address: str) -> str:
"""'Canonicalise' email address
Case folding of local part of email address and lowercase domain part
See MSC2265, https://github.com/matrix-org/matrix-doc/pull/2265
Args:
address: email address to be canonicalised
Returns:
The canonical form of the email address
Raises:
ValueError if the address could not be parsed.
"""
address = address.strip()
parts = address.split("@")
if len(parts) != 2:
logger.debug("Couldn't parse email address %s", address)
raise ValueError("Unable to parse email address")
return parts[0].casefold() + "@" + parts[1].lower()