X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=mediagoblin%2Ftools%2Fmail.py;h=4fa02ce5c04be0e5c5e37e332ce043b56aba148d;hb=5c2ece7401723486d76ea0fcd2f99ba4d1002504;hp=9e00be7ded73d647ae8015bcbc49a1f9726478d6;hpb=ee91c2b88d1a42b9d15d34d2c081cd8394649041;p=mediagoblin.git diff --git a/mediagoblin/tools/mail.py b/mediagoblin/tools/mail.py index 9e00be7d..4fa02ce5 100644 --- a/mediagoblin/tools/mail.py +++ b/mediagoblin/tools/mail.py @@ -1,5 +1,5 @@ # GNU MediaGoblin -- federated, autonomous media hosting -# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS. +# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -98,8 +98,9 @@ def send_email(from_addr, to_addrs, subject, message_body): if not mg_globals.app_config['email_smtp_host']: # e.g. host = '' mhost.connect() # We SMTP.connect explicitly - if mg_globals.app_config['email_smtp_user'] \ - or mg_globals.app_config['email_smtp_pass']: + if ((not common.TESTS_ENABLED) + and (mg_globals.app_config['email_smtp_user'] + or mg_globals.app_config['email_smtp_pass'])): mhost.login( mg_globals.app_config['email_smtp_user'], mg_globals.app_config['email_smtp_pass']) @@ -112,7 +113,7 @@ def send_email(from_addr, to_addrs, subject, message_body): if common.TESTS_ENABLED: EMAIL_TEST_INBOX.append(message) - if mg_globals.app_config['email_debug_mode']: + elif mg_globals.app_config['email_debug_mode']: print u"===== Email =====" print u"From address: %s" % message['From'] print u"To addresses: %s" % message['To'] @@ -121,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