Rewriting mail headers

John E. Barham jbarham at jbarham.com
Wed Jan 22 02:38:19 CET 2003


>>> import email
>>> msg = email.message_from_file(open("test.eml"))
>>> msg["subject"] = "New subject"
>>> print msg.as_string()

Sorry, I spoke too soon.

If you're running 2.2.2, replace
>>> msg["subject"] = "New subject"
with (note the case)
>>> msg.replace_header("Subject", "New subject")

Otherwise, you'll have to do
>>> del msg["subject"]
before
>>> msg["subject"] = "New subject"

    John






More information about the Python-list mailing list