[issue4306] email package with unicode subject/body

2008-11-20 Thread Barry A. Warsaw

Barry A. Warsaw [EMAIL PROTECTED] added the comment:

I'm rejecting the patch because the old way of making this work still
works in Python 3.0.  Any larger changes to the API need to be made in
the context of redesigning the email package to be byte/str aware.

--
resolution:  - rejected
status: open - closed

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4306
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4306] email package with unicode subject/body

2008-11-20 Thread STINNER Victor

STINNER Victor [EMAIL PROTECTED] added the comment:

 I'm rejecting the patch because the old way of making 
 this work still works in Python 3.0.

I checked the documentation and there is a section about email: 
Internationalized headers. I didn't read this section. I just 
expected that Python uses the right encoding beacuse it was already 
specified in the MIMEText() constructor...

 Any larger changes to the API need to be made in
 the context of redesigning the email package to be byte/str aware.

Right.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4306
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4306] email package with unicode subject/body

2008-11-20 Thread Barry A. Warsaw

Barry A. Warsaw [EMAIL PROTECTED] added the comment:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Nov 20, 2008, at 5:07 PM, STINNER Victor wrote:

 STINNER Victor [EMAIL PROTECTED] added the comment:

 I'm rejecting the patch because the old way of making
 this work still works in Python 3.0.

 I checked the documentation and there is a section about email:
 Internationalized headers. I didn't read this section. I just
 expected that Python uses the right encoding beacuse it was already
 specified in the MIMEText() constructor...

Yes.  This is a stupid API (tm). :)

- -Barry

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (Darwin)

iQCVAwUBSSXpJHEjvBPtnXfVAQKfOAP9G2BSPKIPTVTeo5k3rovqGbYSCB23SK+P
+YHInZY2NTikFUgJec4EvWvvuTkW77nb5kxVTb+MlQJMAN//AOy8xvHsFUae4F8Y
P9DsDMb3MhKokr/Y1gZyxlpHhXiK5r6aEh9+cWrujXbf9gwtYWmeiKl6MoZkOWYA
3H9gASFvuUI=
=mapP
-END PGP SIGNATURE-

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4306
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4306] email package with unicode subject/body

2008-11-12 Thread STINNER Victor

STINNER Victor [EMAIL PROTECTED] added the comment:

Please make this a release blocker and I will look at it this 
weekend.   -Barry

--
priority:  - release blocker

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4306
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4306] email package with unicode subject/body

2008-11-12 Thread STINNER Victor

STINNER Victor [EMAIL PROTECTED] added the comment:

The first email example (the one using a file in the library 
documentation) opens a text in binary mode and use the ASCII charset. 
It's quite strange because I expect an text to use only characters, 
something like:
   charset = 'ASCII'
   # Create a text/plain message
   with open(textfile, 'r', encoding=charset) as fp:
  msg = MIMEText(fp.read(), 'plain', charset)

... 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:
 - Message.set_payload() have to block type different than str
   = or would it be possible to use bytes as payload???
 - Fix the example to use characters

The new attached patch fixes the example and check type in 
Message.set_payload().

Added file: http://bugs.python.org/file11993/email_example.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4306
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4306] email package with unicode subject/body

2008-11-12 Thread Benjamin Peterson

Changes by Benjamin Peterson [EMAIL PROTECTED]:


--
assignee:  - barry
nosy: +barry

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4306
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4306] email package with unicode subject/body

2008-11-12 Thread STINNER Victor

New submission from STINNER Victor [EMAIL PROTECTED]:

I never used the email package, so my issue is maybe not a bug. I'm 
trying to send an email with diacritics in the subject and the body. 
I'm french so it's natural to use characters not in the ASCII range. I 
wrote this small program:

def main():
# coding: utf8
ADDRESS = '[EMAIL PROTECTED]'
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:
  (...)
  File /home/haypo/prog/py3k/Lib/email/generator.py, line 141, in 
_write_headers
header_name=h, continuation_ws='\t')
  File /home/haypo/prog/py3k/Lib/email/header.py, line 189, in 
__init__
self.append(s, charset, errors)
  File /home/haypo/prog/py3k/Lib/email/header.py, line 262, in 
append
input_bytes = s.encode(input_charset, errors)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 
6-8: ordinal not in range(128)

I don't understand why it uses ASCII whereas I specified that I would 
like to use the UTF-8 charset.

My attached patch reused the message charset to encode the headers, 
but use ASCII if the header can be encoded as ASCII. The patch 
included an unit test.

--
components: Library (Lib)
files: email_mime_unicode.patch
keywords: patch
messages: 75784
nosy: haypo
severity: normal
status: open
title: email package with unicode subject/body
versions: Python 3.0
Added file: http://bugs.python.org/file11992/email_mime_unicode.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue4306
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com