Hi Ondřej,

Ondřej Surý wrote:
> As this bug is preventing me from filling any bugs at all and it fails
> only after I press "Y", so the content of the lengthy unblock bug is
> gone...  and this puts my laptop in danger of my rage :).
> 
> Traceback (most recent call last):
>   File "/usr/bin/reportbug", line 2234, in <module>
>     main()
>   File "/usr/bin/reportbug", line 1107, in main
>     return iface.user_interface()
>   File "/usr/bin/reportbug", line 2225, in user_interface
>     self.options.envelopefrom)
>   File "/usr/lib/python3/dist-packages/reportbug/submit.py", line 209,
>   in send_report
>     (message, failed) = mime_attach(body, attachments, charset,
>     body_charset)
>   File "/usr/lib/python3/dist-packages/reportbug/submit.py", line 157,
>   in mime_attach
>     part = MIMEText(fp.read())
>   File "/usr/lib/python3.5/codecs.py", line 321, in decode
>     (result, consumed) = self._buffer_decode(data, self.errors, final)
> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe5 in position
> 296505: invalid continuation byte
> 
> and my locale is:
> 
> $ locale
> LANG=en_DK.UTF-8

Your Traceback is different from the others. This bug is not fixed yet.

Did you try to attach a text(plain/html/etc) file in a different
encoding than UTF-8? As a workaround, you could gzip that file.

Attached a patch that should fix the problem.
>From 0566a9cec6c9bd561db0128a58c84b9db0a5d1c4 Mon Sep 17 00:00:00 2001
From: Nis Martensen <nis.marten...@web.de>
Date: Tue, 14 Feb 2017 22:21:29 +0100
Subject: [PATCH] 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),
-- 
2.1.4

Reply via email to