Newline interpretation issue with MIMEApplication with binary data, Python 3.3.2

nilsbunger at gmail.com nilsbunger at gmail.com
Wed Sep 25 12:38:17 EDT 2013


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