Added an email debug mode which, by default, is enabled
authorChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 8 May 2011 03:45:06 +0000 (22:45 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 8 May 2011 03:45:06 +0000 (22:45 -0500)
mediagoblin.ini
mediagoblin/app.py
mediagoblin/celery_setup/from_celery.py
mediagoblin/util.py

index 951971a98ee98b25a8f1d8797e4f8928f973a6c5..b85f22ea172886059af537ec73eebeb8303c057f 100644 (file)
@@ -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/
 
index ad9e77dfd11a606d0c1fbeabdd338ccbdc442fec..e93e0c4e31e62c3bf7ec2bc38c67addd5bac3147 100644 (file)
@@ -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
index 218ebfeb19f124ee0a21fee61ff195162ee77eed..4ad2c1d1b7f846293beb2567f926b2a80e642db5 100644 (file)
@@ -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'),
index d24b59b6f264e7d1ea0663cf35cedc6b99fd5a7a..8695180a0c0b73519807b1bcc79266b0c258861b 100644 (file)
@@ -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())