UTF-8 issues #41

Merged
merged 1 commit into from Jul 3, 2012

Conversation

Projects
None yet
6 participants
Contributor

puttu commented Jun 26, 2012

Just a small fix for some issues with unicode content.

@pcraciunoiu pcraciunoiu commented on the diff Jun 27, 2012

django_ses/__init__.py
@@ -153,7 +153,7 @@ def send_messages(self, email_messages):
response = self.connection.send_raw_email(
source=source or message.from_email,
destinations=message.recipients(),
- raw_message=dkim_sign(message.message().as_string())
+ raw_message=unicode(dkim_sign(message.message().as_string()), 'utf-8')
@pcraciunoiu

pcraciunoiu Jun 27, 2012

Contributor

If message.message() is already a unicode string, I think this breaks. I don't have my setup so I'm wondering - did you check?

@puttu

puttu Jun 27, 2012

Contributor

When I tried to send a message with unicode characters before the change, I was getting this:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 280: ordinal not in range(128)

My first idea was to apply unicode(msg_body, 'utf-8') before feeding the body to send_mail, but I got:
TypeError: decoding Unicode is not supported
(the message body was already a django.utils.safestring.SafeUnicode string).
This commit fixed it for me (Django 1.4).

By the way, I just found a similar commit elsewhere, this one using smart_unicode:
raw = u'%s' % smart_unicode(message.message().as_string())
michalkwiatkowski/django-database-email-backend@4182926

@simonluijk

simonluijk Jul 3, 2012

message.message().as_string() always returns type 'str'. dkim.sign() raises a UnicodeError if you convert message into unicode before parsing it to dkim.sign().

@pcraciunoiu

pcraciunoiu Jul 3, 2012

Contributor

Seems fine then. I don't suppose we can have a test here? I'll go ahead and merge it in, but if anyone feels testy please ;)

@pcraciunoiu pcraciunoiu added a commit that referenced this pull request Jul 3, 2012

@pcraciunoiu pcraciunoiu Merge pull request #41 from puttu/master
UTF-8 issues for raw_message with dkim_sign
f0f43e7

@pcraciunoiu pcraciunoiu merged commit f0f43e7 into django-ses:master Jul 3, 2012

aduston commented on 0ea65f3 Jul 8, 2012

I believe this change broke utf-8 message sending in django-ses. Sorry, I don't have time to make a failing unit test now :(.

Example of stack trace from broken code: http://pastie.org/4222024

Contributor

puttu replied Jul 14, 2012

I tried to replicate that with boto 2.5.2, but couldn't. Which version are you using?

Using boto 2.4.1. I might have time to write a test against this today, in which case I'll either offer more info or issue a pull request.

djw replied Aug 28, 2012

I suspect the code above was added to work around a bug introduced in boto (boto/boto@bb236ec), which is present in all 2.5.x releases. (message.message().as_string() is already utf-8 encoded)

I fixed this a couple of months ago (boto/boto@5c1faab), but there hasn't been a release since then.

hey guys, I'm having a weird issue involving unicode. I'm running boto 2.6.0 and the latest version of django-ses. I've been trying to debug it for hours but can't figure out where is the problem. I've already disabled DKIM and that did not solve it. Here is the stacktrace: http://pastebin.com/wxSqL0ii

It looks like message.message() somehow is unicode. Any help is appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment