From: Magnus Hagander Date: Tue, 28 Feb 2017 12:43:08 +0000 (+0100) Subject: Properly handle UTF8 in sender names in emails X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=2e41b31654b80aeb3e6037fc0b31422c951040c7;p=pgcommitfest2.git Properly handle UTF8 in sender names in emails We need to treat them as structured and escape only the name, not the email part. Reported by Dagfinn Ilmari Mannsåker --- diff --git a/pgcommitfest/commitfest/views.py b/pgcommitfest/commitfest/views.py index 5fda5b2..11f427e 100644 --- a/pgcommitfest/commitfest/views.py +++ b/pgcommitfest/commitfest/views.py @@ -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())