[Reportbug-commits] [reportbug] 21/38: Use quoted-printable encoding for too long lines

Sandro Tosi morph at moszumanska.debian.org
Fri Dec 29 04:33:45 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 7974a0dcb663b7194652a7a3c8004c68b3a8a32a
Author: Nis Martensen <nis.martensen at web.de>
Date:   Thu Sep 7 18:17:00 2017 +0200

    Use quoted-printable encoding for too long lines
---
 reportbug/submit.py | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/reportbug/submit.py b/reportbug/submit.py
index 4135280..1eb1b71 100644
--- a/reportbug/submit.py
+++ b/reportbug/submit.py
@@ -108,12 +108,27 @@ def sign_message(body, fromaddr, package='x', pgp_addr=None, sign='gpg', draftpa
         body = None
     return body
 
+def _MIMEText_wrapper(text):
+    msg = MIMEText(text)
+    # Too long lines need to be encoded (see RFC2822), but MIMEText does
+    # not yet handle this for us.
+    # Since utf-8 will already be base64-encoded at this point, we only
+    # need to deal with the us-ascii case.
+    if msg.get_content_charset() == 'us-ascii' and \
+            max(len(l) for l in text.splitlines()) > 980:
+        email.encoders.encode_quopri(msg)
+        # due to a bug in the email library, the result now has two CTE
+        # headers, only one of which is correct. Delete both and set the
+        # correct value.
+        del msg['Content-Transfer-Encoding']
+        msg['Content-Transfer-Encoding'] = 'quoted-printable'
+    return msg
 
 def mime_attach(body, attachments, charset, body_charset=None):
     mimetypes.init()
 
     message = MIMEMultipart('mixed')
-    bodypart = MIMEText(body)
+    bodypart = _MIMEText_wrapper(body)
     bodypart.add_header('Content-Disposition', 'inline')
     message.preamble = 'This is a multi-part MIME message sent by reportbug.\n\n'
     message.epilogue = ''
@@ -153,7 +168,7 @@ def mime_attach(body, attachments, charset, body_charset=None):
         if maintype == 'text':
             try:
                 with open(attachment, 'rU') as fp:
-                    part = MIMEText(fp.read())
+                    part = _MIMEText_wrapper(fp.read())
             except UnicodeDecodeError:
                 fp = open(attachment, 'rb')
                 part = MIMEBase(maintype, subtype)
@@ -215,7 +230,7 @@ def send_report(body, attachments, mua, fromaddr, sendto, ccaddr, bccaddr,
             ewrite("Error: Message creation failed, not sending\n")
             mua = mta = smtphost = None
     else:
-        message = MIMEText(body)
+        message = _MIMEText_wrapper(body)
 
     # Standard headers
     message['From'] = fromaddr

-- 
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