I need to generate a multipart/mime message to send as a response to a HTTP request but am hitting either a bug or limitation in the Python email.* package.
The problem is that using Python 2.6, the message.as_string()
call below generates a string with \n rather that CRLF as the line endings:
message = MIMEMultipart()
for image in images:
f = image.open('rb')
img = MIMEImage(f.read(), _encoder=encode_7or8bit)
message.attach(img)
message.as_string()
There doesn't seem to be any way to persuade it to use the (MIME standard) CRLF. The Generator class that seems it should be able to do this, doesn't.
What have other people done to get round this?