[Email-SIG] [Python-Dev] Dropping bytes "support" in json

Tony Nelson tonynelson at georgeanelson.com
Mon Apr 13 19:13:25 CEST 2009


At 10:14 -0400 04/13/2009, Barry Warsaw wrote:
 ...
>Actually, thinking about this over the weekend, it's much better for
>message['subject'] to return a Header instance in all cases.  Use
>bytes(header) to get the raw bytes.

I don't agree.  I'd want it to return the appropriate type for that header:
string for Subject:, a list of addresses for To:, and so on.  Either the
user knows what to expect, or they'll learn immediately.  If they get a
Header, they have to then extract the appropriate data from it, based on
its type (but they only know the name).

OK, Header instances could have a .useful field that returned the useful
data in all instances.  But in any case, the email package should guide
users in the correct usage, rather than leaving every choice seeming equal,
when only one choice is correct.


>A good API for getting the parsed and decoded header values needs to
>take into account that it won't always be a string.  For unstructured
>headers like Subject, str(header) would work just fine.  For an
>Originator or Destination address, what does str(header) return?  And
>what would be the API for getting the set of realname/addresses out of
>the header?

msg[<headername>] would be the preferred way.

msg.get_header(<headername>).useful would return the useful data form of
any header.

msg.get_header(<headername>).addresses would return the address list from
any address Header, and raise AttributeError with other Headers.
-- 
____________________________________________________________________
TonyN.:'                       <mailto:tonynelson at georgeanelson.com>
      '                              <http://www.georgeanelson.com/>


More information about the Email-SIG mailing list