473,395 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

get screen output to file using get_payload()

Hi I have managed to print the output of the get_payload to screen
but I need to write to a file as I only require the email body messages
from the mailbox.My script using the fp.readlines() function writes the
entire contents of the mailbox of cause including the headers of the
emails I do not want.

I have tried a few things but I cant get to my goal.Any ideas or
pointers I need only the email body and I cant figute out why I can
using the print statement but get those results to a file.
cheers

import sys
import os
import email
import mailbox
import StringIO
fp = file ("/var/spool/mail/chucka")
mbox = mailbox.UnixMailbox(fp, email.message_from_file)
# list of body messages.
bodies = []

# mail is the file object
for mail in mbox:
print 'mail'
print mail['Subject']
print mail.get_content_type()#text/plain
print mail.get_payload()
mailout = file("/home/chucka/pythonScript/SurveyResults1.txt","r")
fp = open("/var/spool/mail/chucka")
mb = mailbox.UnixMailbox(fp, email.message_from_file)

#for bdymsg in fp.xreadlines():
#for bdymsg in fp.readlines():
#for msgbodies in mb:
# mailout.write(bdymsg)
# bdymsg = mail.get_payload()
# mailout.write(mail.get_payload()

for bmsg in mb:
bmsg = get_payload()
mailout.write(bmsg)
# bmsg = [get_payload]
print "mailbox file copied...to SurveyResults.txt"

# Now close the files
mailout.close()


Jul 18 '05 #1
1 1988
On 2004-06-23, chuck amadi <ch*********@ntlworld.com> wrote:
Hi I have managed to print the output of the get_payload to screen
but I need to write to a file as I only require the email body messages
from the mailbox.My script using the fp.readlines() function writes the
entire contents of the mailbox of cause including the headers of the
emails I do not want.

I have tried a few things but I cant get to my goal.Any ideas or
pointers I need only the email body and I cant figute out why I can
using the print statement but get those results to a file.
cheers
mailout = file("/home/chucka/pythonScript/SurveyResults1.txt","r")

You have the file opened read only. You would need something like:

mailout = file("/home/chucka/pythonScript/SurveyResults1.txt", "w")

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Chuck Amadi | last post by:
Has anyone got a simple python script that will parse a linux mbox and create a large file to view . Cheers Chu
16
by: Chuck Amadi | last post by:
Sorry to bovver you again (again) here's script. I still can't see why the get_payload() doesn't produce the plain text message body of an emails in the testwwws users mailbox. As you can see I...
1
by: chuck amadi | last post by:
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...
6
by: Ville Vainio | last post by:
Just posting this for the sake of google: Like everyone else, I figured it's time to start using the 'logging' module. I typically want to dump "info" level (and up) log information to...
4
by: Roland Hall | last post by:
Am I correct in assuming screen scraping is just the response text sent to the browser? If so, would that mean that this could not be screen scraped? function moi() { var tag = '<a href='; var...
9
by: dana lees | last post by:
Hello, I am developing a C# asp.net application. I am using the authentication and authorization mechanism, which its timeout is set to 60 minutes. My application consists of 2 frames - a...
8
by: gtpilot | last post by:
I have a program that is going to return position data several times a second. Instead of printing this data to the screen on new line every time, I would like to simply have the program print...
7
by: erikcw | last post by:
Hi all, I'm trying to extract zip file (containing an xml file) from an email so I can process it. But I'm running up against some brick walls. I've been googling and reading all afternoon, and...
1
by: sharan | last post by:
Using the expat parser (http://expat.sourceforge.net/) i have to parse the following xml file and print it on the screen in tabular format using C language. i am getting ouput serially but not in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.