From d7397370153b2b0766bb8e405b3c3299cc3835f8 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 11 Oct 2010 22:27:45 +0000 Subject: [PATCH] Fixed #13494 -- Correctly concat an email subject prefix with a translation string. Thanks, hcarvalhoalves and Andi Albrecht. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14157 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/core/mail/__init__.py | 4 ++-- tests/regressiontests/mail/tests.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/django/core/mail/__init__.py b/django/core/mail/__init__.py index d7a868dfc2..8d064223cd 100644 --- a/django/core/mail/__init__.py +++ b/django/core/mail/__init__.py @@ -87,7 +87,7 @@ def mail_admins(subject, message, fail_silently=False, connection=None): """Sends a message to the admins, as defined by the ADMINS setting.""" if not settings.ADMINS: return - EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message, + EmailMessage(u'%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject), message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS], connection=connection).send(fail_silently=fail_silently) @@ -96,7 +96,7 @@ def mail_managers(subject, message, fail_silently=False, connection=None): """Sends a message to the managers, as defined by the MANAGERS setting.""" if not settings.MANAGERS: return - EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message, + EmailMessage(u'%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject), message, settings.SERVER_EMAIL, [a[1] for a in settings.MANAGERS], connection=connection).send(fail_silently=fail_silently) diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py index b0c60d836e..d2f7562d8f 100644 --- a/tests/regressiontests/mail/tests.py +++ b/tests/regressiontests/mail/tests.py @@ -343,3 +343,23 @@ class MailTests(TestCase): settings.ADMINS = old_admins settings.MANAGERS = old_managers + def test_mail_prefix(self): + """Test prefix argument in manager/admin mail.""" + # Regression for #13494. + old_admins = settings.ADMINS + old_managers = settings.MANAGERS + settings.ADMINS = settings.MANAGERS = [('nobody','nobody@example.com')] + + mail_managers(ugettext_lazy('Subject'), 'Content') + self.assertEqual(len(mail.outbox), 1) + message = mail.outbox[0] + self.assertEqual(message.subject, '[Django] Subject') + + mail.outbox = [] + mail_admins(ugettext_lazy('Subject'), 'Content') + self.assertEqual(len(mail.outbox), 1) + message = mail.outbox[0] + self.assertEqual(message.subject, '[Django] Subject') + + settings.ADMINS = old_admins + settings.MANAGERS = old_managers