From 86e85c9920395033f858a3cb0e3bf122e73298a4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Wed, 1 Mar 2017 20:55:53 +0000
Subject: [PATCH 1/2] Properly handle UTF8 in Cc header in emails

Factors out the fix from 2e41b31654b80aeb3e6037fc0b31422c951040c7 and
uses it when Cc-ing patch authors too.
---
 pgcommitfest/commitfest/views.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/pgcommitfest/commitfest/views.py b/pgcommitfest/commitfest/views.py
index 11f427e..b21a823 100644
--- a/pgcommitfest/commitfest/views.py
+++ b/pgcommitfest/commitfest/views.py
@@ -319,6 +319,11 @@ def _review_status_string(reviewstatus):
 	else:
 		return "not tested"
 
+def _user_email_header(user):
+	return formataddr((
+		str(Header(u"%s %s" % (user.first_name, user.last_name), 'utf-8')),
+		UserWrapper(user).email))
+
 @login_required
 @transaction.atomic
 def comment(request, cfid, patchid, what):
@@ -366,12 +371,12 @@ def comment(request, cfid, patchid, what):
 				msg['Subject'] = 'Re: %s' % form.thread.subject
 
 			msg['To'] = settings.HACKERS_EMAIL
-			msg['From'] = formataddr((str(Header(u"%s %s" % (request.user.first_name, request.user.last_name), 'utf-8')), UserWrapper(request.user).email))
+			msg['From'] = _user_email_header(request.user)
 
 			# CC the authors of a patch, if there are any
 			authors = list(patch.authors.all())
 			if len(authors):
-				msg['Cc'] = ", ".join(["%s %s <%s>" % (a.first_name, a.last_name, UserWrapper(a).email) for a in authors])
+				msg['Cc'] = ", ".join([_user_email_header(a) for a in authors])
 
 			msg['Date'] = formatdate(localtime=True)
 			msg['User-Agent'] = 'pgcommitfest'
-- 
2.7.4

