summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Hagander2017-03-11 18:33:08 +0000
committerMagnus Hagander2017-03-11 18:33:08 +0000
commitd745feae8d4e914f7b03d27465d6dfa495058097 (patch)
tree86968dc466275feb922b182db6387b9a2beaa4b9
parentd49b2b07a8b2422173142729fe8d7624de7ef4c5 (diff)
Fix header encoding for To and Cc as well
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
-rw-r--r--pgcommitfest/commitfest/views.py7
-rw-r--r--pgcommitfest/userprofile/util.py8
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))