My simple script parse output screen and to a new file!
Chuck Amadi
chuck at smtl.co.uk
Thu Jun 10 11:29:47 EDT 2004
Has anyone got a work around for readlines() So as the print statement parses
only the bodies of the mail boxes don't need headers etc.
Using the Email Module I have the following snippet thats works minus the
readlines() and write() function reads and writes all data in the mailbox file.
How do I use a for loop at the bottom to only write bodies of the mailbox as
when I use the print statement.
Cheers
# mail is the file object
for mail in mbox:
print mail['Subject']
print mail.get_content_type()#text/plain
print mail.get_payload()
# If your going to use the UnixMailbox in two different loops,must
# need to reinitalize it.
fp = file("/home/chuck/pythonScript/testbox")
mb = mailbox.UnixMailbox(fp, email.message_from_file)
mailout = file("/home/chuck/pythonScript/SurveyResults.txt","w")
for mail in fp.readlines():
mailout.write(mail)
More information about the Python-list
mailing list