From bdf670277bc9a73d5010438b2b650cf5f7387dad Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Thu, 24 Jan 2013 00:35:04 +0400 Subject: [PATCH] Add 8bit Content-Transfer-Encoding support. Signed-off-by: Dmitry Bogatov --- rss2email/config.py | 3 +++ rss2email/email.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/rss2email/config.py b/rss2email/config.py index 0daa979..4dfce42 100644 --- a/rss2email/config.py +++ b/rss2email/config.py @@ -52,6 +52,9 @@ CONFIG['DEFAULT'] = _collections.OrderedDict(( ### Addressing # The email address messages are from by default ('from', 'user@rss2email.invalid'), + # Transfer-Encoding. For local mailing it is safe and + # convient to use 8bit. + ('use_8bit', str(True)), # True: Only use the 'from' address. # False: Use the email address specified by the feed, when possible. ('force-from', str(False)), diff --git a/rss2email/email.py b/rss2email/email.py index 45b105f..005b68a 100644 --- a/rss2email/email.py +++ b/rss2email/email.py @@ -112,6 +112,9 @@ def get_message(sender, recipient, subject, body, content_type, message['From'] = _formataddr((sender_name, sender_addr)) message['To'] = _formataddr((recipient_name, recipient_addr)) message['Subject'] = _Header(subject, subject_encoding) + if config.getboolean(section, 'use_8bit'): + message['Content-Transfer-Encoding'] = '8bit' + message.set_payload(body) if extra_headers: for key,value in extra_headers.items(): encoding = guess_encoding(value, encodings) @@ -160,7 +163,8 @@ def sendmail_send(sender, recipient, message, config=None, section='DEFAULT'): ['/usr/sbin/sendmail', recipient], stdin=_subprocess.PIPE, stdout=_subprocess.PIPE, stderr=_subprocess.PIPE) - stdout,stderr = p.communicate(message.as_string().encode('ascii')) + stdout,stderr = p.communicate(message.as_string() + .encode(str(message.get_charset()))) status = p.wait() if status: raise _error.SendmailError( -- 2.26.2