Alternatively, you could use a BytesIO to prepend the Received header to
the raw data *before* you parse it with the email module.
That's probably what I ought to do. But subclassing Message and adding
a prepend_header was just too easy, and it avoids having to have my
app know anything about the format of an email message in general or a
header in particular. For example, I don't know what characters (if
any) need to be escaped or specially encoded in the contents of a
header. I also don't remember off the top of my head what you're
supposed to do with headers that get too long (I think you just stick
in a \r\n followed by some whitespace and then continue the header,
but I'd have to look that up and then test it).
I did know how to insert a tuple of two strings at the beginning of a
list.