[Python-Dev] Patch making the current email package (mostly) support bytes

Stephen J. Turnbull stephen at xemacs.org
Fri Oct 8 16:55:37 CEST 2010

Barry Warsaw writes:

 > Header wrapping sucks even more because it's supposed to take the
 > semantic context into account, which means that a generic Header
 > wrapping algorithm cannot work for everything.  E.g. Received:
 > headers are supposed to wrap after the semicolon.

Received headers are an easy special case:

    An Internet mail program MUST NOT change or delete a Received:
    line that was previously added to the message header section.
    (RFC 5321, sec. 4.4)

So you save them as bytes and Barry's your FLUFL, as they say.

If email wants to *produce* them (as a service to say smtplib), then
it wants to comply with the detailed recommendations in RFC 5321,
sec. 4.4 anyway; I don't think there's a good reason treat Received
headers as text since they're conceptually part of the wire protocol.
(Except for the information of curious users, but then getting it
exactly right is best done by just passing the whole thing, folds and
all, to .decode('ascii'), I should think.)

I should think you *want* addresses and suchlike structured headers
(Content-Type with several RFC 2231 parameters, anyone?) to line up
nicely, too.  So generic folding algorithms are really only applicable
to unstructured text fields like Subject and Summary anyway.

You can call that "sucky" if you like, I prefer to call it "tasteful."

More information about the Python-Dev mailing list