From: Sebastian Spaeth <Sebastian@SSpaeth.de>
Date: Mon, 7 Jan 2013 09:16:20 +0000 (+0100)
Subject: Normalize the email address in the same way in all places
X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0f9cf6ef32d659a653654f8f07229b044b59e5b2;p=mediagoblin.git

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 <Sebastian@SSpaeth.de>
---

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