aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/util.py')
-rw-r--r--mediagoblin/util.py34
1 files changed, 29 insertions, 5 deletions
diff --git a/mediagoblin/util.py b/mediagoblin/util.py
index 0b6428da..7ff3ec7f 100644
--- a/mediagoblin/util.py
+++ b/mediagoblin/util.py
@@ -1,5 +1,5 @@
# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 Free Software Foundation, Inc
+# Copyright (C) 2011 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
@@ -244,7 +244,7 @@ class FakeMhost(object):
Just a fake mail host so we can capture and test messages
from send_email
"""
- def connect(self):
+ def login(self, *args, **kwargs):
pass
def sendmail(self, from_addr, to_addrs, message):
@@ -274,13 +274,22 @@ def send_email(from_addr, to_addrs, subject, message_body):
- subject: subject of the email
- message_body: email body text
"""
- # TODO: make a mock mhost if testing is enabled
if TESTS_ENABLED or mg_globals.app_config['email_debug_mode']:
mhost = FakeMhost()
elif not mg_globals.app_config['email_debug_mode']:
- mhost = smtplib.SMTP()
+ mhost = smtplib.SMTP(
+ mg_globals.app_config['email_smtp_host'],
+ mg_globals.app_config['email_smtp_port'])
- mhost.connect()
+ # SMTP.__init__ Issues SMTP.connect implicitly if host
+ 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']:
+ mhost.login(
+ mg_globals.app_config['email_smtp_user'],
+ mg_globals.app_config['email_smtp_pass'])
message = MIMEText(message_body.encode('utf-8'), 'plain', 'utf-8')
message['Subject'] = subject
@@ -672,3 +681,18 @@ def render_404(request):
"""
return render_to_response(
request, 'mediagoblin/404.html', {}, status=400)
+
+def delete_media_files(media):
+ """
+ Delete all files associated with a MediaEntry
+
+ Arguments:
+ - media: A MediaEntry document
+ """
+ for listpath in media['media_files'].itervalues():
+ mg_globals.public_store.delete_file(
+ listpath)
+
+ for attachment in media['attachment_files']:
+ mg_globals.public_store.delete_file(
+ attachment['filepath'])