Program not Stripping Headers from Email though Working fine

dont bother dontbotherworld at yahoo.com
Thu Mar 4 03:40:16 EST 2004


Hey,
I have written this simple code. I want to strip all
the headers from a file including To, From, Received,
X-Spam etc which has long list of email messages (spam
archive). 

After I do this: I want to write the payload in
another file output.
The code is here, but I dont know why the headers are
still present in the output file.

Please do help,
Whats missing friends?
Any help is highly appreciated

Thanks
Dont

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


import email
import os
import sys
import re
import mailbox
import email.Parser
import email.Message
import getopt


fread = open('325.r2', 'r')
msg=email.message_from_file(fread)

for hdr in msg.keys():
	if hdr.startswith('From'):
		del msg[hdr]
	if hdr.startswith('To'):
		del msg[hdr]
	if hdr.startswith('Received'):
		del msg[hdr]
	if hdr.startswith('X-'):
		del msg[hdr]

fwrite = open('output','w')
fwrite.write(msg.as_string())


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











__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com




More information about the Python-list mailing list