Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIMEText instead of MIMEBase should be better for XML: why doesn't the encoding work? #1

Open
bartkl opened this issue Nov 1, 2018 · 0 comments
Labels
improvement Code needs improvement

Comments

@bartkl
Copy link
Owner

bartkl commented Nov 1, 2018

Ideally:

message_part = MIMEText(message, 'xml', 'utf8')

This should imply charset: UTF8 and the appropriate value for Content-Encoding-Type:

Unless the _charset parameter is explicitly set to None, the MIMEText object created will have both a Content-Type header with a charset parameter, and a Content-Transfer-Encoding header.

(https://docs.python.org/2.7/library/email.mime.html)

For some reason though, even the most trivial of strings get encoded in base64, and the charset parameter is not set.

So, for now I'm doing it manually:

message_part = MIMEBase('text', 'xml')
message_part.set_charset('utf8')
message.replace_header('Content-Transfer-Encoding', '8bit')
message_part.set_payload(message)

No big deal, but I really don't understand why the first code example doesn't work.

@bartkl bartkl changed the title MIMEText instead of MIMEBase should be better for XML: why doesn't the encoding work? MIMEText instead of MIMEBase should be better for XML: why doesn't the encoding work? Nov 1, 2018
@bartkl bartkl added the improvement Code needs improvement label Nov 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Code needs improvement
Projects
None yet
Development

No branches or pull requests

1 participant