diff options
author | Ben Banfield-Zanin <benbz@matrix.org> | 2020-09-15 11:44:49 +0100 |
---|---|---|
committer | Ben Banfield-Zanin <benbz@matrix.org> | 2020-09-15 11:44:49 +0100 |
commit | 1a7d96aa6ff81638f2ea696fdee2ec44e7bff75a (patch) | |
tree | 1839e80f89c53b34ff1b36974305c6cb0c94aab4 /synapse/util/threepids.py | |
parent | Fix group server for older synapse (diff) | |
parent | Clarify changelog. (diff) | |
download | synapse-1a7d96aa6ff81638f2ea696fdee2ec44e7bff75a.tar.xz |
Merge remote-tracking branch 'origin/release-v1.20.0' into bbz/info-mainline-1.20.0 github/bbz/info-mainline-1.20.0 bbz/info-mainline-1.20.0
Diffstat (limited to 'synapse/util/threepids.py')
-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 20cf4c4a81..bd63b9107e 100644 --- a/synapse/util/threepids.py +++ b/synapse/util/threepids.py @@ -74,3 +74,26 @@ async 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() |