Problems with email.Generator.Generator
Chris Withers
chris at simplistix.co.uk
Tue Sep 12 05:21:02 EDT 2006
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 encoded strings. I don't remember seeing that
> it should be possible to use a unicode string as a message.
Yes, I guess I just find that surprising in today's "everything should
be unicode" world.
> The charset passed in set_payload(pl ,charset) is the charset the the
> string *is* encoded in. Not the charset it *should* be encoded in.
Indeed, although there's still the bug that while set_payload can accept
a Charset instance for its _charset parameter, the __init__ method for
MIMENonMultipart cannot.
Incidentally, here's the class I finally ended up with:
from email.Charset import Charset
from email.MIMEText import MIMEText as OriginalMIMEText
from email.MIMENonMultipart import MIMENonMultipart
class MTText(OriginalMIMEText):
def __init__(self, _text, _subtype='plain', _charset='us-ascii'):
if not isinstance(_charset,Charset):
_charset = Charset(_charset)
if isinstance(_text,unicode):
_text = _text.encode(_charset.input_charset)
MIMENonMultipart.__init__(self, 'text', _subtype,
**{'charset': _charset.input_charset})
self.set_payload(_text, _charset)
cheers,
Chris
--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
More information about the Python-list
mailing list