[Email-SIG] API thoughts
R. David Murray
rdmurray at bitdance.com
Wed Mar 2 17:23:27 CET 2011
On Tue, 01 Mar 2011 18:36:47 -0800, Glenn Linderman <v+python at g.nevcal.com> wrote:
> On 3/1/2011 5:45 PM, R. David Murray wrote:
> > On Tue, 01 Mar 2011 16:55:58 -0800, Glenn Linderman<v+python at g.nevcal.com> wrote:
> >> On 3/1/2011 2:59 PM, R. David Murray wrote:
> >>> On Tue, 01 Mar 2011 13:58:50 -0800, Glenn Linderman<v+python at g.nevcal.com> wrote:
> >> Hmm. And while it might be more complex to handle structured headers,
> >> in fact they come in a character sequences, so a mapping to string is
> >> not impossible. The real issue is if those headers had another API in
> >> email5 (I could look that up, I guess), but perhaps that API could also
> >> be supported along with a subclass of string.
> > They don't. The issue is that what we would like is for the email6 API
> > for the address header to be that it looks like a list of Address objects.
> > So msg['To'][0] would yield an address object. But if we also want the
> > header to look like a string, that won't work, because as a string that
> > should yield the first character of the body of the header.
> >
> > Now, a sensible application would process the list of addresses in a To
> > header by passing it to util.getaddresses, but you can bet that there
> > are applications that don't do that.
> >
> > A compromise would be to have an 'addresses' method that returned the
> > list of addresses. Perhaps this would even be sensible in the context of
> > email6 by itself: it would mean that all headers had a uniform base API
> > (they act like strings) and all structured information is accessed via
> > special methods.
>
> While msg['To'] producing a structured result might not be possible
> when subclassing string, you mention one possible alternative, an
> additional method... seems like you mean msg['To'].addresses()? It
> would also be possible to make msg.p['To'] for parsed/structured
> results. I'm not sure which would be easier to implement, or more
> flexible under the covers to do caching of parsed/structured results.
> Of course there are several headers dealing with lists of addresses, as
> you are well aware, so msg.addresses() wouldn't work without some
> specification of the header.
Yes, exactly msg['To'].addresses (might as well use a property).
I think I prefer this to a separate retrieval method, since not all
headers are structured headers, and it is not clear what the "parsed"
version of a non-structured header would be (a plain string?).
--David
More information about the Email-SIG
mailing list