Commit 69772ccd2b333c822b4c999f260dfdc7aa824b04
1 parent
fa6c79ff
Exists in
master
and in
39 other branches
send mail to user when email subject field is blank - closes #42
Showing
2 changed files
with
30 additions
and
0 deletions
Show diff stats
src/super_archives/management/commands/import_emails.py
| @@ -11,7 +11,10 @@ from optparse import make_option | @@ -11,7 +11,10 @@ from optparse import make_option | ||
| 11 | 11 | ||
| 12 | from django.db import transaction | 12 | from django.db import transaction |
| 13 | from django.template.defaultfilters import slugify | 13 | from django.template.defaultfilters import slugify |
| 14 | +from django.core.mail.message import EmailMessage | ||
| 14 | from django.core.management.base import BaseCommand, CommandError | 15 | from django.core.management.base import BaseCommand, CommandError |
| 16 | +from django.template.loader import render_to_string | ||
| 17 | +from django.utils.translation import ugettext as _ | ||
| 15 | 18 | ||
| 16 | from super_archives.models import MailingList, Message, \ | 19 | from super_archives.models import MailingList, Message, \ |
| 17 | Thread, EmailAddress | 20 | Thread, EmailAddress |
| @@ -196,6 +199,22 @@ class Command(BaseCommand, object): | @@ -196,6 +199,22 @@ class Command(BaseCommand, object): | ||
| 196 | email_addr.save() | 199 | email_addr.save() |
| 197 | 200 | ||
| 198 | subject = email_msg.get_subject() | 201 | subject = email_msg.get_subject() |
| 202 | + if not subject: | ||
| 203 | + no_subject_mail = EmailMessage( | ||
| 204 | + subject=_( | ||
| 205 | + u"[Colab] Warning - Email sent with a blank subject." | ||
| 206 | + ), | ||
| 207 | + body=render_to_string( | ||
| 208 | + u'superarchives/emails/email_blank_subject.txt', | ||
| 209 | + { | ||
| 210 | + 'email_body': email_msg.get_body(), | ||
| 211 | + 'mailinglist': mailinglist.name, | ||
| 212 | + 'user': email_addr.get_full_name() | ||
| 213 | + } | ||
| 214 | + ), | ||
| 215 | + to=[email_addr.address, ] | ||
| 216 | + ) | ||
| 217 | + no_subject_mail.send() | ||
| 199 | 218 | ||
| 200 | email = Message.all_objects.create( | 219 | email = Message.all_objects.create( |
| 201 | message_id=email_msg.get('Message-ID'), | 220 | message_id=email_msg.get('Message-ID'), |
src/super_archives/templates/superarchives/emails/email_blank_subject.txt
0 → 100644
| @@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
| 1 | +{% load i18n %} | ||
| 2 | +{% trans 'Hello' %} {{ user }}, | ||
| 3 | +{% blocktrans with body=email_body mailinglist=mailinglist %} | ||
| 4 | +You've sent an email to {{ mailinglist }} with a blank subject and the following content: | ||
| 5 | + | ||
| 6 | +"{{ body }}" | ||
| 7 | + | ||
| 8 | +Please, fill the subject in every email you send it. | ||
| 9 | + | ||
| 10 | +Thank you. | ||
| 11 | +{% endblocktrans %} |