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


Groups > comp.lang.python > #54838

Re: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2

Newsgroups comp.lang.python
Date 2013-09-26 09:35 -0700
References <14063249-6159-48ff-bfe2-8e8d6e3cd7a4@googlegroups.com>
Message-ID <a675d865-8961-49a5-b70f-0d795b353aa2@googlegroups.com> (permalink)
Subject Re: Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2
From Nils Bunger <nilsbunger@gmail.com>

Show all headers | View raw


Hi all, 

I was able to workaround this problem by encoding a unique 'marker' in the binary part, then replacing the marker with the actual binary content after generating the MIME message. 

See my answer on Stack Overflow http://stackoverflow.com/a/19033750/526098 for the code.

Thanks, your suggestions helped me think of this.

Nils

On Wednesday, September 25, 2013 9:38:17 AM UTC-7, Nils Bunger wrote:
> 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 | NextPrevious 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