From: W. Trevor King Date: Thu, 24 Jan 2013 04:39:44 +0000 (-0500) Subject: email: Use Charsets to set the Content-Transfer-Encoding X-Git-Tag: v3.0~7 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=05dd3da1ed21f554e0a6dbc874cee3b377f92ae0;p=rss2email.git email: Use Charsets to set the Content-Transfer-Encoding This ensures that payload encoding/decoding happens appropriately, and allows 7-bit-clean data to be sent with a 7bit CTE, even when the use-8bit setting is on. Signed-off-by: W. Trevor King --- diff --git a/rss2email/email.py b/rss2email/email.py index 3b1e217..90d245d 100644 --- a/rss2email/email.py +++ b/rss2email/email.py @@ -19,6 +19,8 @@ """Email message generation and dispatching """ +from email.charset import Charset as _Charset +import email.encoders as _email_encoders from email.header import Header as _Header from email.mime.text import MIMEText as _MIMEText from email.utils import formataddr as _formataddr @@ -116,8 +118,9 @@ def get_message(sender, recipient, subject, body, content_type, message['Subject'] = _Header(subject, subject_encoding) if config.getboolean(section, 'use-8bit'): del message['Content-Transfer-Encoding'] - message['Content-Transfer-Encoding'] = '8bit' - message.set_payload(body) + charset = _Charset(body_encoding) + charset.body_encoding = _email_encoders.encode_7or8bit + message.set_payload(body, charset=charset) if extra_headers: for key,value in extra_headers.items(): encoding = guess_encoding(value, encodings)