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

Grant Edwards invalid at invalid.invalid
Tue May 6 10:12:53 EDT 2014


On 2014-05-06, Steven D'Aprano <steve at pearwood.info> wrote:
> On Tue, 06 May 2014 02:13:09 +0000, Grant Edwards wrote:
>
>> There's is a somewhat messy way to do it by calling msg.items() to
>> retrieve all the current headers, removing all of them, and then adding
>> them all back (includeing the new one) in the order I want them.
>
> Does msg.items() return the actual message header list, or a copy?

A shallow copy:

    def items(self):
        """Get all the message's header fields and values.

        These will be sorted in the order they appeared in the original
        message, or were added to the message, and may contain duplicates.
        Any fields deleted and re-inserted are always appended to the header
        list.
        """
        return self._headers[:]

> Because if it returns the list itself, you can just insert directly into 
> the list using the insert method.

-- 
Grant Edwards               grant.b.edwards        Yow! What I need is a
                                  at               MATURE RELATIONSHIP with a
                              gmail.com            FLOPPY DISK ...



More information about the Python-list mailing list