From 0f9cf6ef32d659a653654f8f07229b044b59e5b2 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Mon, 7 Jan 2013 10:16:20 +0100 Subject: [PATCH] Normalize the email address in the same way in all places We were case normalizing the email address for registration, but not at all for the forgotten password retrieval. Make a tools.mail.normalize_email helper that can be used to normalize the email in the same way in all places. Signed-off-by: Sebastian Spaeth --- mediagoblin/tools/mail.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mediagoblin/tools/mail.py b/mediagoblin/tools/mail.py index 8639ba0c..4fa02ce5 100644 --- a/mediagoblin/tools/mail.py +++ b/mediagoblin/tools/mail.py @@ -122,3 +122,16 @@ def send_email(from_addr, to_addrs, subject, message_body): print message.get_payload(decode=True) return mhost.sendmail(from_addr, to_addrs, message.as_string()) + + +def normalize_email(email): + """return case sensitive part, lower case domain name + + :returns: None in case of broken email addresses""" + try: + em_user, em_dom = email.split('@', 1) + except ValueError: + # email contained no '@' + return None + email = "@".join((em_user, em_dom.lower())) + return email