[Python-Dev] headers api for email package

Chris Withers chris at simplistix.co.uk
Fri May 1 19:14:12 CEST 2009


>>> Where you just want "a damned valid email and stop making my life 
>>> hard!":
>>>
>>> Message['Subject']='Some text'
>>
>> Yes.  In which case I propose we guess the encoding as 1) ascii, 2) 
>> utf-8, 3) wtf?

Well, we're talking about Python 3 here right? In which case the above 
involves only unicode, so why do we need to guess anything? Just use 
utf-8 and be done with it...

> However, it's not supposed to be used by mail composers, who are
> expected to know the encoding.  It's for mail gateways that are
> transforming something and don't know the encoding.  I'm not
> sure what this means for the email module, which certainly
> will be used in a mail gateways....maybe it's the responsibility
> of the application code to explicitly say 'unknown encoding'?

Indeed, surely this happens when you have bytes and need to do something 
with it? That's not what my example above is about...

>>> Where you care about what encoding is used:
>>>
>>> Message['Subject']=Header('Some text',encoding='utf-8')
>>
>> Yes.

...it's covered by this.

>>> If you have bytes, for whatever reason:
>>>
>>> Message['Subject']=b'some bytes'.decode('utf-8')
>>>
>>> ...because only you know what encoding those bytes use!
>>
>> So you're saying that __setitem__() should not accept raw bytes?

Indeed :-)

Chris

-- 
Simplistix - Content Management, Zope & Python Consulting
            - http://www.simplistix.co.uk


More information about the Python-Dev mailing list