summary refs log tree commit diff
path: root/synapse/util/threepids.py
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/util/threepids.py')
-rw-r--r--synapse/util/threepids.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/synapse/util/threepids.py b/synapse/util/threepids.py

index 34ce7cac16..cfdaa1c5d9 100644 --- a/synapse/util/threepids.py +++ b/synapse/util/threepids.py
@@ -78,3 +78,26 @@ def check_3pid_allowed(hs, medium, address): defer.returnValue(True) defer.returnValue(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()