Properly handle UTF8 in sender names in emails
authorMagnus Hagander <magnus@hagander.net>
Tue, 28 Feb 2017 12:43:08 +0000 (13:43 +0100)
committerMagnus Hagander <magnus@hagander.net>
Tue, 28 Feb 2017 12:43:08 +0000 (13:43 +0100)
We need to treat them as structured and escape only the name, not the
email part.

Reported by Dagfinn Ilmari MannsÃ¥ker

pgcommitfest/commitfest/views.py

index 5fda5b298fa8e62b8f9f80c102f318f62e04e358..11f427e0798b9f034028bdaf12cfe12fc06cb135 100644 (file)
@@ -11,7 +11,8 @@ from django.conf import settings
 
 from datetime import datetime
 from email.mime.text import MIMEText
-from email.utils import formatdate, make_msgid
+from email.utils import formatdate, make_msgid, formataddr
+from email.header import Header
 
 from pgcommitfest.mailqueue.util import send_mail, send_simple_mail
 from pgcommitfest.userprofile.util import UserWrapper
@@ -365,7 +366,7 @@ def comment(request, cfid, patchid, what):
                                msg['Subject'] = 'Re: %s' % form.thread.subject
 
                        msg['To'] = settings.HACKERS_EMAIL
-                       msg['From'] = "%s %s <%s>" % (request.user.first_name, request.user.last_name, UserWrapper(request.user).email)
+                       msg['From'] = formataddr((str(Header(u"%s %s" % (request.user.first_name, request.user.last_name), 'utf-8')), UserWrapper(request.user).email))
 
                        # CC the authors of a patch, if there are any
                        authors = list(patch.authors.all())