EMAIL script parse output screen and to a new file!

chuck amadi chuck.amadi at
Sun Jun 13 16:05:56 CEST 2004

Chuck Amadi wrote:

>Cheers for pointing that out !.
>By the way list is there a better way than using the readlines() to parse the 
>mail data into a file , because Im using email.message_from_file it returns 
>all the data i.e reads one entire line from the file , headers as well as just 
>the desired body messages .
>fp = file("/home/chuck/pythonScript/testbox")
>mb = mailbox.UnixMailbox(fp, email.message_from_file)                          
>#<Instead of this >                                                            
>mailout = file("/home/chuck/pythonScript/SurveyResults.txt","w")
>for mail in fp.readlines():
>    mailout.write(mail)
>#<Something like this>
>for mail in mb:
>        body = mail.get_payload()
>	mailout.write(body) # write only the body messages to SurveyResults.txt
>Cheers if the is a better way I can't get my head round how I can print mail ( 
>only the body messages) to screen and the entire mail headers and body to the 
>new file.
>Hi hav any one got any suggstions to my script I can parse the email body messages to screen but I want the same desired effect to save to a new file.

The above works but also parse's the email headers as well as the 
desired body messages.



More information about the Python-list mailing list