rfc822 module: deleting headers
Jason R. Mastaler
jason-dated-1022700360.9a9240 at mastaler.com
Tue May 21 15:26:00 EDT 2002
This question concerns how to remove headers from an incoming mail
message using the rfc822 module. The docs say:
Message instances also support the mapping writable interface
m[name] = value and del m[name].
So take the following program invoked from a .qmail file (qmail's
equivalent of .forward):
#!/usr/bin/env python
import cStringIO, rfc822, sys
stdin = cStringIO.StringIO(sys.stdin.read())
headers = rfc822.Message(stdin)
body = stdin.read()
print headers.headers
del headers['Message-ID']
print headers.headers
sys.exit(0)
As you can see, I attempt to remove the 'Message-ID' header before
exiting 0, which causes qmail to skip to the next line in my .qmail
file, which writes the message to my mailbox.
However, when the message reaches my mailbox, it still contains
'Message-ID'. The two print statements above show that indeed
Message-ID was removed from the headers list, but this isn't showing
up in the message.
So how is this falling out of sync? I assume because of the exit(0)?
Any way to synchronize the rfc822.Message instance with the actual
message headers before the program exits?
Thanks.
More information about the Python-list
mailing list