Code

Ticket #13494: bug13494.diff

File bug13494.diff, 2.4 KB (added by andialbrecht, 4 years ago)
Line 
1diff --git a/django/core/mail/__init__.py b/django/core/mail/__init__.py
2index f9d1210..8a2d9bf 100644
3--- a/django/core/mail/__init__.py
4+++ b/django/core/mail/__init__.py
5@@ -87,7 +87,7 @@ def mail_admins(subject, message, fail_silently=False, connection=None):
6     """Sends a message to the admins, as defined by the ADMINS setting."""
7     if not settings.ADMINS:
8         return
9-    EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message,
10+    EmailMessage(u'%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject), message,
11                  settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS],
12                  connection=connection).send(fail_silently=fail_silently)
13 
14@@ -96,7 +96,7 @@ def mail_managers(subject, message, fail_silently=False, connection=None):
15     """Sends a message to the managers, as defined by the MANAGERS setting."""
16     if not settings.MANAGERS:
17         return
18-    EmailMessage(settings.EMAIL_SUBJECT_PREFIX + subject, message,
19+    EmailMessage(u'%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject), message,
20                  settings.SERVER_EMAIL, [a[1] for a in settings.MANAGERS],
21                  connection=connection).send(fail_silently=fail_silently)
22 
23diff --git a/tests/regressiontests/mail/tests.py b/tests/regressiontests/mail/tests.py
24index 84be585..6b93304 100644
25--- a/tests/regressiontests/mail/tests.py
26+++ b/tests/regressiontests/mail/tests.py
27@@ -414,6 +414,34 @@ Message-ID: ...
28 Content
29 -------------------------------------------------------------------------------
30 
31+# Make sure that adding a prefix works with translated subject (#13494).
32+>>> mail_managers(ugettext_lazy('Subject'), 'Content', connection=connection)
33+Content-Type: text/plain; charset="utf-8"
34+MIME-Version: 1.0
35+Content-Transfer-Encoding: quoted-printable
36+Subject: [Django] Subject
37+From: root@localhost
38+To: nobody@example.com
39+Date: ...
40+Message-ID: ...
41+
42+Content
43+-------------------------------------------------------------------------------
44+
45+>>> mail_admins(ugettext_lazy('Subject'), 'Content', connection=connection)
46+Content-Type: text/plain; charset="utf-8"
47+MIME-Version: 1.0
48+Content-Transfer-Encoding: quoted-printable
49+Subject: [Django] Subject
50+From: root@localhost
51+To: nobody@example.com
52+Date: ...
53+Message-ID: ...
54+
55+Content
56+-------------------------------------------------------------------------------
57+
58+
59 >>> settings.ADMINS = old_admins
60 >>> settings.MANAGERS = old_managers
61