diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2011-05-07 22:45:06 -0500 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2011-05-07 22:45:06 -0500 |
commit | 29f3fb7052a0a512d5970a936b30175b9c7eef63 (patch) | |
tree | 2fd223953830baba7285cdd01badb4ac0ecb8861 | |
parent | 3eae207c54b6c8fa4c2e122403b4462d93b8b713 (diff) | |
download | mediagoblin-29f3fb7052a0a512d5970a936b30175b9c7eef63.tar.lz mediagoblin-29f3fb7052a0a512d5970a936b30175b9c7eef63.tar.xz mediagoblin-29f3fb7052a0a512d5970a936b30175b9c7eef63.zip |
Added an email debug mode which, by default, is enabled
-rw-r--r-- | mediagoblin.ini | 2 | ||||
-rw-r--r-- | mediagoblin/app.py | 9 | ||||
-rw-r--r-- | mediagoblin/celery_setup/from_celery.py | 1 | ||||
-rw-r--r-- | mediagoblin/util.py | 17 |
4 files changed, 23 insertions, 6 deletions
diff --git a/mediagoblin.ini b/mediagoblin.ini index 951971a9..b85f22ea 100644 --- a/mediagoblin.ini +++ b/mediagoblin.ini @@ -15,6 +15,8 @@ publicstore_base_dir = %(here)s/user_dev/media/public publicstore_base_url = /mgoblin_media/ direct_remote_path = /mgoblin_static/ email_sender_address = "notice@mediagoblin.example.org" +# set to false to enable sending notices +email_debug_mode = true ## Uncomment this to put some user-overriding templates here #local_templates = %(here)s/user_dev/templates/ diff --git a/mediagoblin/app.py b/mediagoblin/app.py index ad9e77df..e93e0c4e 100644 --- a/mediagoblin/app.py +++ b/mediagoblin/app.py @@ -18,6 +18,7 @@ import urllib import routes import mongokit +from paste.deploy.converters import asbool from webob import Request, exc from mediagoblin import routing, util, models, storage, staticdirect @@ -36,7 +37,7 @@ class MediaGoblinApp(object): def __init__(self, connection, database_path, public_store, queue_store, staticdirector, - email_sender_address, + email_sender_address, email_debug_mode, user_template_path=None): # Get the template environment self.template_env = util.get_jinja_env(user_template_path) @@ -61,6 +62,7 @@ class MediaGoblinApp(object): # object. setup_globals( email_sender_address=email_sender_address, + email_debug_mode=email_debug_mode, db_connection=connection, database=self.db, public_store=self.public_store, @@ -141,8 +143,9 @@ def paste_app_factory(global_config, **app_config): connection, app_config.get('db_name', 'mediagoblin'), public_store=public_store, queue_store=queue_store, staticdirector=staticdirector, - email_sender_address=app_config.get('email_sender_address', - 'notice@mediagoblin.example.org'), + email_sender_address=app_config.get( + 'email_sender_address', 'notice@mediagoblin.example.org'), + email_debug_mode=app_config.get('email_debug_mode'), user_template_path=app_config.get('local_templates')) return mgoblin_app diff --git a/mediagoblin/celery_setup/from_celery.py b/mediagoblin/celery_setup/from_celery.py index 218ebfeb..4ad2c1d1 100644 --- a/mediagoblin/celery_setup/from_celery.py +++ b/mediagoblin/celery_setup/from_celery.py @@ -82,6 +82,7 @@ def setup_self(setup_globals_func=setup_globals): db_connection=connection, database=db, public_store=public_store, + email_debug_mode=app_config.get('email_debug_mode'), email_sender_address=mgoblin_section.get( 'email_sender_address', 'notice@mediagoblin.example.org'), diff --git a/mediagoblin/util.py b/mediagoblin/util.py index d24b59b6..8695180a 100644 --- a/mediagoblin/util.py +++ b/mediagoblin/util.py @@ -21,6 +21,8 @@ import sys import jinja2 import mongokit +from mediagoblin import globals as mgoblin_globals + TESTS_ENABLED = False def _activate_testing(): @@ -153,9 +155,9 @@ def send_email(from_addr, to_addrs, subject, message_body): - message_body: email body text """ # TODO: make a mock mhost if testing is enabled - if TESTS_ENABLED: + if TESTS_ENABLED or mgoblin_globals.email_debug_mode: mhost = FakeMhost() - else: + elif not mgoblin_globals.email_debug_mode: mhost = smtplib.SMTP() mhost.connect() @@ -168,4 +170,13 @@ def send_email(from_addr, to_addrs, subject, message_body): if TESTS_ENABLED: EMAIL_TEST_INBOX.append(message) - return mhost.sendmail(from_addr, to_addrs, message.as_string()) + elif mgoblin_globals.email_debug_mode: + print u"===== Email =====" + print u"From address: %s" % message['From'] + print u"To addresses: %s" % message['To'] + print u"Subject: %s" % message['Subject'] + print u"-- Body: --" + print message.get_payload(decode=True) + + else: + return mhost.sendmail(from_addr, to_addrs, message.as_string()) |