From a6226d63912be69da1312d3cb1f0f6ebcf5bff40 Mon Sep 17 00:00:00 2001 From: Mathieu Clabaut Date: Sat, 9 May 2015 17:59:18 +0200 Subject: [PATCH] Convert subject and body to unicode before sending mail Not doing this was raising an exception : Traceback (most recent call last): File /base/data/home/apps/e~sacred-bonus-88417/1.384178859090314065/gluon/restricted.py, line 227, in restricted exec ccode in environment File /base/data/home/apps/e~sacred-bonus-88417/1.384178859090314065/applications/foundit/controllers/default.py, line 127, in File /base/data/home/apps/e~sacred-bonus-88417/1.384178859090314065/gluon/globals.py, line 393, in self._caller = lambda f: f() File /base/data/home/apps/e~sacred-bonus-88417/1.384178859090314065/applications/foundit/controllers/default.py, line 34, in user return dict(form=auth()) File /base/data/home/apps/e~sacred-bonus-88417/1.384178859090314065/gluon/tools.py, line 1595, in __call__ return getattr(self, args[0])() File /base/data/home/apps/e~sacred-bonus-88417/1.384178859090314065/gluon/tools.py, line 3272, in request_reset_password if self.email_reset_password(user): File /base/data/home/apps/e~sacred-bonus-88417/1.384178859090314065/gluon/tools.py, line 3296, in email_reset_password message=self.messages.reset_password % d): File /base/data/home/apps/e~sacred-bonus-88417/1.384178859090314065/gluon/tools.py, line 798, in send subject=subject, body=text, **xcc) File /base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py, line 402, in send_mail message.send(make_sync_call=make_sync_call) File /base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py, line 1108, in send message = self.ToProto() File /base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py, line 1350, in ToProto message = super(EmailMessage, self).ToProto() File /base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/api/mail.py, line 1046, in ToProto message.set_subject(_to_str(self.subject)) File cpp_message.pyx, line 124, in cpp_message.SetScalarAccessors.Setter (third_party/apphosting/python/protobuf/proto1/cpp_message.cc:2229) TypeError: has type , but expected one of: str, unicode --- gluon/tools.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/gluon/tools.py b/gluon/tools.py index 6d6c42fe..71abdc76 100644 --- a/gluon/tools.py +++ b/gluon/tools.py @@ -767,8 +767,8 @@ class Mail(object): if self.settings.server == 'logging': logger.warn('email not sent\n%s\nFrom: %s\nTo: %s\nSubject: %s\n\n%s\n%s\n' % ('-' * 40, sender, - ', '.join(to), subject, - text or html, '-' * 40)) + ', '.join(to), subject, + text or html, '-' * 40)) elif self.settings.server == 'gae': xcc = dict() if cc: @@ -779,23 +779,23 @@ class Mail(object): xcc['reply_to'] = reply_to from google.appengine.api import mail attachments = attachments and [mail.Attachment( - a.my_filename, + a.my_filename, a.my_payload, contebt_id='' % k ) for k,a in enumerate(attachments) if not raw] if attachments: result = mail.send_mail( sender=sender, to=origTo, - subject=subject, body=text, html=html, + subject=unicode(subject), body=unicode(text), html=html, attachments=attachments, **xcc) elif html and (not raw): result = mail.send_mail( sender=sender, to=origTo, - subject=subject, body=text, html=html, **xcc) + subject=unicode(subject), body=unicode(text), html=html, **xcc) else: result = mail.send_mail( sender=sender, to=origTo, - subject=subject, body=text, **xcc) + subject=unicode(subject), body=unicode(text), **xcc) else: smtp_args = self.settings.server.split(':') kwargs = dict(timeout=self.settings.timeout) @@ -3714,7 +3714,7 @@ class Auth(object): return record.id else: id = membership.insert(group_id=group_id, user_id=user_id) - if role: + if role: self.user_groups[group_id] = role else: self.update_groups()