From a62a7ec2aeb6e67da239350f514ae166bd29ffc5 Mon Sep 17 00:00:00 2001 From: Adrien Cunin Date: Tue, 2 Aug 2016 16:12:32 +0200 Subject: [PATCH] Handle non-ASCII characters in body and subject Change-Id: I522482c9d8cca1493206988694c8d497bc9d32d5 --- tools/invite2summit/send.py | 28 +++++++++++--------------- tools/invite2summit/settings.py.sample | 7 ++++--- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/tools/invite2summit/send.py b/tools/invite2summit/send.py index bee63688c3..ccaf25c2af 100644 --- a/tools/invite2summit/send.py +++ b/tools/invite2summit/send.py @@ -17,6 +17,7 @@ import csv import email.utils +import email.mime.text import settings import smtplib import sys @@ -27,7 +28,7 @@ from string import Template class ATC(object): def __init__(self, row): self.lpid = row[0] - self.name = row[1] + self.name = unicode(row[1], 'utf8') self.emails = row[2:] @@ -67,22 +68,17 @@ if __name__ == '__main__': content = template.substitute(name=committer.name, code=code, signature=settings.EMAIL_SIGNATURE) - msg = ( - "From: %s\r\n" - "To: %s\r\n" - "Date: %s\r\n" - "Message-ID: %s\r\n" - "Subject: %s\r\n" - "%s" - % ( - settings.EMAIL_FROM, - ','.join(committer.emails), - email.utils.formatdate(), - email.utils.make_msgid(), - settings.EMAIL_SUBJECT, - content)) - session.sendmail(settings.EMAIL_FROM, committer.emails, msg) + msg = email.mime.text.MIMEText(content, 'plain', + 'utf8') + msg["From"] = settings.EMAIL_FROM + msg["To"] = ','.join(committer.emails) + msg["Date"] = email.utils.formatdate() + msg["Message-ID"] = email.utils.make_msgid() + msg["Subject"] = settings.EMAIL_SUBJECT + + session.sendmail(settings.EMAIL_FROM, committer.emails, + msg.as_string()) print "%s,ATC,%s" % (code, committer.name) session.quit() time.sleep(settings.EMAIL_PAUSE) diff --git a/tools/invite2summit/settings.py.sample b/tools/invite2summit/settings.py.sample index 00107a9b7c..4d61662098 100644 --- a/tools/invite2summit/settings.py.sample +++ b/tools/invite2summit/settings.py.sample @@ -1,3 +1,4 @@ +# coding=utf8 # Settings for the passcode-sending application # # Copyright 2013 Thierry Carrez @@ -15,9 +16,9 @@ # License for the specific language governing permissions and limitations # under the License. -EMAIL_SUBJECT = "Your registration code for OpenStack Summit in Portland" +EMAIL_SUBJECT = u"Your registration code for OpenStack Summit in Portland" -EMAIL_TEMPLATE = """ +EMAIL_TEMPLATE = u""" Hello $name, As you may already know, we'll be having our next OpenStack Summit @@ -42,7 +43,7 @@ $signature """ EMAIL_FROM = "thierry@openstack.org" -EMAIL_SIGNATURE = "Thierry Carrez\nOpenStack Foundation" +EMAIL_SIGNATURE = u"Thierry Carrez\nOpenStack Foundation" EMAIL_HOST = "secure.emailsrvr.com" EMAIL_PORT = 465 EMAIL_USER = "thierry.carrez@openstack.org"