Re: Problems with email.Generator.Generator

2006-09-12 Thread Max M
Chris Withers wrote: Chris Withers wrote: print msg.as_string() MIME-Version: 1.0 Content-Type: text/plain; charset; charset=utf-8 ^^^ Actually, even this isn't correct as you can see above... charset = Charset('utf-8') msg = MIMEText('','plain',None)

Re: Problems with email.Generator.Generator

2006-09-12 Thread Peter Otten
Chris Withers wrote: Okay, more out of desperation than anything else, lets try this: from email.Charset import Charset,QP from email.MIMEText import MIMEText from StringIO import StringIO from email import Generator,Message Generator.StringIO = Message.StringIO = StringIO charset =

Re: Problems with email.Generator.Generator

2006-09-12 Thread Chris Withers
Max M wrote: From the docs: The payload is either a string in the case of simple message objects or a list of Message objects for MIME container documents (e.g. multipart/* and message/rfc822) Where'd you find that? I must have missed it in my digging :-S Message objects are always

Re: Problems with email.Generator.Generator

2006-09-12 Thread Max M
Chris Withers wrote: Max M wrote: From the docs: The payload is either a string in the case of simple message objects or a list of Message objects for MIME container documents (e.g. multipart/* and message/rfc822) Where'd you find that? I must have missed it in my digging :-S End

Problems with email.Generator.Generator

2006-09-11 Thread Chris Withers
Hi All, The following piece of code is giving me issues: from email.Charset import Charset,QP from email.MIMEText import MIMEText charset = Charset('utf-8') charset.body_encoding = QP msg = MIMEText( u'Some text with chars that need encoding: \xa3', 'plain', )

Re: Problems with email.Generator.Generator

2006-09-11 Thread Manlio Perillo
Chris Withers ha scritto: Hi All, The following piece of code is giving me issues: from email.Charset import Charset,QP from email.MIMEText import MIMEText charset = Charset('utf-8') charset.body_encoding = QP msg = MIMEText( u'Some text with chars that need encoding: \xa3',

Re: Problems with email.Generator.Generator

2006-09-11 Thread Chris Withers
Manlio Perillo wrote: Try with: msg = MIMEText( u'Some text with chars that need encoding: \xa3', _charset='utf-8', ) and you will obtain the error: Traceback (most recent call last): File pyshell#4, line 3, in -toplevel- _charset='utf-8', File

Re: Problems with email.Generator.Generator

2006-09-11 Thread Peter Otten
Chris Withers wrote: The following piece of code is giving me issues: from email.Charset import Charset,QP from email.MIMEText import MIMEText charset = Charset('utf-8') charset.body_encoding = QP msg = MIMEText( u'Some text with chars that need encoding: \xa3', 'plain',

Re: Problems with email.Generator.Generator

2006-09-11 Thread Chris Withers
Peter Otten wrote: http://sourceforge.net/tracker/?func=detailaid=1409455group_id=5470atid=105470 Now, is this change to Generator.py in error or am I doing something wrong? I'm not familiar enough with the email package to answer that. I'm hoping someone around here is ;-) If the latter,

Re: Problems with email.Generator.Generator

2006-09-11 Thread Steve Holden
Chris Withers wrote: Peter Otten wrote: http://sourceforge.net/tracker/?func=detailaid=1409455group_id=5470atid=105470 Now, is this change to Generator.py in error or am I doing something wrong? I'm not familiar enough with the email package to answer that. I'm hoping someone around here

Re: Problems with email.Generator.Generator

2006-09-11 Thread Gerard Flanagan
Chris Withers wrote: Now, I want to know what I'm supposed to do when I have unicode source and want it to end up as either a text/plain or text/html mime part. Is there a how-to for this anywhere? The email package's docs are short on examples involving charsets, unicode and the like :-(

Re: Problems with email.Generator.Generator

2006-09-11 Thread Manlio Perillo
Chris Withers ha scritto: [...] OK, but I fail to see how replacing one unicode error with another is any help... :-S The problem is simple: email package does not support well Unicode strings. For now I'm using this: charset = utf-8 # the charset to be used for email class

Re: Problems with email.Generator.Generator

2006-09-11 Thread Chris Withers
Steve Holden wrote: Is there a how-to for this anywhere? The email package's docs are short on examples involving charsets, unicode and the like :-( Well, it would seem like the easiest approach is to monkey-patch the use of cStringIO to StringIO as recommended and see if that fixes your

Re: Problems with email.Generator.Generator

2006-09-11 Thread Chris Withers
Manlio Perillo wrote: The problem is simple: email package does not support well Unicode strings. Really? All the character set support seems to indicate a fair bit of thought went into this aspect, although it does appear that no-one bothered to document it :-( Chris -- Simplistix -

Re: Problems with email.Generator.Generator

2006-09-11 Thread Steve Holden
Chris Withers wrote: Steve Holden wrote: Is there a how-to for this anywhere? The email package's docs are short on examples involving charsets, unicode and the like :-( Well, it would seem like the easiest approach is to monkey-patch the use of cStringIO to StringIO as recommended and

Re: Problems with email.Generator.Generator

2006-09-11 Thread Peter Otten
Chris Withers wrote: At worst, and most likely based on my past experience of (c)StringIO being used to accumulate output, it won't make a jot of difference... What past experience? StringIO.StringIO().write(unichr(128)) cStringIO.StringIO().write(unichr(128)) Traceback (most recent call

Re: Problems with email.Generator.Generator

2006-09-11 Thread Chris Withers
Peter Otten wrote: What past experience? StringIO.StringIO().write(unichr(128)) cStringIO.StringIO().write(unichr(128)) Traceback (most recent call last): File stdin, line 1, in ? UnicodeEncodeError: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)

Re: Problems with email.Generator.Generator

2006-09-11 Thread Chris Withers
Peter Otten wrote: Chris Withers wrote: At worst, and most likely based on my past experience of (c)StringIO being used to accumulate output, it won't make a jot of difference... What past experience? StringIO.StringIO().write(unichr(128)) cStringIO.StringIO().write(unichr(128))

Re: Problems with email.Generator.Generator

2006-09-11 Thread Chris Withers
Chris Withers wrote: ...except it gets the transfer encoding wrong, which means Thunderbird shows =A3 instead of the pound sign that it should :-( ...this is down to a pretty lame bit of code in Encoders.py which basically checks for a unicode error *sigh* OK, slight progress... here a

Re: Problems with email.Generator.Generator

2006-09-11 Thread Chris Withers
Chris Withers wrote: print msg.as_string() MIME-Version: 1.0 Content-Type: text/plain; charset; charset=utf-8 ^^^ Actually, even this isn't correct as you can see above... charset = Charset('utf-8') msg = MIMEText('','plain',None) msg.set_payload(u'Some

Problems with email.Generator.Generator - Solved?

2006-09-11 Thread Chris Withers
Chris Withers wrote: Has no-one ever successfully generated a correctly formatted email with email.MIMEText where the message includes non-ascii characters?! I'm guessing not ;-) Well, I think I have a winner, but it required me to subclass MIMEText: from email.Charset import Charset,QP from