parse output screen ok but cant get desired output new file!

chuck amadi chuck.amadi at ntlworld.com
Wed Jun 23 02:29:12 EDT 2004


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)                          
> > >
> > >
> > >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 have 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.I have tried a few things to no effect.
> >                     .
> >                     .
> >                     .
> > There's a lot going on in your message.  I *think* what you want
> > is the suggestion to replace
> >   for mail in fp.readlines():
> >       mailout.write(mail)
> > with
> >   mailout.write(fp.read())
> > -- 
> > 
> >

> Hi again where I print mail.get_payload()
> I want to write this to the file. Bu uisng readlinds() function I
> obviously get the entire contents including the headers thus I want to
> do something like this

> for bdymsg in mb:
> bdymsg = mail.get_payload()
> print mail.get_payload()# prints body msg's to screen
> mailout.write(bdymsg)
> # mailout.write(mail.get_payload()) # Something along these lines.
> mailout.close()









More information about the Python-list mailing list