Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #54752

Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2

X-Received by 10.224.93.19 with SMTP id t19mr121192qam.3.1380127097952; Wed, 25 Sep 2013 09:38:17 -0700 (PDT)
X-Received by 10.182.29.196 with SMTP id m4mr431165obh.2.1380127097910; Wed, 25 Sep 2013 09:38:17 -0700 (PDT)
Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!d5no1817570qap.0!news-out.google.com!9ni193qaf.0!nntp.google.com!d5no1901194qap.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Wed, 25 Sep 2013 09:38:17 -0700 (PDT)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=216.21.175.87; posting-account=Ty2SawoAAADMF7SbfwAUaRSpfReyFVyj
NNTP-Posting-Host 216.21.175.87
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <14063249-6159-48ff-bfe2-8e8d6e3cd7a4@googlegroups.com> (permalink)
Subject Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2
From nilsbunger@gmail.com
Injection-Date Wed, 25 Sep 2013 16:38:17 +0000
Content-Type text/plain; charset=ISO-8859-1
X-Received-Bytes 1695
Xref csiph.com comp.lang.python:54752

Show key headers only | View raw


Hi, 

I'm having trouble encoding a MIME message with a binary file.  Newline characters are being interpreted even though the content is supposed to be binary. This is using Python 3.3.2

Small test case:

app = MIMEApplication(b'Q\x0dQ', _encoder=encode_noop)
b = io.BytesIO()
g = BytesGenerator(b)
g.flatten(app)
for i in b.getvalue()[-3:]:
    print ("%02x " % i, end="")
print ()

This prints 51 0a 51,  meaning the 0x0d character got reinterpreted as a newline. 

I've tried setting an email policy of HTTP policy, but that goes even further, converting \r to \r\n

This is for HTTP transport, so binary encoding is normal.

Any thoughts how I can do this properly?

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2 nilsbunger@gmail.com - 2013-09-25 09:38 -0700
  Re: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2 Chris Angelico <rosuav@gmail.com> - 2013-09-26 14:11 +1000
    Re: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2 Nils Bunger <nilsbunger@gmail.com> - 2013-09-25 21:23 -0700
      Re: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2 Chris Angelico <rosuav@gmail.com> - 2013-09-26 14:32 +1000
        Re: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2 Neil Cerutti <neilc@norwich.edu> - 2013-09-26 13:41 +0000
          Re: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2 Nils Bunger <nilsbunger@gmail.com> - 2013-09-26 08:56 -0700
            Re: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2 Piet van Oostrum <piet@vanoostrum.org> - 2013-09-26 14:44 -0400
  Re: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2 Nils Bunger <nilsbunger@gmail.com> - 2013-09-26 09:35 -0700

csiph-web