You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the message class assigns the subject as-is to the MailBase and then to the email.message message, not performing any character escaping, in contrast to the message body. If the subject contains special characters as ü the message cannot be converted to a string and will raise a UnicodeEncodeError.
Tested under Python 3.2, using pyramid_mailer v0.14 and the DebugMailer.
Is there any reason that there is no character escaping of the subject?
A possible solution would be to use the email.header Header class like this:
This seems to work fine in the current version -- the subject is encoded as utf8 properly like so:
Subject: =?utf-8?b?xxxxxxxxxxxxxxxxxxxxxxx?=
It looks to me like we just need some tests to assert several test cases pass.
I started writing some, and have run into this issue with Python2: passing a unicode instance as the subject or body appears to work as intended. However, passing in a string instance with utf-8 data in it will generate an exception.
Perhaps a flag/kwarg to the Message constructor can change the behavior of how best_charset works? IMHO, I think if a body contains utf-8 data it should be handled as utf-8 and not do the us-ascii encoding or raise exceptions.
Currently the message class assigns the subject as-is to the
MailBase
and then to theemail.message message
, not performing any character escaping, in contrast to the message body. If the subject contains special characters as ü the message cannot be converted to a string and will raise aUnicodeEncodeError
.Tested under Python 3.2, using pyramid_mailer v0.14 and the DebugMailer.
Is there any reason that there is no character escaping of the subject?
A possible solution would be to use the email.header Header class like this:
Or using a more appropriate encoding, determined by
best_charset
.Unfortunately one cannot pass a Header instance to the pyramid mailer
Message
class as subject, as thevalidate
function ofMessage
will fail.By the way, the problem extends to To and From headers as well.
The text was updated successfully, but these errors were encountered: