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
email package with unicode subject/body #48556
Comments
I never used the email package, so my issue is maybe not a bug. I'm def main():
# coding: utf8
ADDRESS = 'victor.stinner@haypocalc.com'
from email.mime.text import MIMEText
msg = MIMEText('accent éôŁ', 'plain', 'utf-8')
msg['Subject'] = 'sujet éôł'
msg['From'] = ADDRESS
msg['To'] = ADDRESS
text = msg.as_string()
print("--- FLATTEN ---")
print(text)
return
import smtplib
client=smtplib.SMTP('smtp.free.fr')
client.sendmail(ADDRESS, ADDRESS, text)
client.quit()
main() (remove the "return" to really send the email) The problem: I don't understand why it uses ASCII whereas I specified that I would My attached patch reused the message charset to encode the headers, |
The first email example (the one using a file in the library ... and the example doesn't work:
Traceback (most recent call last):
File "y.py", line 11, in <module>
msg = MIMEText(fp.read())
File "/home/haypo/prog/py3k/Lib/email/mime/text.py", line 30, in
__init__
self.set_payload(_text, _charset)
File "/home/haypo/prog/py3k/Lib/email/message.py", line 234, in
set_payload
self.set_charset(charset)
File "/home/haypo/prog/py3k/Lib/email/message.py", line 269, in
set_charset
cte(self)
File "/home/haypo/prog/py3k/Lib/email/encoders.py", line 60, in
encode_7or8bit
orig.encode('ascii')
AttributeError: 'bytes' object has no attribute 'encode' Solutions:
The new attached patch fixes the example and check type in |
"Please make this a release blocker and I will look at it this |
This example works though, and it also works in earlier Pythons. from email.header import Header
def main():
# coding: utf8
ADDRESS = 'victor.stinner@haypocalc.com'
from email.mime.text import MIMEText
msg = MIMEText('accent \xe9\xf4\u0142', 'plain', 'utf-8')
msg['Subject'] = Header('sujet \xe9\xf4\u0142'.encode('utf-8'),
'utf-8')
msg['From'] = ADDRESS
msg['To'] = ADDRESS
text = msg.as_string()
print("--- FLATTEN ---")
print(text)
return
main() |
I'm rejecting the patch because the old way of making this work still |
I checked the documentation and there is a section about "email:
Right. |
-----BEGIN PGP SIGNED MESSAGE----- On Nov 20, 2008, at 5:07 PM, STINNER Victor wrote:
Yes. This is a stupid API (tm). :)
-----BEGIN PGP SIGNATURE----- iQCVAwUBSSXpJHEjvBPtnXfVAQKfOAP9G2BSPKIPTVTeo5k3rovqGbYSCB23SK+P |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: