[Reportbug-maint] Bug#849765: Bug#849765: reportbug: produces invalid mails when there are long lines

2017-09-07 Thread Nis Martensen
control: tags -1 patch

On 30 Dec 2016 Adam Borowski wrote:
> RFC 821:
> # The maximum total length of a text line including the  is 1000
> # characters (but not counting the leading dot duplicated for transparency).
> 
> Some MTAs are said to have a bit shorter limits, such as 990 bytes.

Here is a patch that fixes the problem in reportbug.
>From d32fb670bcdf622b9e2b3d45e88abd8cf0e2d711 Mon Sep 17 00:00:00 2001
From: Nis Martensen 
Date: Thu, 7 Sep 2017 18:17:00 +0200
Subject: [PATCH 2/2] 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 e6bd50b..4940538 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 = ''
@@ -154,7 +169,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)
@@ -216,7 +231,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
-- 
2.11.0

___
Reportbug-maint mailing list
Reportbug-maint@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/reportbug-maint

[Reportbug-maint] Bug#849765: Bug#849765: reportbug: produces invalid mails when there are long lines

2016-12-30 Thread Adam Borowski
On Fri, Dec 30, 2016 at 01:48:59PM -0500, Sandro Tosi wrote:
> On Fri, Dec 30, 2016 at 1:41 PM, Adam Borowski  wrote:
> > If the bug report contains an overlong line -- for example, mutt's bug
> > script includes its configure options, 1017 characters long -- reportbug
> > will send that unescaped.
> 
> would you be able to retrieve the saved version of the report (there
> is an output line saying where it is stored, /var/tmp/ IIRC) and
> attach it here? at least i have the exact text that causes the issue

Sure, here you go.  Nothing in /var/tmp but I have an editor backup file --
without my typed part but should be good enough.

> (i'm also not sure if there are limits to the line length in an email,
> but i'll look it up in the SMTP docs)

RFC 821:
# The maximum total length of a text line including the  is 1000
# characters (but not counting the leading dot duplicated for transparency).

Some MTAs are said to have a bit shorter limits, such as 990 bytes.

RFC 2822:
#2.1.1. Line Length Limits
#
#   There are two limits that this standard places on the number of
#   characters in a line. Each line of characters MUST be no more than
#   998 characters, and SHOULD be no more than 78 characters, excluding
#   the CRLF.
#
#   The 998 character limit is due to limitations in many implementations
#   which send, receive, or store Internet Message Format messages that
#   simply cannot handle more than 998 characters on a line. Receiving
#   implementations would do well to handle an arbitrarily large number
#   of characters in a line for robustness sake. However, there are so
#   many implementations which (in compliance with the transport
#   requirements of [RFC2821]) do not accept messages containing more
#   than 1000 character including the CR and LF per line, it is important
#   for implementations not to create such messages.

(1000 including \r\n = 998 excluding them)


Meow!
-- 
Autotools hint: to do a zx-spectrum build on a pdp11 host, type:
  ./configure --host=zx-spectrum --build=pdp11
Subject: mutt: complains about GPGME
Package: mutt
Version: 1.7.1-5
Severity: normal



-- Package-specific info:
NeoMutt 20161126 (1.7.1)
Copyright (C) 1996-2016 Michael R. Elkins and others.
Mutt comes with ABSOLUTELY NO WARRANTY; for details type `mutt -vv'.
Mutt is free software, and you are welcome to redistribute it
under certain conditions; type `mutt -vv' for details.

System: Linux 4.9.0+ (x86_64)
libidn: 1.33 (compiled with 1.33)
hcache backends: tokyocabinet

Compiler:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 6.2.1-5' 
--with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs 
--enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr 
--program-suffix=-6 --program-prefix=x86_64-linux-gnu- --enable-shared 
--enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext 
--enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ 
--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes 
--with-default-libstdcxx-abi=new --enable-gnu-unique-object 
--disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie 
--with-system-zlib --disable-browser-plugin --enable-java-awt=gtk 
--enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre 
--enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64 
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64 
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar 
--enable-objc-gc=auto --enable-multiarch --with-arch-32=i686 --with-abi=m64 
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic 
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu 
--target=x86_64-linux-gnu
Thread model: posix
gcc version 6.2.1 20161124 (Debian 6.2.1-5) 

Configure options: '--build=x86_64-linux-gnu' '--prefix=/usr' 
'--includedir=\${prefix}/include' '--mandir=\${prefix}/share/man' 
'--infodir=\${prefix}/share/info' '--sysconfdir=/etc' '--localstatedir=/var' 
'--disable-silent-rules' '--libdir=\${prefix}/lib/x86_64-linux-gnu' 
'--libexecdir=\${prefix}/lib/x86_64-linux-gnu' '--disable-maintainer-mode' 
'--disable-dependency-tracking' '--with-mailpath=/var/mail' 
'--enable-compressed' '--enable-debug' '--enable-fcntl' '--enable-hcache' 
'--enable-gpgme' '--enable-imap' '--enable-smtp' '--enable-pop' 
'--enable-sidebar' '--enable-nntp' '--enable-notmuch' '--disable-fmemopen' 
'--with-curses' '--with-gnutls' '--with-gss' '--with-idn' '--with-mixmaster' 
'--with-sasl' '--without-gdbm' '--without-bdb' '--without-qdbm' 
'--with-tokyocabinet' 'build_alias=x86_64-linux-gnu' 'CFLAGS=-g -O2 
-fdebug-prefix-map=/build/mutt-Uun1o_/mutt-1.7.1=. -fstack-protector-strong 
-Wformat -Werror=format-security' 'LDFLAGS=-Wl,-z,relro -Wl,-z,now' 
'CPPFLAGS=-Wdate-time 

[Reportbug-maint] Bug#849765: Bug#849765: reportbug: produces invalid mails when there are long lines

2016-12-30 Thread Sandro Tosi
On Fri, Dec 30, 2016 at 1:41 PM, Adam Borowski  wrote:
> If the bug report contains an overlong line -- for example, mutt's bug
> script includes its configure options, 1017 characters long -- reportbug
> will send that unescaped.

would you be able to retrieve the saved version of the report (there
is an output line saying where it is stored, /var/tmp/ IIRC) and
attach it here? at least i have the exact text that causes the issue
(i'm also not sure if there are limits to the line length in an email,
but i'll look it up in the SMTP docs)

-- 
Sandro "morph" Tosi
My website: http://sandrotosi.me/
Me at Debian: http://wiki.debian.org/SandroTosi
G+: https://plus.google.com/u/0/+SandroTosi

___
Reportbug-maint mailing list
Reportbug-maint@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/reportbug-maint