[Reportbug-commits] [reportbug] 03/05: Handle text attachments in different encodings

Sandro Tosi morph at moszumanska.debian.org
Wed Apr 19 01:17:37 UTC 2017


This is an automated email from the git hooks/post-receive script.

morph pushed a commit to branch master
in repository reportbug.

commit 16705d629242fadbbf78311e9a4cc5afcade1409
Author: Nis Martensen <nis.martensen at web.de>
Date:   Tue Feb 14 22:21:29 2017 +0100

    Handle text attachments in different encodings
---
 reportbug/submit.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/reportbug/submit.py b/reportbug/submit.py
index 5cc1231..b3025b3 100644
--- a/reportbug/submit.py
+++ b/reportbug/submit.py
@@ -153,9 +153,15 @@ def mime_attach(body, attachments, charset, body_charset=None):
 
         maintype, subtype = ctype.split('/', 1)
         if maintype == 'text':
-            fp = open(attachment, 'rU')
-            part = MIMEText(fp.read())
-            fp.close()
+            try:
+                with open(attachment, 'rU') as fp:
+                    part = MIMEText(fp.read())
+            except UnicodeDecodeError:
+                fp = open(attachment, 'rb')
+                part = MIMEBase(maintype, subtype)
+                part.set_payload(fp.read())
+                fp.close()
+                email.encoders.encode_base64(part)
         elif maintype == 'message':
             fp = open(attachment, 'rb')
             part = MIMEMessage(email.message_from_file(fp),

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reportbug/reportbug.git



More information about the Reportbug-commits mailing list