This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: replace_header method for Message class
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: barry Nosy List: barry, skip.montanaro
Priority: normal Keywords: patch

Created on 2002-08-29 16:23 by skip.montanaro, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
header.py skip.montanaro, 2002-08-30 14:10
Messages (5)
msg41056 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2002-08-29 16:23
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)
msg41057 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2002-08-30 13:12
Logged In: YES 
user_id=12800

+1 although I'd like to think some on the method name. 
Also, we'll need a Python 2.1 compatible version of that
method (no "enumerate").   The email package still has to be
Py2.1 compatible.  See PEP 291.

Care to upload a new version?
msg41058 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2002-08-30 14:10
Logged In: YES 
user_id=44345

How about the attached?  Used zip() instead of enumerate.  I'll let you 
worry about the name... ;-)
msg41059 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2002-08-30 14:13
Logged In: YES 
user_id=12800

+1 Thanks!

I'll try to get this into email 2.3.
msg41060 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2002-09-06 03:41
Logged In: YES 
user_id=12800

Added to Message.py 1.21
History
Date User Action Args
2022-04-10 16:05:37adminsetgithub: 37104
2002-08-29 16:23:05skip.montanarocreate