From 05dd3da1ed21f554e0a6dbc874cee3b377f92ae0 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 23 Jan 2013 23:39:44 -0500 Subject: [PATCH] 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 --- rss2email/email.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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) -- 2.26.2