From d745feae8d4e914f7b03d27465d6dfa495058097 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Sat, 11 Mar 2017 13:33:08 -0500 Subject: [PATCH] Fix header encoding for To and Cc as well MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Patch in 2e41b31654b80aeb3e6037fc0b31422c951040c7 only handled From and missed the ohher tields. To make this cleaner, move the escpaping code into the UserWrapper class. Reported by Dagfinn Ilmari Mannsåker, but not using his patch --- pgcommitfest/commitfest/views.py | 7 +++---- pgcommitfest/userprofile/util.py | 8 ++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pgcommitfest/commitfest/views.py b/pgcommitfest/commitfest/views.py index 11f427e..c3007b2 100644 --- a/pgcommitfest/commitfest/views.py +++ b/pgcommitfest/commitfest/views.py @@ -11,8 +11,7 @@ from django.conf import settings from datetime import datetime from email.mime.text import MIMEText -from email.utils import formatdate, make_msgid, formataddr -from email.header import Header +from email.utils import formatdate, make_msgid from pgcommitfest.mailqueue.util import send_mail, send_simple_mail from pgcommitfest.userprofile.util import UserWrapper @@ -366,12 +365,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'] = UserWrapper(request.user).encoded_email_header # 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([UserWrapper(a).encoded_email_header for a in authors]) msg['Date'] = formatdate(localtime=True) msg['User-Agent'] = 'pgcommitfest' diff --git a/pgcommitfest/userprofile/util.py b/pgcommitfest/userprofile/util.py index af50caf..89b4e28 100644 --- a/pgcommitfest/userprofile/util.py +++ b/pgcommitfest/userprofile/util.py @@ -1,5 +1,7 @@ from Crypto.Hash import SHA256 from Crypto import Random +from email.utils import formataddr +from email.header import Header from models import UserProfile @@ -29,3 +31,9 @@ class UserWrapper(object): return self.user.email except UserProfile.DoesNotExist: return self.user.email + + @property + def encoded_email_header(self): + return formataddr(( + str(Header(u"%s %s" % (self.user.first_name, self.user.last_name), 'utf-8')), + self.email)) -- 2.39.5