[Email-SIG] API for Header objects [was: Dropping bytes "support" in json]

Tony Nelson tonynelson at georgeanelson.com
Fri Apr 17 19:26:16 CEST 2009


At 00:13 +0900 04/18/2009, Stephen J. Turnbull wrote:
>R. David Murray writes:
>
> > put Header objects into it.  I don't think the "overhead" of
> > having to do
> >
> >      message['Subject'] = Header('subject string')
>
>Hm.  Should a Header know which header it is?  Ie, should that be
>
>    message['Subject'] = Header('subject', 'subject string')
 ...

How about:

    message['Subject'] = 'subject string'
    message['To'] = ('joe', 'joe123 at foo.com')

Since the Header does indeed know what it is, a Subject: Header could
expect a string for input, and an Address header could expect an address
tuple or list of them (and cope with possibly needing to coerce the
addr-spec into bytes with the ASCII codec).

Internally, Message.__setitem__() would look up the name, making and
assigning the proper Headere subclass if missing, and pass that object the
data.  The Header subclass knows what type of data it expects and raises
(ValueError?) if it gets something inappropriate.
-- 
____________________________________________________________________
TonyN.:'                       <mailto:tonynelson at georgeanelson.com>
      '                              <http://www.georgeanelson.com/>


More information about the Email-SIG mailing list