Python:Email and Header Parsing: Some Help

dont bother dontbotherworld at yahoo.com
Thu Feb 26 03:51:40 EST 2004


Hi,
I have written this small piece of code. I am a brand
new  player of Python. I had asked some people for
help, unfortunately not many helped.
Here is the code I have:

import email
import os
import sys
fread = open('email_message', 'r')
msg=email.message_from_file(fread)
print msg
#fwrite = open('output','w')
#fwrite.write(msg)

This way I am able to print the entire email message
on the stdout. The program generates an error If I try
to write the output to a file-- It says the argument
(here msg) should be a string but not as an instance
like here. How to write the message to another file
then?

2. I have so many headers in the email message

To:
From:
X Received:
X Priority:
Subject:
etc etc.
I want to parse the headers separtely and message
separately. Does anyone has an example code to deal
with Parser?
Also I want to remove the redundant words and all html
tags. Any advise on that?
I saw some examples using HTMLGen But I dont have
HTMLGen with python on my machine. I have Python
2.3.3. on my machine.

All help is greatly appreciated.
Thanks
Dont

__________________________________
Do you Yahoo!?
Get better spam protection with Yahoo! Mail.
http://antispam.yahoo.com/tools




More information about the Python-list mailing list