[Patches] [ python-Patches-601959 ] replace_header method for Message class

noreply@sourceforge.net noreply@sourceforge.net
Thu, 29 Aug 2002 09:23:05 -0700


Patches item #601959, was opened at 2002-08-29 11:23
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=601959&group_id=5470

Category: Library (Lib)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Skip Montanaro (montanaro)
Assigned to: Barry A. Warsaw (bwarsaw)
Summary: replace_header method for Message class

Initial Comment:
There are certain situations where I want to replace the contents of a 
header and not change either the header's name or its position in the 
list of headers.  Accordingly, something like

    del msg["Subject"]
    msg["Subject"] = newsubj

doesn't quite cut it.  For example, de-SpamAssassin-ing a message 
for feeding to GBayes would change the header order (minor change, 
but annoying) and potentially change the actual subject string (some 
spam seems to use "SUBJECT:" instead of "Subject:").

Here's a replace_header method that does what I want.

    def replace_header(self, hdr, newval):
        """replace first value for hdr with newval"""
        hdr = hdr.lower()
        for (i, (k, v)) in enumerate(self._headers):
            if k.lower() == hdr:
                self._headers[i] = (k, newval)


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=601959&group_id=5470