Add "Received:" header to email msg in correct position?

Chris Angelico rosuav at gmail.com
Tue May 6 06:41:40 EDT 2014


On Tue, May 6, 2014 at 8:26 PM, alister
<alister.nospam.ware at ntlworld.com> wrote:
> On Tue, 06 May 2014 19:47:54 +1000, Chris Angelico wrote:
>
>> On Tue, May 6, 2014 at 7:15 PM, alister
>> <alister.nospam.ware at ntlworld.com> wrote:
>>> On Mon, 05 May 2014 19:51:15 +0000, Grant Edwards wrote:
>>>
>>>> I'm working on a Python app that receives an e-mail message via SMTP,
>>>> does some trivial processing on it, and forwards it to another SMTP
>>>> server.
>>>>
>>>> I'd like to do the polite thing and add a "Received:" header, but I
>>>> can't figure out how to get Python's email module to add it in the
>>>> correct place.  It always ends up at the "bottom" of the headers below
>>>> From: To: etc.  It's supposed to go at the above all the Received:
>>>> headers that where there when I received it.
>>>
>>> Is this required or just being polite?
>>> what I mean is does the standard state the headers must be in a
>>> particular order or can they appear anywhere, you may be spending time
>>> trying to resolve an issue that does not need fixing.
>>
>> Yes, it's required. RFC 2821 [1] section 3.8.2 says "prepend".
>>
>> ChrisA
>>
>> [1] http://www.ietf.org/rfc/rfc2821.txt
>
> oh well, so much for the easy route :-)
> This suggests the email module could do with amending so that headers can
> be pretended as appended.

Even if it's special-cased as a dedicated "prepend received header"
method, that would probably do. I can't think of any other headers
where you need to specifically order them rather than appending.

ChrisA



More information about the Python-list mailing list