Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2
Nils Bunger
nilsbunger at gmail.com
Thu Sep 26 12:35:25 EDT 2013
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?
More information about the Python-list
mailing list