diff options
author | Sebastian Spaeth <Sebastian@SSpaeth.de> | 2013-01-07 10:16:20 +0100 |
---|---|---|
committer | Sebastian Spaeth <Sebastian@SSpaeth.de> | 2013-01-21 15:38:57 +0100 |
commit | 0f9cf6ef32d659a653654f8f07229b044b59e5b2 (patch) | |
tree | 161200bb78d0e6177e81c09d5e562212eab6bcd4 | |
parent | 0c97a82556ae66fc5036547105607ef900b40033 (diff) | |
download | mediagoblin-0f9cf6ef32d659a653654f8f07229b044b59e5b2.tar.lz mediagoblin-0f9cf6ef32d659a653654f8f07229b044b59e5b2.tar.xz mediagoblin-0f9cf6ef32d659a653654f8f07229b044b59e5b2.zip |
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>
-rw-r--r-- | mediagoblin/tools/mail.py | 13 |
1 files changed, 13 insertions, 0 deletions
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 |