email: Encode the body when we might use 8bit encoding
authorW. Trevor King <wking@tremily.us>
Thu, 24 Jan 2013 05:30:04 +0000 (00:30 -0500)
committerW. Trevor King <wking@tremily.us>
Thu, 24 Jan 2013 05:32:36 +0000 (00:32 -0500)
R. David Murray writes [1]:
> In 2.x that will work, and will give you the 8bit CTE at need, as
> long as you pass encoded text to MIMEText (as opposed to
> unicode...which it doesn't really handle correctly if I recall
> right).

See also, [2].

[1]: http://bugs.python.org/issue12552
     email.MIMEText overide BASE64 for utf8 charset
[2]: http://bugs.python.org/issue12553
     Add support for using a default CTE of '8bit' to MIMEText

Signed-off-by: W. Trevor King <wking@tremily.us>
rss2email/email.py

index 8bf3eb61950d152ad4acd22b17ad767d93db7d9e..626acda7e7fa1553653e7c111812a13fec8ef9d1 100644 (file)
@@ -122,7 +122,7 @@ def get_message(sender, recipient, subject, body, content_type,
         del message['Content-Transfer-Encoding']
         charset = _Charset(body_encoding)
         charset.body_encoding = _email_encoders.encode_7or8bit
-        message.set_payload(body, charset=charset)
+        message.set_payload(body.encode(body_encoding), charset=charset)
     if extra_headers:
         for key,value in extra_headers.items():
             encoding = guess_encoding(value, encodings)