Add 8bit Content-Transfer-Encoding support.
authorDmitry Bogatov <KAction@gnu.org>
Wed, 23 Jan 2013 20:35:04 +0000 (00:35 +0400)
committerW. Trevor King <wking@tremily.us>
Wed, 23 Jan 2013 22:19:15 +0000 (17:19 -0500)
Signed-off-by: Dmitry Bogatov <KAction@gnu.org>
rss2email/config.py
rss2email/email.py

index 0daa9799bb37417f0d7945b6ae43e09c50bd6a5e..4dfce42d53c76cf3f05d49c3f787597cbf1b05df 100644 (file)
@@ -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)),
index 45b105fad6f0fc298960a1169f6eca550fec2d22..005b68a0fc43a9ab233d91b6993fafd05f3941ec 100644 (file)
@@ -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(