changeset 526:dd97341788fa

For #194, we no longer need the mailer application.
author Brian Neal <bgneal@gmail.com>
date Mon, 19 Dec 2011 01:21:09 +0000
parents a053fbd3ac98
children 645025056dfa
files gpp/mailer/__init__.py gpp/mailer/admin.py gpp/mailer/management/__init__.py gpp/mailer/management/commands/__init__.py gpp/mailer/management/commands/send_mail.py gpp/mailer/models.py gpp/settings/base.py
diffstat 5 files changed, 0 insertions(+), 108 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/mailer/__init__.py	Mon Dec 19 01:11:43 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-from socket import error as socket_error
-import smtplib
-import time
-import logging
-
-import django.core.mail
-
-import mailer.models
-
-
-def enqueue_mail(subject, message, from_email, recipient_list):
-    """Creates mailer mail queue entries for the given email."""
-
-    if len(subject) > mailer.models.MAX_SUBJECT:
-        subject = u'%s...' % subject[:mailer.models.MAX_SUBJECT - 3]
-
-    for recipient in recipient_list:
-        mailer.models.Message(
-                from_address=from_email,
-                to_address=recipient,
-                subject=subject,
-                body=message).save()
-
-
-def send_queued_mail():
-    """Reads the queued messages from the database, sends them, and removes them
-    from the queue."""
-
-    sent, errors = 0, 0
-
-    logging.debug("Sending queued mail...")
-    start_time = time.time()
-
-    msgs = mailer.models.Message.objects.all()
-    for msg in msgs:
-        try:
-            django.core.mail.send_mail(
-                    msg.subject,
-                    msg.body,
-                    msg.from_address,
-                    [msg.to_address],
-                    fail_silently=False)
-        except (socket_error, smtplib.SMTPException), e:
-            errors += 1
-            logging.error("Error sending queued mail: %s", e)
-        else:
-            sent += 1
-            msg.delete()
-
-    end_time = time.time()
-    logging.debug("Sent queued mail: %d successful, %d error(s); elapsed time: %.2f" % (
-        sent, errors, end_time - start_time))
--- a/gpp/mailer/admin.py	Mon Dec 19 01:11:43 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,13 +0,0 @@
-"""This file contains the automatic admin site definitions for the mailer
-application."""
-from django.contrib import admin
-
-from mailer.models import Message
-
-
-class MessageAdmin(admin.ModelAdmin):
-    list_display = ('from_address', 'to_address', 'subject', 'creation_date')
-    list_display_links = ('subject', )
-
-
-admin.site.register(Message, MessageAdmin)
--- a/gpp/mailer/management/commands/send_mail.py	Mon Dec 19 01:11:43 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-"""send_mail is a custom manage.py command for the mailer application.
-It is intended to be called from a cron job periodically to send out queued
-email in bulk. This avoids doing the mailing on the HTTP request processing.
-"""
-from django.core.management.base import NoArgsCommand
-
-import mailer
-
-
-class Command(NoArgsCommand):
-    help = "Run periodically to send out queued email."
-
-    def handle_noargs(self, **options):
-        mailer.send_queued_mail()
-
--- a/gpp/mailer/models.py	Mon Dec 19 01:11:43 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-"""Models for the mailer application."""
-import datetime
-
-from django.db import models
-
-
-MAX_SUBJECT = 120
-
-class Message(models.Model):
-    """The model to represent stored emails in the database."""
-    from_address = models.EmailField()
-    to_address = models.EmailField()
-    subject = models.CharField(max_length=MAX_SUBJECT)
-    body = models.TextField()
-    creation_date = models.DateTimeField()
-
-    class Meta:
-        ordering = ('creation_date', )
-
-    def __unicode__(self):
-        return u'From: %s, To: %s, Subj: %s' % (
-            self.from_address, self.to_address, self.subject)
-
-    def save(self, *args, **kwargs):
-        if self.id is None:
-            self.creation_date = datetime.datetime.now()
-        super(Message, self).save(*args, **kwargs)
--- a/gpp/settings/base.py	Mon Dec 19 01:11:43 2011 +0000
+++ b/gpp/settings/base.py	Mon Dec 19 01:21:09 2011 +0000
@@ -133,7 +133,6 @@
     'gcalendar',
     'irc',
     'legacy',
-    'mailer',
     'membermap',
     'messages',
     'news',