On 2014-05-07, Ian Kelly <ian.g.ke...@gmail.com> wrote: > On May 7, 2014 9:13 AM, "Chris Angelico" <ros...@gmail.com> wrote: >> >> On Thu, May 8, 2014 at 1:06 AM, Burak Arslan <burak.ars...@arskom.com.tr> > wrote: >> > Seeing how discussion is still going on about this, I'd like to state >> > once more what I said above in other words: You just need to do this: >> > >> > "Received: blah\r\n" + message.to_string() >> > >> > or better: >> > >> > socket.write("Received: blah\r\n") >> > socket.write(message.to_string()) >> > >> > And again, this is not a hack, this is how it's supposed to work. >> >> Yes, that method does work... if you're taking it in and sending it >> right out again. But it means you have to hang onto two pieces of data >> - the message and the new Received header - until you write it to a >> file/socket. > > 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. :) -- Grant Edwards grant.b.edwards Yow! All this time I've at been VIEWING a RUSSIAN gmail.com MIDGET SODOMIZE a HOUSECAT! -- https://mail.python.org/mailman/listinfo/python-list