diff options
author | Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> | 2020-07-03 15:03:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-03 14:03:13 +0100 |
commit | 21a212f8e50343e9b55944fa75ece7911fd2cb70 (patch) | |
tree | 01fa808e274bea9593cff5784a577f8e0f313430 /synapse/util | |
parent | Allow YAML config file to contain None (#7779) (diff) | |
download | synapse-21a212f8e50343e9b55944fa75ece7911fd2cb70.tar.xz |
Fix inconsistent handling of upper and lower cases of email addresses. (#7021)
fixes #7016
Diffstat (limited to 'synapse/util')
-rw-r--r-- | synapse/util/threepids.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/synapse/util/threepids.py b/synapse/util/threepids.py index 3ec1dfb0c2..43c2e0ac23 100644 --- a/synapse/util/threepids.py +++ b/synapse/util/threepids.py @@ -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() |